Whether the agent has memory.
memory_config (`Optional[dict]`, defaults to `None`):
The config of memory.
-
parse_func (`Optional[Callable[..., Any]]`, defaults to `None`):
+
parse_func (`Optional[Callable[..., Any]]`,
+
defaults to `parse_dict`):
The function used to parse the model output,
e.g. `json.loads`, which is used to extract json from the
output.
-
fault_handler (`Optional[Callable[..., Any]]`, defaults to `None`):
+
fault_handler (`Optional[Callable[..., Any]]`,
+
defaults to `default_response`):
The function used to handle the fault when parse_func fails
to parse the model output.
max_retries (`Optional[int]`, defaults to `None`):
@@ -222,7 +241,7 @@
Source code for agentscope.agents.dict_dialog_agent
parse_func
=self.parse_func,
fault_handler=self.fault_handler,
max_retries=self.max_retries,
-
).text
+
).raw
# logging raw messages in debug mode
logger.debug(json.dumps(response, indent=4))
diff --git a/_modules/agentscope/models/model.html b/_modules/agentscope/models/model.html
index d476780ae..74e476931 100644
--- a/_modules/agentscope/models/model.html
+++ b/_modules/agentscope/models/model.html
@@ -197,7 +197,16 @@
Source code for agentscope.models.model
@property
def raw(self) -> dict:
"""Raw dictionary field."""
- return self._raw
+
return self._raw
+
+
def __str__(self) -> str:
+
serialized_fields = {
+
"text": self.text,
+
"embedding": self.embedding,
+
"image_urls": self.image_urls,
+
"raw": self.raw,
+
}
+
return json.dumps(serialized_fields, indent=4)
diff --git a/_sources/tutorial/201-agent.md.txt b/_sources/tutorial/201-agent.md.txt
index 7885ba28d..f4d513e53 100644
--- a/_sources/tutorial/201-agent.md.txt
+++ b/_sources/tutorial/201-agent.md.txt
@@ -90,10 +90,10 @@ def reply(self, x: dict = None) -> dict:
prompt = self.engine.join(self.sys_prompt, self.memory.get_memory())
# Invoke the language model with the prepared prompt
- response = self.model(prompt, parse_func=json.loads, fault_handler=lambda x: {"speak": x})
+ response = self.model(prompt).text
# Format the response and create a message object
- msg = Msg(self.name, response.get("speak", None) or response, **response)
+ msg = Msg(self.name, response)
# Record the message to memory and return it
self.memory.add(msg)
diff --git a/_sources/tutorial/204-service.md.txt b/_sources/tutorial/204-service.md.txt
index 448627a28..9703171a7 100644
--- a/_sources/tutorial/204-service.md.txt
+++ b/_sources/tutorial/204-service.md.txt
@@ -118,12 +118,12 @@ class YourAgent(AgentBase):
prompt += params_prompt
# Get the model response
- model_response = self.model(prompt)
+ model_response = self.model(prompt).text
# Parse the model response and call the create_file function
# Additional extraction functions might be necessary
try:
- kwargs = json.loads(model_response.content)
+ kwargs = json.loads(model_response)
create_file(**kwargs)
except:
# Error handling
diff --git a/agentscope.agents.html b/agentscope.agents.html
index e1e2a656b..599c0493e 100644
--- a/agentscope.agents.html
+++ b/agentscope.agents.html
@@ -117,6 +117,8 @@
DictDialogAgent.reply()
+
default_response()
+
parse_dict()
text_to_image_agent module
@@ -589,6 +591,18 @@ Agents package