From a757ecfd2bb03012a096ebfc65de14a0379f154a Mon Sep 17 00:00:00 2001 From: Debanjum Date: Tue, 10 Dec 2024 19:20:19 -0800 Subject: [PATCH] Put the generated assets message after the user query and fix prompt --- src/khoj/processor/conversation/prompts.py | 4 ++-- src/khoj/processor/conversation/utils.py | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/khoj/processor/conversation/prompts.py b/src/khoj/processor/conversation/prompts.py index f173b9f4..b1268e47 100644 --- a/src/khoj/processor/conversation/prompts.py +++ b/src/khoj/processor/conversation/prompts.py @@ -180,8 +180,8 @@ Improved Prompt: generated_assets_context = PromptTemplate.from_template( """ -Assets that you created have already been created to respond to the query. Below, there are references to the descriptions used to create the assets. -You can provide a summary of your reasoning from the information below or use it to respond to the original query. +You have ALREADY created the assets described below. They will automatically be added to the final response. +You can provide a summary of your reasoning from the information below or use it to respond to my previous query. Generated Assets: {generated_assets} diff --git a/src/khoj/processor/conversation/utils.py b/src/khoj/processor/conversation/utils.py index ae312f13..8de9cccf 100644 --- a/src/khoj/processor/conversation/utils.py +++ b/src/khoj/processor/conversation/utils.py @@ -468,6 +468,14 @@ def generate_chatml_messages_with_context( messages = [] + if not is_none_or_empty(generated_asset_results): + messages.append( + ChatMessage( + content=f"{prompts.generated_assets_context.format(generated_assets=yaml_dump(generated_asset_results))}\n\n", + role="user", + ) + ) + if not is_none_or_empty(user_message): messages.append( ChatMessage( @@ -482,11 +490,6 @@ def generate_chatml_messages_with_context( message_attached_files = gather_raw_query_files({file.name: file.content for file in generated_files}) messages.append(ChatMessage(content=message_attached_files, role="assistant")) - if not is_none_or_empty(generated_asset_results): - context_message += ( - f"{prompts.generated_assets_context.format(generated_assets=yaml_dump(generated_asset_results))}\n\n" - ) - if program_execution_context: program_context_text = "\n".join(program_execution_context) context_message += f"{prompts.additional_program_context.format(context=program_context_text)}\n"