mirror of
https://github.com/khoj-ai/khoj.git
synced 2025-02-17 08:04:21 +00:00
Pass chat history to the summarize chat actor
This commit is contained in:
parent
7e3090060b
commit
67d0e59eac
3 changed files with 25 additions and 4 deletions
|
@ -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:
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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,
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue