Use operator context consistently as a dict[str, str] of query, result

This commit is contained in:
Debanjum
2025-05-19 09:21:42 -07:00
parent 07e33994f0
commit cc355f93fc
8 changed files with 15 additions and 15 deletions

View File

@@ -144,7 +144,7 @@ async def converse_anthropic(
user_query,
online_results: Optional[Dict[str, Dict]] = None,
code_results: Optional[Dict[str, Dict]] = None,
operator_results: Optional[List[str]] = None,
operator_results: Optional[Dict[str, str]] = None,
conversation_log={},
model: Optional[str] = "claude-3-7-sonnet-latest",
api_key: Optional[str] = None,

View File

@@ -166,7 +166,7 @@ async def converse_gemini(
user_query,
online_results: Optional[Dict[str, Dict]] = None,
code_results: Optional[Dict[str, Dict]] = None,
operator_results: Optional[List[str]] = None,
operator_results: Optional[Dict[str, str]] = None,
conversation_log={},
model: Optional[str] = "gemini-2.0-flash",
api_key: Optional[str] = None,

View File

@@ -169,7 +169,7 @@ async def converse_openai(
user_query,
online_results: Optional[Dict[str, Dict]] = None,
code_results: Optional[Dict[str, Dict]] = None,
operator_results: Optional[List[str]] = None,
operator_results: Optional[Dict[str, str]] = None,
conversation_log={},
model: str = "gpt-4o-mini",
api_key: Optional[str] = None,

View File

@@ -91,7 +91,7 @@ class InformationCollectionIteration:
context: list = None,
onlineContext: dict = None,
codeContext: dict = None,
operatorContext: str = None,
operatorContext: dict[str, str] = None,
summarizedResult: str = None,
warning: str = None,
):
@@ -267,7 +267,7 @@ async def save_to_conversation_log(
compiled_references: List[Dict[str, Any]] = [],
online_results: Dict[str, Any] = {},
code_results: Dict[str, Any] = {},
operator_results: Dict[str, Any] = {},
operator_results: Dict[str, str] = {},
inferred_queries: List[str] = [],
intent_type: str = "remember",
client_application: ClientApplication = None,

View File

@@ -145,6 +145,7 @@ async def operate_browser(
operator_agent.reset()
yield {
"text": user_input_message or response,
"query": query,
"result": user_input_message or response,
"webpages": [{"link": url, "snippet": ""} for url in environment.visited_urls],
}

View File

@@ -886,7 +886,7 @@ async def chat(
researched_results = ""
online_results: Dict = dict()
code_results: Dict = dict()
operator_results: List[str] = []
operator_results: Dict[str, str] = {}
generated_asset_results: Dict = dict()
## Extract Document References
compiled_references: List[Any] = []
@@ -962,8 +962,7 @@ async def chat(
if research_result.context:
compiled_references.extend(research_result.context)
if research_result.operatorContext:
operator_results.append(research_result.operatorContext)
operator_results.update(research_result.operatorContext)
researched_results += research_result.summarizedResult
else:
@@ -1237,7 +1236,7 @@ async def chat(
if isinstance(result, dict) and ChatEvent.STATUS in result:
yield result[ChatEvent.STATUS]
else:
operator_results.append(result["text"])
operator_results = {result["query"]: result["result"]}
# Add webpages visited while operating browser to references
if result.get("webpages"):
if not online_results.get(defiltered_query):

View File

@@ -1354,7 +1354,7 @@ async def agenerate_chat_response(
compiled_references: List[Dict] = [],
online_results: Dict[str, Dict] = {},
code_results: Dict[str, Dict] = {},
operator_results: List[str] = [],
operator_results: Dict[str, str] = {},
inferred_queries: List[str] = [],
conversation_commands: List[ConversationCommand] = [ConversationCommand.Default],
user: KhojUser = None,
@@ -1411,7 +1411,7 @@ async def agenerate_chat_response(
compiled_references = []
online_results = {}
code_results = {}
operator_results = []
operator_results = {}
deepthought = True
chat_model = await ConversationAdapters.aget_valid_chat_model(user, conversation, is_subscribed)

View File

@@ -237,7 +237,7 @@ async def execute_information_collection(
online_results: Dict = dict()
code_results: Dict = dict()
document_results: List[Dict[str, str]] = []
operator_results: str = ""
operator_results: Dict[str, str] = {}
summarize_files: str = ""
this_iteration = InformationCollectionIteration(tool=None, query=query)
@@ -421,7 +421,7 @@ async def execute_information_collection(
if isinstance(result, dict) and ChatEvent.STATUS in result:
yield result[ChatEvent.STATUS]
else:
operator_results = result["text"] # type: ignore
operator_results = {result["query"]: result["result"]}
this_iteration.operatorContext = operator_results
# Add webpages visited while operating browser to references
if result.get("webpages"):
@@ -478,7 +478,7 @@ async def execute_information_collection(
if code_results:
results_data += f"\n<code_results>\n{yaml.dump(truncate_code_context(code_results), allow_unicode=True, sort_keys=False, default_flow_style=False)}\n</code_results>"
if operator_results:
results_data += f"\n<browser_operator_results>\n{operator_results}\n</browser_operator_results>"
results_data += f"\n<browser_operator_results>\n{next(iter(operator_results.values()))}\n</browser_operator_results>"
if summarize_files:
results_data += f"\n<summarized_files>\n{yaml.dump(summarize_files, allow_unicode=True, sort_keys=False, default_flow_style=False)}\n</summarized_files>"
if this_iteration.warning: