Save user chat sessions and provide API's for session CRUD and message retrieval #48
+4,262
−333
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What are the relevant tickets?
Closes https://github.com/mitodl/hq/issues/6536 (mostly)
Description (What does it do?)
UserChatSession
model, creates it at the start of a new thread, with title based on initial user message (editable via API), and if created by anonymous user, updates it with the correct user when finally logged in.../api/v0/chat_sessions/
)../api/v0/chat_sessions/<thread_id>/
)../api/v0/chat_sessions/<thread_id>/messages/
)How can this be tested?
Saving chat history
docker compose up
: if you've already run migrations before, check that they don't run again (the LiteLLM proxy service was previously wiping out the db on startup). The LiteLLM should also start up successfully.frontend-demo/src/app/page.tsx
to includeclear_history: true
:http://ai.open.odl.local:8003
and send a few messages. Because of the change above, each message will be treated as a new "chat session" and the chatbot won't recall your previous messages.UserChatSession
object for each of your messages, with title=your message (maybe truncated), and userid=None.[email protected]
and passwordstudent
. Then go back to the chat page and send another message.UserChatbotSession
objects should now have a user (you) associated with them.Chat history endpoints
http://ai.open.odl.local:8002/api/v0/chat_sessions/<threaad_id>
. You should be able to edit the title.http://ai.open.odl.local:8002/api/v0/chat_sessions/<threaad_id>/messages
. You should see the user and ai agent messages in chronological order.DRF-spectacular schema
Additional Context
TODO for a subsequent PR: