Pass background context to iterating chat director

This commit is contained in:
Debanjum Singh Solanky
2024-10-09 19:00:54 -07:00
parent 028b6e6379
commit a6905a9f0c
3 changed files with 21 additions and 3 deletions

View File

@@ -498,6 +498,11 @@ You are an extremely methodical planner. Your goal is to make a plan to execute
If you already know the answer to the question, return an empty response, e.g., {{}}.
Background Context:
- Current Date: {day_of_week}, {current_date}
- User's Location: {location}
- {username}
Which of the data sources listed below you would use to answer the user's question? You **only** have access to the following data sources:
{tools}
@@ -523,8 +528,7 @@ previous_iteration = PromptTemplate.from_template(
data_source: {data_source}
query: {query}
summary: {summary}
---
""".strip()
---"""
)
pick_relevant_information_collection_tools = PromptTemplate.from_template(

View File

@@ -713,6 +713,7 @@ async def chat(
uploaded_image_url=uploaded_image_url,
agent=agent,
send_status_func=partial(send_event, ChatEvent.STATUS),
user_name=user_name,
location=location,
file_filters=conversation.file_filters if conversation else [],
):

View File

@@ -1,5 +1,6 @@
import json
import logging
from datetime import datetime
from typing import Any, Callable, Dict, List, Optional
from fastapi import Request
@@ -48,6 +49,8 @@ async def apick_next_tool(
conversation_history: dict,
subscribed: bool,
uploaded_image_url: str = None,
location: LocationData = None,
user_name: str = None,
agent: Agent = None,
previous_iterations: List[InformationCollectionIteration] = None,
):
@@ -84,12 +87,21 @@ async def apick_next_tool(
prompts.personality_context.format(personality=agent.personality) if agent and agent.personality else ""
)
# Extract Past User Message and Inferred Questions from Conversation Log
today = datetime.today()
location_data = f"{location}" if location else "Unknown"
username = prompts.user_name.format(name=user_name) if user_name else ""
# TODO Add current date/time to the query
function_planning_prompt = prompts.plan_function_execution.format(
query=query,
tools=tool_options_str,
chat_history=chat_history,
personality_context=personality_context,
current_date=today.strftime("%Y-%m-%d"),
day_of_week=today.strftime("%A"),
username=username,
location=location_data,
previous_iterations=previous_iterations_history,
)
@@ -135,6 +147,7 @@ async def execute_information_collection(
uploaded_image_url: str = None,
agent: Agent = None,
send_status_func: Optional[Callable] = None,
user_name: str = None,
location: LocationData = None,
file_filters: List[str] = [],
):
@@ -150,7 +163,7 @@ async def execute_information_collection(
result: str = ""
this_iteration = await apick_next_tool(
query, conversation_history, subscribed, uploaded_image_url, agent, previous_iterations
query, conversation_history, subscribed, uploaded_image_url, location, user_name, agent, previous_iterations
)
if this_iteration.data_source == ConversationCommand.Notes:
## Extract Document References