Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
IANTHEREAL committed Oct 28, 2024
1 parent b9f50e6 commit fb5a755
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions backend/app/rag/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,28 @@ def __init__(
self.engine_name = engine_name

self.user_question, self.chat_history = self._parse_chat_messages(chat_messages)
self.chat_engine_config = ChatEngineConfig.load_from_db(db_session, engine_name)
self.db_chat_engine = self.chat_engine_config.get_db_chat_engine()

if chat_id:
# FIXME:
# only chat owner or superuser can access the chat,
# anonymous user can only access anonymous chat by track_id
self.db_chat_obj = chat_repo.get(self.db_session, chat_id)
if not self.db_chat_obj:
raise ChatNotFound()
try:
self.chat_engine_config = ChatEngineConfig.load_from_db(db_session, self.db_chat_obj.engine.name)
self.db_chat_engine = self.chat_engine_config.get_db_chat_engine()
except Exception as e:
logger.error(f"Failed to load chat engine config: {e}")
self.chat_engine_config = ChatEngineConfig.load_from_db(db_session, engine_name)
self.db_chat_engine = self.chat_engine_config.get_db_chat_engine()
logger.info(f"ChatService - chat_id: {chat_id}, chat_engine: {self.db_chat_obj.engine.name}")
self.chat_history = [
ChatMessage(role=m.role, content=m.content, additional_kwargs={})
for m in chat_repo.get_messages(self.db_session, self.db_chat_obj)
]
else:
self.chat_engine_config = ChatEngineConfig.load_from_db(db_session, engine_name)
self.db_chat_engine = self.chat_engine_config.get_db_chat_engine()
self.db_chat_obj = chat_repo.create(
self.db_session,
DBChat(
Expand Down

0 comments on commit fb5a755

Please sign in to comment.