From 12b32a3d04b1f2e3bc2981dba223205ff1cbbb80 Mon Sep 17 00:00:00 2001 From: sabaimran Date: Wed, 23 Oct 2024 19:30:47 -0700 Subject: [PATCH] Resolve merge conflicts --- src/khoj/processor/conversation/utils.py | 3 +++ src/khoj/processor/tools/online_search.py | 13 +++++++++---- src/khoj/routers/helpers.py | 23 +---------------------- src/khoj/routers/research.py | 4 +--- 4 files changed, 14 insertions(+), 29 deletions(-) diff --git a/src/khoj/processor/conversation/utils.py b/src/khoj/processor/conversation/utils.py index 76de46ec..e8ef32f8 100644 --- a/src/khoj/processor/conversation/utils.py +++ b/src/khoj/processor/conversation/utils.py @@ -122,6 +122,9 @@ def construct_chat_history(conversation_history: dict, n: int = 4, agent_name="A elif chat["by"] == "khoj" and ("text-to-image" in chat["intent"].get("type")): chat_history += f"User: {chat['intent']['query']}\n" chat_history += f"{agent_name}: [generated image redacted for space]\n" + elif chat["by"] == "khoj" and ("excalidraw" in chat["intent"].get("type")): + chat_history += f"User: {chat['intent']['query']}\n" + chat_history += f"{agent_name}: {chat['intent']['inferred-queries'][0]}\n" return chat_history diff --git a/src/khoj/processor/tools/online_search.py b/src/khoj/processor/tools/online_search.py index 7a098721..739d4c70 100644 --- a/src/khoj/processor/tools/online_search.py +++ b/src/khoj/processor/tools/online_search.py @@ -4,7 +4,7 @@ import logging import os import urllib.parse from collections import defaultdict -from typing import Callable, Dict, List, Optional, Tuple, Union +from typing import Any, Callable, Dict, List, Optional, Tuple, Union import aiohttp from bs4 import BeautifulSoup @@ -94,11 +94,16 @@ async def search_online( # Gather distinct web pages from organic results for subqueries without an instant answer. # Content of web pages is directly available when Jina is used for search. - webpages = set() + webpages: Dict[str, Dict] = {} for subquery in response_dict: + if "answerBox" in response_dict[subquery]: + continue for organic in response_dict[subquery].get("organic", [])[:max_webpages_to_read]: - if "answerBox" not in response_dict[subquery]: - webpages.add(organic.get("link"), {"queries": {subquery}, "content": organic.get("content")}) + link = organic.get("link") + if link in webpages: + webpages[link]["queries"].add(subquery) + else: + webpages[link] = {"queries": {subquery}, "content": organic.get("content")} # Read, extract relevant info from the retrieved web pages if webpages: diff --git a/src/khoj/routers/helpers.py b/src/khoj/routers/helpers.py index a28d8ec2..2585f77d 100644 --- a/src/khoj/routers/helpers.py +++ b/src/khoj/routers/helpers.py @@ -82,7 +82,6 @@ from khoj.processor.conversation.google.gemini_chat import ( converse_gemini, gemini_send_message_to_model, ) -from khoj.processor.conversation.helpers import send_message_to_model_wrapper from khoj.processor.conversation.offline.chat_model import ( converse_offline, send_message_to_model_offline, @@ -214,21 +213,6 @@ def get_next_url(request: Request) -> str: return urljoin(str(request.base_url).rstrip("/"), next_path) -def construct_chat_history(conversation_history: dict, n: int = 4, agent_name="AI") -> str: - chat_history = "" - for chat in conversation_history.get("chat", [])[-n:]: - if chat["by"] == "khoj" and chat["intent"].get("type") in ["remember", "reminder", "summarize"]: - chat_history += f"User: {chat['intent']['query']}\n" - chat_history += f"{agent_name}: {chat['message']}\n" - elif chat["by"] == "khoj" and ("text-to-image" in chat["intent"].get("type")): - chat_history += f"User: {chat['intent']['query']}\n" - chat_history += f"{agent_name}: [generated image redacted for space]\n" - elif chat["by"] == "khoj" and ("excalidraw" in chat["intent"].get("type")): - chat_history += f"User: {chat['intent']['query']}\n" - chat_history += f"{agent_name}: {chat['intent']['inferred-queries'][0]}\n" - return chat_history - - def get_conversation_command(query: str, any_references: bool = False) -> ConversationCommand: if query.startswith("/notes"): return ConversationCommand.Notes @@ -1129,9 +1113,9 @@ def generate_chat_response( if conversation_config.model_type == "offline": loaded_model = state.offline_chat_processor_config.loaded_model chat_response = converse_offline( + user_query=query_to_run, references=compiled_references, online_results=online_results, - user_query=query_to_run, loaded_model=loaded_model, conversation_log=meta_log, completion_func=partial_completion, @@ -1151,7 +1135,6 @@ def generate_chat_response( chat_response = converse( compiled_references, query_to_run, - q, query_images=query_images, online_results=online_results, code_results=code_results, @@ -1195,10 +1178,6 @@ def generate_chat_response( online_results, code_results, meta_log, - q, - query_images=query_images, - online_results=online_results, - conversation_log=meta_log, model=conversation_config.chat_model, api_key=api_key, completion_func=partial_completion, diff --git a/src/khoj/routers/research.py b/src/khoj/routers/research.py index 84577ca7..d1578b5b 100644 --- a/src/khoj/routers/research.py +++ b/src/khoj/routers/research.py @@ -87,14 +87,12 @@ async def apick_next_tool( max_iterations=max_iterations, ) - chat_model_option = await ConversationAdapters.aget_advanced_conversation_config(user) - with timer("Chat actor: Infer information sources to refer", logger): response = await send_message_to_model_wrapper( function_planning_prompt, response_type="json_object", user=user, - chat_model_option=chat_model_option, + query_images=query_images, ) try: