From df9ab51fd0fc06bbd185e1623bf74c0b60784a27 Mon Sep 17 00:00:00 2001 From: Debanjum Date: Tue, 20 May 2025 15:31:33 -0700 Subject: [PATCH] Track research results as iteration list instead of iteration summaries --- src/khoj/routers/api_chat.py | 8 ++++---- src/khoj/routers/helpers.py | 9 ++++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/khoj/routers/api_chat.py b/src/khoj/routers/api_chat.py index fed6a559..7b78063d 100644 --- a/src/khoj/routers/api_chat.py +++ b/src/khoj/routers/api_chat.py @@ -883,7 +883,7 @@ async def chat( user_message_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S") meta_log = conversation.conversation_log - researched_results = "" + research_results: List[InformationCollectionIteration] = [] online_results: Dict = dict() code_results: Dict = dict() operator_results: Dict[str, str] = {} @@ -963,14 +963,14 @@ async def chat( compiled_references.extend(research_result.context) if research_result.operatorContext: operator_results.update(research_result.operatorContext) - researched_results += research_result.summarizedResult + research_results.append(research_result) else: yield research_result # researched_results = await extract_relevant_info(q, researched_results, agent) if state.verbose > 1: - logger.debug(f"Researched Results: {researched_results}") + logger.debug(f'Researched Results: {"".join(r.summarizedResult for r in research_results)}') used_slash_summarize = conversation_commands == [ConversationCommand.Summarize] file_filters = conversation.file_filters if conversation else [] @@ -1379,13 +1379,13 @@ async def chat( online_results, code_results, operator_results, + research_results, inferred_queries, conversation_commands, user, request.user.client_app, location, user_name, - researched_results, uploaded_images, train_of_thought, attached_file_context, diff --git a/src/khoj/routers/helpers.py b/src/khoj/routers/helpers.py index 38cf9174..a91f51a0 100644 --- a/src/khoj/routers/helpers.py +++ b/src/khoj/routers/helpers.py @@ -94,6 +94,7 @@ from khoj.processor.conversation.openai.gpt import ( ) from khoj.processor.conversation.utils import ( ChatEvent, + InformationCollectionIteration, ResponseWithThought, clean_json, clean_mermaidjs, @@ -1355,13 +1356,13 @@ async def agenerate_chat_response( online_results: Dict[str, Dict] = {}, code_results: Dict[str, Dict] = {}, operator_results: Dict[str, str] = {}, + research_results: List[InformationCollectionIteration] = [], inferred_queries: List[str] = [], conversation_commands: List[ConversationCommand] = [ConversationCommand.Default], user: KhojUser = None, client_application: ClientApplication = None, location_data: LocationData = None, user_name: Optional[str] = None, - meta_research: str = "", query_images: Optional[List[str]] = None, train_of_thought: List[Any] = [], query_files: str = None, @@ -1405,8 +1406,10 @@ async def agenerate_chat_response( query_to_run = q deepthought = False - if meta_research: - query_to_run = f"{q}\n\n{meta_research}\n" + if research_results: + compiled_research = "".join([r.summarizedResult for r in research_results if r.summarizedResult]) + if compiled_research: + query_to_run = f"{q}\n\n{compiled_research}\n" compiled_references = [] online_results = {} code_results = {}