feat: default web_search to approximate location (#3180)#3195
feat: default web_search to approximate location (#3180)#3195lrg913427-dot wants to merge 1 commit intoopenai:mainfrom
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 07a9fba949
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| changed = True | ||
| result.append(tool) | ||
|
|
||
| return result if changed else tools |
There was a problem hiding this comment.
Return collected tools to avoid exhausting iterators
If tools is a one-shot iterable (e.g., generator/iterator), this function consumes it in the for loop and then returns the original iterable when changed is false. In that case the caller (all responses.* create/stream paths now using this helper) receives an already-exhausted iterable, so no tools are sent at all. This regression appears whenever users pass non-reiterable Iterable[ToolParam] values that either contain no web-search tool or only web-search tools that already have user_location.
Useful? React with 👍 / 👎.
Closes #3180.
When web_search tools are used without specifying user_location, the server defaults to injecting
country: "US"into the system prompt. This aligns SDK behavior with the OpenAI Playground by injectinguser_location: {type: approximate}as the default, preventing hidden US geolocation assumptions for non-US developers.Changes
src/openai/lib/_tools.py: Added_apply_web_search_default_location_tools()helper that injects defaultuser_locationinto web_search toolssrc/openai/resources/responses/responses.py: Applied preprocessing to all 6 tool parameter locationstests/lib/test_tools.py: 11 unit tests covering all edge casesBehavior
type: web_search*are unaffecteduser_locationare not overridden