Pass deep typed chat history for more ergonomic, readable, safe code

The chat dictionary is an artifact from earlier non-db chat history
storage. We've been ensuring new chat messages have valid type before
being written to DB for more than 6 months now.

Move to using the deeply typed chat history helps avoids null refs,
makes code more readable and easier to reason about.

Next Steps:
The current update entangles chat_history written to DB
with any virtual chat history message generated for intermediate
steps. The chat message type written to DB should be decoupled from
type that can be passed to AI model APIs (maybe?).

For now we've made the ChatMessage.message type looser to allow
for list[dict] type (apart from string). But later maybe a good idea
to decouple the chat_history recieved by send_message_to_model from
the chat_history saved to DB (which can then have its stricter type check)
This commit is contained in:
Debanjum
2025-06-03 15:28:06 -07:00
parent 430459a338
commit 05d4e19cb8
20 changed files with 271 additions and 248 deletions

View File

@@ -708,6 +708,6 @@ def populate_chat_history(message_list):
"context": context,
"intent": {"query": user_message, "inferred-queries": f'["{user_message}"]'},
},
conversation_log=[],
chat_history=[],
)
return conversation_log