-
Notifications
You must be signed in to change notification settings - Fork 1
fix web search tool #128
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
Merged
Merged
fix web search tool #128
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -755,32 +755,14 @@ def _responses_messages_to_string(messages: list[dict[str, Any]]) -> str: | |
| ) | ||
|
|
||
| if message["action"]["type"] == "search": | ||
| if "annotations" in message: | ||
| annotations = message["annotations"] | ||
| else: | ||
| next_text_message = adjusted_messages[i + 1] | ||
| if next_text_message["type"] != "message": | ||
| continue | ||
| next_text_content = next_text_message["content"][0] | ||
| if next_text_content["type"] != "output_text": | ||
| continue | ||
| annotations = next_text_content["annotations"] | ||
|
|
||
| urls = list( | ||
| { | ||
| (annotation["url"], annotation["title"]) | ||
| for annotation in annotations | ||
| if annotation["type"] == "url_citation" | ||
| } | ||
| ) | ||
| urls = list({source["url"] for source in message["action"]["sources"] if source["type"] == "url"}) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you confirm that you tested this update on both gpt-4.1 series and gpt-5 series models?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes |
||
|
|
||
| with ThreadPoolExecutor() as executor: | ||
|
|
||
| def extract_text(pair: tuple[str, str]) -> str: | ||
| def extract_text(url: str) -> str: | ||
| fallback_text = "Response is not shown, but the LLM can still access it. Assume that whatever the LLM references in this URL is true." | ||
|
|
||
| try: | ||
| url = pair[0] | ||
| if url in _url_cache: | ||
| return _url_cache[url] | ||
|
|
||
|
|
@@ -814,10 +796,9 @@ def extract_text(pair: tuple[str, str]) -> str: | |
| websites = [ | ||
| { | ||
| "url": url, | ||
| "title": title, | ||
| "content": data, | ||
| } | ||
| for (url, title), data in zip(urls, requests) | ||
| for url, data in zip(urls, requests) | ||
| ] | ||
|
|
||
| tool_call = { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Could you cover this?
Code:
Has
'content': [{'annotations': [{'end_index': 401,
'start_index': 298,
'title': 'New Toyota Innova Crysta Review (2.8-AT and 2.4-MT) | Motoroids',
'type': 'url_citation',
'url': 'https://www.motoroids.com/reviews/new-toyota-innova-crysta-review-2-8-at-and-2-4-mt/'},
type:
url_citationUh oh!
There was an error while loading. Please reload this page.
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.
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.
@aditya1503 You forgot to put
include=["web_search_call.action.sources"]in your message call.Uh oh!
There was an error while loading. Please reload this page.
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.
@Tonyhrule are you able to raise an informative error message when that happens? That'll probably happen often? Especially given only one person has ever tried your code and they forgot to add it