-
Notifications
You must be signed in to change notification settings - Fork 6
Add deep-research routing and GPT-5.2 model support to OpenAI client #550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1573045
da0df99
60f8b17
6b4a02e
2976ac0
216f295
bc520cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, | ||
| } | ||
|
|
@@ -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 | ||
|
|
||
|
|
||
| def _prepare_responses_args(self, *, messages, args): | ||
| """ | ||
|
|
@@ -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 | ||
|
|
@@ -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( | ||
|
|
@@ -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
|
||
| }) | ||
|
|
||
| self.logger.info(f"Deep research tools configured: {len(research_tools)} tools") | ||
|
|
@@ -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) | ||
|
|
@@ -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( | ||
|
|
@@ -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
|
||
| }) | ||
| self.logger.info(f"Deep research streaming tools: {len(research_tools)} tools") | ||
|
|
||
|
|
||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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