Pass user name to document and online search actors prompts

This should improve the quality of personal information extraction
from document and online sources. The user name is only used when it
is set
This commit is contained in:
Debanjum Singh Solanky
2024-07-26 22:56:24 +05:30
parent eb5af38f33
commit a47a54f207
9 changed files with 42 additions and 11 deletions

View File

@@ -5,7 +5,7 @@ from typing import Dict, Optional
from langchain.schema import ChatMessage
from khoj.database.models import Agent
from khoj.database.models import Agent, KhojUser
from khoj.processor.conversation import prompts
from khoj.processor.conversation.openai.utils import (
chat_completion_with_backoff,
@@ -27,11 +27,13 @@ def extract_questions(
temperature=0,
max_tokens=100,
location_data: LocationData = None,
user: KhojUser = None,
):
"""
Infer search queries to retrieve relevant notes to answer user query
"""
location = f"{location_data.city}, {location_data.region}, {location_data.country}" if location_data else "Unknown"
username = prompts.user_name.format(name=user.get_full_name()) if user and user.get_full_name() else ""
# Extract Past User Message and Inferred Questions from Conversation Log
chat_history = "".join(
@@ -59,6 +61,7 @@ def extract_questions(
text=text,
yesterday_date=(today - timedelta(days=1)).strftime("%Y-%m-%d"),
location=location,
username=username,
)
messages = [ChatMessage(content=prompt, role="user")]