Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 28 additions & 13 deletions parrot/clients/gpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
OpenAIModel.GPT_4_1_NANO.value,
OpenAIModel.GPT5_MINI.value,
OpenAIModel.GPT5.value,
OpenAIModel.GPT5_2.value,
OpenAIModel.GPT5_CHAT.value,
OpenAIModel.GPT5_PRO.value,
}
Expand Down Expand Up @@ -228,6 +229,17 @@ def _is_responses_model(self, model_str: str) -> bool:
ms = (model_str or "").strip()
return ms in RESPONSES_ONLY_MODELS

@staticmethod
def _resolve_deep_research_model(model_str: str) -> str:
"""Resolve the deep research model based on the requested model."""
normalized = (model_str or "").strip()
if normalized in {
OpenAIModel.O4_MINI.value,
OpenAIModel.O4_MINI_DEEP_RESEARCH.value,
}:
return OpenAIModel.O4_MINI_DEEP_RESEARCH.value
return OpenAIModel.O3_DEEP_RESEARCH.value
Comment on lines +232 to +241
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new GPT-5.2 model support and updated deep research routing logic lack test coverage. The codebase has comprehensive test coverage for OpenAI client functionality (see tests/test_openai_client.py), including existing deep research tests. New tests should be added to verify: 1) GPT-5.2 is properly added to STRUCTURED_OUTPUT_COMPATIBLE_MODELS and structured outputs work with it, 2) the _resolve_deep_research_model method correctly routes o4-mini to o4-mini-deep-research and other models to o3-deep-research, 3) the background flag is properly propagated through the Responses API, and 4) the memory_limit configuration is correctly added to the code_interpreter tool when deep_research is enabled.

Copilot uses AI. Check for mistakes.
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback



def _prepare_responses_args(self, *, messages, args):
"""
Expand Down Expand Up @@ -374,6 +386,8 @@ def _append_text(value: Any):
req["max_output_tokens"] = args["max_tokens"]
if "parallel_tool_calls" in args:
req["parallel_tool_calls"] = args["parallel_tool_calls"]
if "background" in args and args["background"] is not None:
req["background"] = args["background"]
return req

@staticmethod
Expand Down Expand Up @@ -612,12 +626,11 @@ async def ask(
# Deep research routing: switch to deep research model if requested
if deep_research:
# Use o3-deep-research as default deep research model
if model_str in {"gpt-4o-mini", "gpt-4o", "gpt-4-turbo", OpenAIModel.GPT4_1.value}:
model_str = "o3-deep-research"
self.logger.info(f"Deep research enabled: switching to {model_str}")
elif model_str not in RESPONSES_ONLY_MODELS:
# If not already a deep research model, switch to it
model_str = "o3-deep-research"
if model_str not in {
OpenAIModel.O3_DEEP_RESEARCH.value,
OpenAIModel.O4_MINI_DEEP_RESEARCH.value,
}:
model_str = self._resolve_deep_research_model(model_str)
self.logger.info(f"Deep research enabled: switching to {model_str}")

messages, conversation_session, system_prompt = await self._prepare_conversation_context(
Expand Down Expand Up @@ -664,7 +677,7 @@ async def ask(
if enable_code_interpreter:
research_tools.append({
"type": "code_interpreter",
"container": {"type": "auto"}
"container": {"type": "auto", "memory_limit": "4g"}
Comment on lines 677 to +680
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code_interpreter tool configuration includes a "container" field with "memory_limit": "4g". This syntax should be verified against OpenAI's actual API documentation for the Responses API and deep research models. While the format appears consistent with Docker memory limits used elsewhere in the codebase (see parrot/tools/codeinterpreter/executor.py), OpenAI's API may use different syntax or may not support the container.memory_limit parameter at all. If this parameter is not supported, the API call may fail with an "unknown_parameter" error.

Copilot uses AI. Check for mistakes.
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

})

self.logger.info(f"Deep research tools configured: {len(research_tools)} tools")
Expand Down Expand Up @@ -719,6 +732,8 @@ async def ask(
args['max_tokens'] = max_tokens or self.max_tokens
if temperature:
args['temperature'] = temperature
if deep_research and background:
args['background'] = True

# -------- ROUTING: Responses-only vs Chat -----------
use_responses = self._is_responses_model(model_str)
Expand Down Expand Up @@ -937,11 +952,11 @@ async def ask_stream(

# Deep research routing (same as in ask method)
if deep_research:
if model_str in {"gpt-4o-mini", "gpt-4o", "gpt-4-turbo", OpenAIModel.GPT4_1.value}:
model_str = "o3-deep-research"
self.logger.info(f"Deep research streaming enabled: switching to {model_str}")
elif model_str not in RESPONSES_ONLY_MODELS:
model_str = "o3-deep-research"
if model_str not in {
OpenAIModel.O3_DEEP_RESEARCH.value,
OpenAIModel.O4_MINI_DEEP_RESEARCH.value,
}:
model_str = self._resolve_deep_research_model(model_str)
self.logger.info(f"Deep research streaming enabled: switching to {model_str}")

messages, conversation_session, system_prompt = await self._prepare_conversation_context(
Expand Down Expand Up @@ -977,7 +992,7 @@ async def ask_stream(
if enable_code_interpreter:
research_tools.append({
"type": "code_interpreter",
"container": {"type": "auto"}
"container": {"type": "auto", "memory_limit": "4g"}
Comment on lines 992 to +995
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code_interpreter tool configuration includes a "container" field with "memory_limit": "4g". This syntax should be verified against OpenAI's actual API documentation for the Responses API and deep research models. While the format appears consistent with Docker memory limits used elsewhere in the codebase (see parrot/tools/codeinterpreter/executor.py), OpenAI's API may use different syntax or may not support the container.memory_limit parameter at all. If this parameter is not supported, the API call may fail with an "unknown_parameter" error.

Copilot uses AI. Check for mistakes.
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

})
self.logger.info(f"Deep research streaming tools: {len(research_tools)} tools")

Expand Down
1 change: 1 addition & 0 deletions parrot/models/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class OpenAIModel(Enum):
"""Enum class for OpenAI models."""
GPT5_MINI = "gpt-5-mini"
GPT5 = "gpt-5"
GPT5_2 = "gpt-5.2"
GPT5_CHAT = "gpt-5-chat-latest"
GPT5_PRO = "gpt-5-pro"
GPT5_NANO = "gpt-5-nano"
Expand Down