mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-23 15:38:55 +01:00
When diagram generation fails, save to conversation log
- Update tool name when choosing tools to execute
This commit is contained in:
parent
7e662a05f8
commit
0eba6ce315
5 changed files with 37 additions and 18 deletions
|
@ -46,7 +46,7 @@ from khoj.routers.helpers import (
|
|||
FeedbackData,
|
||||
acreate_title_from_history,
|
||||
agenerate_chat_response,
|
||||
aget_relevant_information_sources,
|
||||
aget_relevant_tools_to_execute,
|
||||
construct_automation_created_message,
|
||||
create_automation,
|
||||
gather_raw_query_files,
|
||||
|
@ -752,7 +752,7 @@ async def chat(
|
|||
attached_file_context = gather_raw_query_files(query_files)
|
||||
|
||||
if conversation_commands == [ConversationCommand.Default] or is_automated_task:
|
||||
conversation_commands = await aget_relevant_information_sources(
|
||||
conversation_commands = await aget_relevant_tools_to_execute(
|
||||
q,
|
||||
meta_log,
|
||||
is_automated_task,
|
||||
|
@ -1164,8 +1164,27 @@ async def chat(
|
|||
inferred_queries.append(better_diagram_description_prompt)
|
||||
diagram_description = excalidraw_diagram_description
|
||||
else:
|
||||
async for result in send_llm_response(f"Failed to generate diagram. Please try again later."):
|
||||
error_message = "Failed to generate diagram. Please try again later."
|
||||
async for result in send_llm_response(error_message):
|
||||
yield result
|
||||
|
||||
await sync_to_async(save_to_conversation_log)(
|
||||
q,
|
||||
error_message,
|
||||
user,
|
||||
meta_log,
|
||||
user_message_time,
|
||||
inferred_queries=[better_diagram_description_prompt],
|
||||
client_application=request.user.client_app,
|
||||
conversation_id=conversation_id,
|
||||
compiled_references=compiled_references,
|
||||
online_results=online_results,
|
||||
code_results=code_results,
|
||||
query_images=uploaded_images,
|
||||
train_of_thought=train_of_thought,
|
||||
raw_query_files=raw_query_files,
|
||||
tracer=tracer,
|
||||
)
|
||||
return
|
||||
|
||||
content_obj = {
|
||||
|
|
|
@ -336,7 +336,7 @@ async def acheck_if_safe_prompt(system_prompt: str, user: KhojUser = None, lax:
|
|||
return is_safe, reason
|
||||
|
||||
|
||||
async def aget_relevant_information_sources(
|
||||
async def aget_relevant_tools_to_execute(
|
||||
query: str,
|
||||
conversation_history: dict,
|
||||
is_task: bool,
|
||||
|
|
|
@ -7,7 +7,7 @@ from freezegun import freeze_time
|
|||
from khoj.database.models import Agent, Entry, KhojUser
|
||||
from khoj.processor.conversation import prompts
|
||||
from khoj.processor.conversation.utils import message_to_log
|
||||
from khoj.routers.helpers import aget_relevant_information_sources
|
||||
from khoj.routers.helpers import aget_relevant_tools_to_execute
|
||||
from tests.helpers import ConversationFactory
|
||||
|
||||
SKIP_TESTS = True
|
||||
|
@ -735,7 +735,7 @@ async def test_get_correct_tools_online(client_offline_chat):
|
|||
user_query = "What's the weather in Patagonia this week?"
|
||||
|
||||
# Act
|
||||
tools = await aget_relevant_information_sources(user_query, {}, is_task=False)
|
||||
tools = await aget_relevant_tools_to_execute(user_query, {}, is_task=False)
|
||||
|
||||
# Assert
|
||||
tools = [tool.value for tool in tools]
|
||||
|
@ -750,7 +750,7 @@ async def test_get_correct_tools_notes(client_offline_chat):
|
|||
user_query = "Where did I go for my first battleship training?"
|
||||
|
||||
# Act
|
||||
tools = await aget_relevant_information_sources(user_query, {}, is_task=False)
|
||||
tools = await aget_relevant_tools_to_execute(user_query, {}, is_task=False)
|
||||
|
||||
# Assert
|
||||
tools = [tool.value for tool in tools]
|
||||
|
@ -765,7 +765,7 @@ async def test_get_correct_tools_online_or_general_and_notes(client_offline_chat
|
|||
user_query = "What's the highest point in Patagonia and have I been there?"
|
||||
|
||||
# Act
|
||||
tools = await aget_relevant_information_sources(user_query, {}, is_task=False)
|
||||
tools = await aget_relevant_tools_to_execute(user_query, {}, is_task=False)
|
||||
|
||||
# Assert
|
||||
tools = [tool.value for tool in tools]
|
||||
|
@ -782,7 +782,7 @@ async def test_get_correct_tools_general(client_offline_chat):
|
|||
user_query = "How many noble gases are there?"
|
||||
|
||||
# Act
|
||||
tools = await aget_relevant_information_sources(user_query, {}, is_task=False)
|
||||
tools = await aget_relevant_tools_to_execute(user_query, {}, is_task=False)
|
||||
|
||||
# Assert
|
||||
tools = [tool.value for tool in tools]
|
||||
|
@ -806,7 +806,7 @@ async def test_get_correct_tools_with_chat_history(client_offline_chat, default_
|
|||
chat_history = create_conversation(chat_log, default_user2)
|
||||
|
||||
# Act
|
||||
tools = await aget_relevant_information_sources(user_query, chat_history, is_task=False)
|
||||
tools = await aget_relevant_tools_to_execute(user_query, chat_history, is_task=False)
|
||||
|
||||
# Assert
|
||||
tools = [tool.value for tool in tools]
|
||||
|
|
|
@ -8,7 +8,7 @@ from freezegun import freeze_time
|
|||
from khoj.processor.conversation.openai.gpt import converse, extract_questions
|
||||
from khoj.processor.conversation.utils import message_to_log
|
||||
from khoj.routers.helpers import (
|
||||
aget_relevant_information_sources,
|
||||
aget_relevant_tools_to_execute,
|
||||
generate_online_subqueries,
|
||||
infer_webpage_urls,
|
||||
schedule_query,
|
||||
|
@ -538,7 +538,7 @@ async def test_select_data_sources_actor_chooses_to_search_notes(
|
|||
chat_client, user_query, expected_conversation_commands
|
||||
):
|
||||
# Act
|
||||
conversation_commands = await aget_relevant_information_sources(user_query, {}, False, False)
|
||||
conversation_commands = await aget_relevant_tools_to_execute(user_query, {}, False, False)
|
||||
|
||||
# Assert
|
||||
assert set(expected_conversation_commands) == set(conversation_commands)
|
||||
|
|
|
@ -8,7 +8,7 @@ from freezegun import freeze_time
|
|||
from khoj.database.models import Agent, Entry, KhojUser, LocalPdfConfig
|
||||
from khoj.processor.conversation import prompts
|
||||
from khoj.processor.conversation.utils import message_to_log
|
||||
from khoj.routers.helpers import aget_relevant_information_sources
|
||||
from khoj.routers.helpers import aget_relevant_tools_to_execute
|
||||
from tests.helpers import ConversationFactory
|
||||
|
||||
# Initialize variables for tests
|
||||
|
@ -719,7 +719,7 @@ async def test_get_correct_tools_online(chat_client):
|
|||
user_query = "What's the weather in Patagonia this week?"
|
||||
|
||||
# Act
|
||||
tools = await aget_relevant_information_sources(user_query, {}, False, False)
|
||||
tools = await aget_relevant_tools_to_execute(user_query, {}, False, False)
|
||||
|
||||
# Assert
|
||||
tools = [tool.value for tool in tools]
|
||||
|
@ -734,7 +734,7 @@ async def test_get_correct_tools_notes(chat_client):
|
|||
user_query = "Where did I go for my first battleship training?"
|
||||
|
||||
# Act
|
||||
tools = await aget_relevant_information_sources(user_query, {}, False, False)
|
||||
tools = await aget_relevant_tools_to_execute(user_query, {}, False, False)
|
||||
|
||||
# Assert
|
||||
tools = [tool.value for tool in tools]
|
||||
|
@ -749,7 +749,7 @@ async def test_get_correct_tools_online_or_general_and_notes(chat_client):
|
|||
user_query = "What's the highest point in Patagonia and have I been there?"
|
||||
|
||||
# Act
|
||||
tools = await aget_relevant_information_sources(user_query, {}, False, False)
|
||||
tools = await aget_relevant_tools_to_execute(user_query, {}, False, False)
|
||||
|
||||
# Assert
|
||||
tools = [tool.value for tool in tools]
|
||||
|
@ -766,7 +766,7 @@ async def test_get_correct_tools_general(chat_client):
|
|||
user_query = "How many noble gases are there?"
|
||||
|
||||
# Act
|
||||
tools = await aget_relevant_information_sources(user_query, {}, False, False)
|
||||
tools = await aget_relevant_tools_to_execute(user_query, {}, False, False)
|
||||
|
||||
# Assert
|
||||
tools = [tool.value for tool in tools]
|
||||
|
@ -790,7 +790,7 @@ async def test_get_correct_tools_with_chat_history(chat_client):
|
|||
chat_history = generate_history(chat_log)
|
||||
|
||||
# Act
|
||||
tools = await aget_relevant_information_sources(user_query, chat_history, False, False)
|
||||
tools = await aget_relevant_tools_to_execute(user_query, chat_history, False, False)
|
||||
|
||||
# Assert
|
||||
tools = [tool.value for tool in tools]
|
||||
|
|
Loading…
Reference in a new issue