Skip to content

Conversation

@majiayu000
Copy link

Fixes #1333

Changes

  • Add WebSearchOptions, UserLocation, and ApproximateLocation types to support OpenAI web search
  • Add WithWebSearch call option for enabling web search on supported models (gpt-4o-search-preview)
  • Implement conversion from llms types to OpenAI client types
  • Add comprehensive tests for web search options marshaling and conversion

Usage

llm.GenerateContent(ctx, messages,
    llms.WithWebSearch(&llms.WebSearchOptions{
        SearchContextSize: "high",
        UserLocation: &llms.UserLocation{
            Type: "approximate",
            Approximate: &llms.ApproximateLocation{
                Country: "US",
                City:    "San Francisco",
            },
        },
    }),
)

Add support for OpenAI's web search feature in the Chat Completions API.
This enables users to use search-enabled models like gpt-4o-search-preview
with web search capabilities.

Changes:
- Add WebSearchOptions, UserLocation, and ApproximateLocation structs
  to both llms and openaiclient packages
- Add WebSearchOptions field to ChatRequest for API requests
- Add WithWebSearch() CallOption for configuring web search
- Add webSearchOptionsFromCallOptions() conversion function
- Add comprehensive unit tests for web search functionality

Signed-off-by: majiayu000 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Web search tool for OpenAI Client

1 participant