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

fix(server): solve the chat error #720

Merged
merged 3 commits into from
Feb 5, 2025
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
22 changes: 13 additions & 9 deletions server/agent/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,17 @@
output = event.get("data", {}).get("output", {})
generations = output.get("generations", [])
if generations and len(generations) > 0:
content = generations[0][0].get("message", {}).get("usage_metadata")
if content:
yield {
"id": event["run_id"],
"type": "usage",
**content,
}
generation = generations[0][0]
message = generation.get("message")
if message:
content = message.usage_metadata
xingwanying marked this conversation as resolved.
Show resolved Hide resolved
if content:
yield {

Check warning on line 164 in server/agent/base.py

View check run for this annotation

Codecov / codecov/patch

server/agent/base.py#L159-L164

Added lines #L159 - L164 were not covered by tests
"id": event["run_id"],
"type": "usage",
**content,
}

elif kind == "on_tool_start":
children_value = event["data"].get("input", {})
yield {
Expand Down Expand Up @@ -216,9 +220,9 @@

except Exception as e:
if isinstance(e, APIError):
yield { "status": "error", "message": e.body }
yield {"status": "error", "message": e.body}

Check warning on line 223 in server/agent/base.py

View check run for this annotation

Codecov / codecov/patch

server/agent/base.py#L223

Added line #L223 was not covered by tests
else:
yield { "status": "error", "message": str(e) }
yield {"status": "error", "message": str(e)}

Check warning on line 225 in server/agent/base.py

View check run for this annotation

Codecov / codecov/patch

server/agent/base.py#L225

Added line #L225 was not covered by tests

async def run_chat(self, input_data: ChatData) -> str:
try:
Expand Down