mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-05 21:29:11 +00:00
Format online, notes, code context with YAML to be legibile for LLM
This commit is contained in:
@@ -18,6 +18,7 @@ from khoj.processor.conversation.utils import (
|
||||
)
|
||||
from khoj.utils.helpers import ConversationCommand, is_none_or_empty
|
||||
from khoj.utils.rawconfig import LocationData
|
||||
from khoj.utils.yaml import yaml_dump
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -155,7 +156,6 @@ def converse(
|
||||
"""
|
||||
# Initialize Variables
|
||||
current_date = datetime.now()
|
||||
compiled_references = "\n\n".join({f"# File: {item['file']}\n## {item['compiled']}\n" for item in references})
|
||||
|
||||
if agent and agent.personality:
|
||||
system_prompt = prompts.custom_personality.format(
|
||||
@@ -179,7 +179,7 @@ def converse(
|
||||
system_prompt = f"{system_prompt}\n{user_name_prompt}"
|
||||
|
||||
# Get Conversation Primer appropriate to Conversation Type
|
||||
if conversation_commands == [ConversationCommand.Notes] and is_none_or_empty(compiled_references):
|
||||
if conversation_commands == [ConversationCommand.Notes] and is_none_or_empty(references):
|
||||
completion_func(chat_response=prompts.no_notes_found.format())
|
||||
return iter([prompts.no_notes_found.format()])
|
||||
elif conversation_commands == [ConversationCommand.Online] and is_none_or_empty(online_results):
|
||||
@@ -187,12 +187,12 @@ def converse(
|
||||
return iter([prompts.no_online_results_found.format()])
|
||||
|
||||
context_message = ""
|
||||
if not is_none_or_empty(compiled_references):
|
||||
context_message = f"{prompts.notes_conversation.format(references=compiled_references)}\n\n"
|
||||
if not is_none_or_empty(references):
|
||||
context_message = f"{prompts.notes_conversation.format(references=yaml_dump(references))}\n\n"
|
||||
if not is_none_or_empty(online_results):
|
||||
context_message += f"{prompts.online_search_conversation.format(online_results=str(online_results))}\n\n"
|
||||
context_message += f"{prompts.online_search_conversation.format(online_results=yaml_dump(online_results))}\n\n"
|
||||
if not is_none_or_empty(code_results):
|
||||
context_message += f"{prompts.code_executed_context.format(code_results=str(code_results))}\n\n"
|
||||
context_message += f"{prompts.code_executed_context.format(code_results=yaml_dump(code_results))}\n\n"
|
||||
context_message = context_message.strip()
|
||||
|
||||
# Setup Prompt with Primer or Conversation History
|
||||
|
||||
Reference in New Issue
Block a user