Skip to content

Commit

Permalink
fix: added conversation validation in chat
Browse files Browse the repository at this point in the history
  • Loading branch information
antoninoLorenzo committed Feb 23, 2025
1 parent 1d5bcc0 commit 10443fc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/chat/service.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List
from typing import List, Optional

from src.agent import Agent, init_default_architecture
from src.chat.model import AGENT_SETTINGS
Expand Down Expand Up @@ -30,7 +30,10 @@ def new_conversation(self, name: str) -> Conversation:
)
return self.__memory[new_conversation_id]

def get_conversation(self, conversation_id: int) -> Conversation:
def get_conversation(self, conversation_id: int) -> Optional[Conversation]:
"""
:return: a Conversation or None
"""
return self.__memory[conversation_id]

def rename_conversation(self, conversation_id: int, new_name: str):
Expand Down
4 changes: 3 additions & 1 deletion src/chat/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ async def query(
raise HTTPException(status_code=400, detail='expected {"query": str}')

conversation = conversation_service.get_conversation(conversation_id)
if not conversation:
raise HTTPException(status_code=404, detail='conversation not found')

conversation += Message(role=Role.USER, content=usr_query)

return StreamingResponse(query_generator(agent, conversation))

0 comments on commit 10443fc

Please sign in to comment.