Skip to content
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

gpt-4o-search-preview and gpt-4o-mini-search-preview chat completion models #837

Open
simonw opened this issue Mar 18, 2025 · 3 comments
Open
Labels
enhancement New feature or request openai

Comments

@simonw
Copy link
Owner

simonw commented Mar 18, 2025

Since gpt-4o-search-preview and gpt-4o-mini-search-preview are separate models I think it makes sense to support them directly as model selections (chat completions only). I'll file a new tickt for that.

Originally posted by @simonw in #831

@simonw simonw added enhancement New feature or request openai labels Mar 18, 2025
@simonw
Copy link
Owner Author

simonw commented Mar 18, 2025

This is likely blocked on:

Because that's needed to obey the OpenAI requirement to:

When displaying web results or information contained in web results to end users, inline citations must be made clearly visible and clickable in your user interface.

@simonw
Copy link
Owner Author

simonw commented Mar 18, 2025

Need to support some options:

        "web_search_options": {
            "search_context_size": "low"
        },

That's low or medium or high which has a big impact on price: https://platform.openai.com/docs/pricing#web-search

        "web_search_options": {
            "user_location": {
                "type": "approximate",
                "approximate": {
                    "country": "GB",
                    "city": "London",
                    "region": "London"
                }
            }
        },

Also accepts timezone.

@simonw
Copy link
Owner Author

simonw commented Mar 18, 2025

Streaming output from OpenAI looks like this:

curl -X POST "https://api.openai.com/v1/chat/completions" \
    -H "Authorization: Bearer $OPENAI_API_KEY" \
    -H "Content-type: application/json" \
    -d '{
        "model": "gpt-4o-search-preview",
        "stream": true,
        "web_search_options": {},
        "messages": [{
            "role": "user",
            "content": "What was a positive news story from today?"
        }]
    }'

Truncated:

data: {"id":"chatcmpl-3d393fb6-508b-4ae0-90bc-6fddbd84e9d8","object":"chat.completion.chunk","created":1742342019,"model":"gpt-4o-search-preview-2025-03-11","service_tier":"default","system_fingerprint":"","choices":[{"index":0,"delta":{"role":"assistant","content":"","refusal":null},"finish_reason":null}]}

data: {"id":"chatcmpl-3d393fb6-508b-4ae0-90bc-6fddbd84e9d8","object":"chat.completion.chunk","created":1742342019,"model":"gpt-4o-search-preview-2025-03-11","service_tier":"default","system_fingerprint":"","choices":[{"index":0,"delta":{"content":"As"},"finish_reason":null}]}

...

data: {"id":"chatcmpl-3d393fb6-508b-4ae0-90bc-6fddbd84e9d8","object":"chat.completion.chunk","created":1742342019,"model":"gpt-4o-search-preview-2025-03-11","service_tier":"default","system_fingerprint":"","choices":[{"index":0,"delta":{"annotations":[{"type":"url_citation","url_citation":{"end_index":432,"start_index":358,"title":"2025","url":"https://en.wikipedia.org/wiki/2025?utm_source=openai"}},{"type":"url_citation","url_citation":{"end_index":812,"start_index":738,"title":"2025","url":"https://en.wikipedia.org/wiki/2025?utm_source=openai"}},{"type":"url_citation","url_citation":{"end_index":1141,"start_index":1067,"title":"2025","url":"https://en.wikipedia.org/wiki/2025?utm_source=openai"}}]},"finish_reason":"stop"}]}

data: [DONE]

The citations all came back in that last data chunk:

{
    "id": "chatcmpl-3d393fb6-508b-4ae0-90bc-6fddbd84e9d8",
    "object": "chat.completion.chunk",
    "created": 1742342019,
    "model": "gpt-4o-search-preview-2025-03-11",
    "service_tier": "default",
    "system_fingerprint": "",
    "choices": [
        {
            "index": 0,
            "delta": {
                "annotations": [
                    {
                        "type": "url_citation",
                        "url_citation": {
                            "end_index": 432,
                            "start_index": 358,
                            "title": "2025",
                            "url": "https://en.wikipedia.org/wiki/2025?utm_source=openai"
                        }
                    },
                    {
                        "type": "url_citation",
                        "url_citation": {
                            "end_index": 812,
                            "start_index": 738,
                            "title": "2025",
                            "url": "https://en.wikipedia.org/wiki/2025?utm_source=openai"
                        }
                    },
                    {
                        "type": "url_citation",
                        "url_citation": {
                            "end_index": 1141,
                            "start_index": 1067,
                            "title": "2025",
                            "url": "https://en.wikipedia.org/wiki/2025?utm_source=openai"
                        }
                    }
                ]
            },
            "finish_reason": "stop"
        }
    ]
}

Full output here: https://gist.github.com/simonw/a3bf3c6ea865195268ccab612d6008a1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request openai
Projects
None yet
Development

No branches or pull requests

1 participant