Skip to content

feat(OpenAI): Support annotations in Chat response. (Web Search) #564

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 61 commits into from
May 1, 2025

Conversation

Saraphoo
Copy link
Contributor

@Saraphoo Saraphoo commented Apr 24, 2025

What:

  • Bug Fix
  • New Feature

Description:

Enabling SDK's ability to use web_search_options and return annotations.

Related:

fixes: #552

Copy link
Collaborator

@iBotPeaches iBotPeaches left a comment

Choose a reason for hiding this comment

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

With a simple run of Pint - you'll probably have a large chunk of these cs issues resolved. So haven't done a thorough review.

You also want to make a test to assert the new object (annotations) is valid. You can see this pattern done on on logprobs. You basically can just extract the exact chunk of annotations to pass it to your new class (CreateResponseChoiceAnnotation) so you can assert those are extracted properly.

@Saraphoo Saraphoo marked this pull request as ready for review April 29, 2025 15:48
Copy link
Collaborator

@iBotPeaches iBotPeaches left a comment

Choose a reason for hiding this comment

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

Some quick comments. Can you swap double quotes for single into the docblocks? I'll review more later

Copy link
Collaborator

@iBotPeaches iBotPeaches left a comment

Choose a reason for hiding this comment

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

Very close - works well, we just introduced an extra layer of arrays which needs to be removed.

@iBotPeaches iBotPeaches changed the title Chat Support WebSearch feat(OpenAI): Support annotations in Chat response. (Web Search) Apr 30, 2025
Copy link
Collaborator

@iBotPeaches iBotPeaches left a comment

Choose a reason for hiding this comment

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

All looks good now. I tested it out with this sample and it works as I expect.

        $result = OpenAI::chat()->create([
            'model' => 'gpt-4o-mini-search-preview',
            'messages' => [
                [
                    'role' => 'user',
                    'content' => 'Could you find 2 articles on french drains for OSHAA certification?',
                ]
            ],
            'web_search_options' => [
                'user_location' => [
                    'type' => 'approximate',
                    'approximate' => [
                        'country' => 'US',
                        'city' => 'Tampa',
                    ]
                ]
            ],
        ]);

@iBotPeaches
Copy link
Collaborator

I made a few changes to merge:

  • I aligned the sample to a model that supports searching in case people stumble upon the tests
  • I removed some extra newlines
  • I added some test cases around the Response payload alongside toolCalls for consistency

@iBotPeaches iBotPeaches merged commit 9bd5a25 into openai-php:main May 1, 2025
10 checks passed
@iBotPeaches iBotPeaches added the enhancement New feature or request label May 1, 2025
@iBotPeaches
Copy link
Collaborator

thanks! and congrats on 1st pr!

@iBotPeaches iBotPeaches deleted the chat-support-websearch branch May 1, 2025 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Add support for web search
2 participants