Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HotFix] Fix bug in dict_dialog_agent #98

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/agentscope/agents/dict_dialog_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,16 @@

def parse_dict(response: ModelResponse) -> ModelResponse:
"""Parse function for DictDialogAgent"""
return ModelResponse(raw=json.loads(response.text))
try:
response_dict = json.loads(response.text)
except json.decoder.JSONDecodeError:
# Sometimes LLM may return a response with single quotes, which is not
# a valid JSON format. We replace single quotes with double quotes and
# try to load it again.
# TODO: maybe using a more robust json library to handle this case
response_dict = json.loads(response.text.replace("'", '"'))

return ModelResponse(raw=response_dict)


def default_response(response: ModelResponse) -> ModelResponse:
Expand Down Expand Up @@ -159,6 +168,12 @@ def reply(self, x: dict = None) -> dict:

# record to memory
if self.memory:
self.memory.add(msg)
# Convert the response dict into a string to store in memory
msg_memory = Msg(
name=self.name,
content=str(msg.content),
ZiTao-Li marked this conversation as resolved.
Show resolved Hide resolved
role="assistant",
)
self.memory.add(msg_memory)

return msg