From 33689feb9198ba3346c0fdb5ae9195a996b57697 Mon Sep 17 00:00:00 2001 From: Debanjum Date: Fri, 9 May 2025 19:07:39 -0600 Subject: [PATCH] Handle more openai response types for better rendering and error avoidance The reasoning messages in openai cua needs to be passed back or some such. Else it throws missing response with required id error. Folks are confused about expected behavior for this online as well. The documentation to handle this seems to be sparse, unclear. --- src/khoj/processor/operator/operator_actions.py | 7 +++++++ src/khoj/processor/operator/operator_agent_openai.py | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/khoj/processor/operator/operator_actions.py b/src/khoj/processor/operator/operator_actions.py index 435083cd..05a65d01 100644 --- a/src/khoj/processor/operator/operator_actions.py +++ b/src/khoj/processor/operator/operator_actions.py @@ -119,6 +119,12 @@ class RequestUserAction(BaseAction): request: str +class NoopAction(BaseAction): + """No operation action.""" + + type: Literal["noop"] = "noop" + + OperatorAction = Union[ ClickAction, DoubleClickAction, @@ -139,4 +145,5 @@ OperatorAction = Union[ GotoAction, BackAction, RequestUserAction, + NoopAction, ] diff --git a/src/khoj/processor/operator/operator_agent_openai.py b/src/khoj/processor/operator/operator_agent_openai.py index 8ff0ae4a..47696f8c 100644 --- a/src/khoj/processor/operator/operator_agent_openai.py +++ b/src/khoj/processor/operator/operator_agent_openai.py @@ -160,7 +160,11 @@ class OpenAIOperatorAgent(OperatorAgent): except Exception as e: logger.error(f"Error converting OpenAI action {action_type}: {e}") content = f"Error: {action_type}: {e}" - + elif block.type == "message": + rendered_response["text"] = response.output_text + elif block.type == "reasoning": + actions.append(NoopAction()) + action_results.append(block) if action_to_run or content: actions.append(action_to_run) if action_to_run or content: