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: Apply a temp hotfix for sessions.chat #497

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions agents-api/agents_api/models/entry/get_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
}
for r in d.pop("relations")
],
# TODO: Remove this once we sort the entries in the cozo query
# Sort entries by created_at
"entries": sorted(d.pop("entries"), key=lambda entry: entry["created_at"]),
**d,
},
)
Expand Down
17 changes: 17 additions & 0 deletions agents-api/agents_api/routers/sessions/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ async def chat(
# messages = messages[-settings["max_tokens"] :]
raise NotImplementedError("Truncation is not yet implemented")

# FIXME: Hotfix for datetime not serializable. Needs investigation
messages = [
msg.model_dump() if hasattr(msg, "model_dump") else msg
for msg in messages
]

messages = [
dict(role=m["role"], content=m["content"], user=m.get("user"))
for m in messages
]

# Get the response from the model
model_response = await litellm.acompletion(
messages=messages,
Expand All @@ -90,6 +101,12 @@ async def chat(
for msg in new_messages
]

# Add the response to the new entries
new_entries.append(
CreateEntryRequest.from_model_input(
model=settings["model"], **model_response.choices[0].model_dump()['message'], source="api_response"
)
)
background_tasks.add_task(
create_entries,
developer_id=developer.id,
Expand Down
Loading