Resolve merge conflicts

This commit is contained in:
sabaimran 2024-10-23 19:30:47 -07:00 committed by Debanjum Singh Solanky
parent 30f9225021
commit 12b32a3d04
4 changed files with 14 additions and 29 deletions

View file

@ -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

View file

@ -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:

View file

@ -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,

View file

@ -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: