@@ -227,6 +227,7 @@ def _builtin_chat(
227227 db_user_message = db_user_message ,
228228 response_text = need_clarify_response ,
229229 knowledge_graph = knowledge_graph ,
230+ source_documents = [],
230231 )
231232 return None , []
232233
@@ -247,7 +248,6 @@ def _builtin_chat(
247248 db_user_message = db_user_message ,
248249 response_text = response_text ,
249250 knowledge_graph = knowledge_graph ,
250- source_documents = source_documents ,
251251 )
252252
253253 return response_text , source_documents
@@ -329,7 +329,7 @@ def _search_knowledge_graph(
329329 def _refine_user_question (
330330 self ,
331331 user_question : str ,
332- chat_history : Optional [List [ChatMessage ]] = list ,
332+ chat_history : Optional [List [ChatMessage ]] = [] ,
333333 refined_question_prompt : Optional [str ] = None ,
334334 knowledge_graph_context : str = "" ,
335335 annotation_silent : bool = False ,
@@ -377,7 +377,7 @@ def _refine_user_question(
377377 def _clarify_question (
378378 self ,
379379 user_question : str ,
380- chat_history : Optional [List [ChatMessage ]] = list ,
380+ chat_history : Optional [List [ChatMessage ]] = [] ,
381381 knowledge_graph_context : str = "" ,
382382 ) -> Generator [ChatEvent , None , Tuple [bool , str ]]:
383383 """
@@ -577,7 +577,7 @@ def _chat_finish(
577577 db_user_message : ChatMessage ,
578578 response_text : str ,
579579 knowledge_graph : KnowledgeGraphRetrievalResult = KnowledgeGraphRetrievalResult (),
580- source_documents : Optional [List [SourceDocument ]] = list ,
580+ source_documents : Optional [List [SourceDocument ]] = [] ,
581581 annotation_silent : bool = False ,
582582 ):
583583 if not annotation_silent :
@@ -627,14 +627,20 @@ def _external_chat(self) -> Generator[ChatEvent | str, None, None]:
627627 goal , response_format = self .user_question , {}
628628 if settings .ENABLE_QUESTION_CACHE and len (self .chat_history ) == 0 :
629629 try :
630- logger .info (f"start to find_best_answer_for_question with question: { self .user_question } " )
630+ logger .info (
631+ f"start to find_best_answer_for_question with question: { self .user_question } "
632+ )
631633 cache_messages = chat_repo .find_best_answer_for_question (
632634 self .db_session , self .user_question
633635 )
634636 if cache_messages and len (cache_messages ) > 0 :
635- logger .info (f"find_best_answer_for_question result { len (cache_messages )} for question { self .user_question } " )
637+ logger .info (
638+ f"find_best_answer_for_question result { len (cache_messages )} for question { self .user_question } "
639+ )
636640 except Exception as e :
637- logger .error (f"Failed to find best answer for question { self .user_question } : { e } " )
641+ logger .error (
642+ f"Failed to find best answer for question { self .user_question } : { e } "
643+ )
638644
639645 if not cache_messages or len (cache_messages ) == 0 :
640646 try :
@@ -643,10 +649,11 @@ def _external_chat(self) -> Generator[ChatEvent | str, None, None]:
643649
644650 # 2. Check if the goal provided enough context information or need to clarify.
645651 if self .engine_config .clarify_question :
646- need_clarify , need_clarify_response = (
647- yield from self ._clarify_question (
648- user_question = goal , chat_history = self .chat_history
649- )
652+ (
653+ need_clarify ,
654+ need_clarify_response ,
655+ ) = yield from self ._clarify_question (
656+ user_question = goal , chat_history = self .chat_history
650657 )
651658 if need_clarify :
652659 yield from self ._chat_finish (
0 commit comments