Pass chat history to the summarize chat actor

This commit is contained in:
Debanjum Singh Solanky 2024-10-07 17:34:58 -07:00
parent 7e3090060b
commit 67d0e59eac
3 changed files with 25 additions and 4 deletions

View file

@ -411,6 +411,10 @@ Tell the user exactly what the document says in response to their query, while a
extract_relevant_summary = PromptTemplate.from_template(
"""
{personality_context}
Conversation History:
{chat_history}
Target Query: {query}
Document Contents:

View file

@ -758,7 +758,12 @@ async def chat(
yield result
response = await extract_relevant_summary(
q, contextual_data, subscribed=subscribed, uploaded_image_url=uploaded_image_url, agent=agent
q,
contextual_data,
conversation_history=meta_log,
subscribed=subscribed,
uploaded_image_url=uploaded_image_url,
agent=agent,
)
response_log = str(response)
async for result in send_llm_response(response_log):
@ -1238,7 +1243,11 @@ async def get_chat(
yield result
response = await extract_relevant_summary(
q, contextual_data, subscribed=subscribed, uploaded_image_url=uploaded_image_url
q,
contextual_data,
conversation_history=meta_log,
subscribed=subscribed,
uploaded_image_url=uploaded_image_url,
)
response_log = str(response)
async for result in send_llm_response(response_log):

View file

@ -208,7 +208,7 @@ def get_next_url(request: Request) -> str:
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"]:
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")):
@ -574,7 +574,12 @@ async def extract_relevant_info(q: str, corpus: str, subscribed: bool, agent: Ag
async def extract_relevant_summary(
q: str, corpus: str, subscribed: bool = False, uploaded_image_url: str = None, agent: Agent = None
q: str,
corpus: str,
conversation_history: dict,
subscribed: bool = False,
uploaded_image_url: str = None,
agent: Agent = None,
) -> Union[str, None]:
"""
Extract relevant information for a given query from the target corpus
@ -587,8 +592,11 @@ async def extract_relevant_summary(
prompts.personality_context.format(personality=agent.personality) if agent and agent.personality else ""
)
chat_history = construct_chat_history(conversation_history)
extract_relevant_information = prompts.extract_relevant_summary.format(
query=q,
chat_history=chat_history,
corpus=corpus.strip(),
personality_context=personality_context,
)