OpenAI Conversation: Add web search support for new models (#143054)

Use a list of openai models for web search support in openai_conversation
This commit is contained in:
Evan Graham 2025-04-16 17:08:36 +01:00 committed by GitHub
parent f8b56c460e
commit 024ec2b153
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 4 deletions

View File

@ -63,6 +63,7 @@ from .const import (
RECOMMENDED_WEB_SEARCH_CONTEXT_SIZE,
RECOMMENDED_WEB_SEARCH_USER_LOCATION,
UNSUPPORTED_MODELS,
WEB_SEARCH_MODELS,
)
_LOGGER = logging.getLogger(__name__)
@ -160,9 +161,10 @@ class OpenAIOptionsFlow(OptionsFlow):
errors[CONF_CHAT_MODEL] = "model_not_supported"
if user_input.get(CONF_WEB_SEARCH):
if not user_input.get(
CONF_CHAT_MODEL, RECOMMENDED_CHAT_MODEL
).startswith("gpt-4o"):
if (
user_input.get(CONF_CHAT_MODEL, RECOMMENDED_CHAT_MODEL)
not in WEB_SEARCH_MODELS
):
errors[CONF_WEB_SEARCH] = "web_search_not_supported"
elif user_input.get(CONF_WEB_SEARCH_USER_LOCATION):
user_input.update(await self.get_location_data())

View File

@ -41,3 +41,12 @@ UNSUPPORTED_MODELS: list[str] = [
"gpt-4o-mini-realtime-preview",
"gpt-4o-mini-realtime-preview-2024-12-17",
]
WEB_SEARCH_MODELS: list[str] = [
"gpt-4.1",
"gpt-4.1-mini",
"gpt-4o",
"gpt-4o-search-preview",
"gpt-4o-mini",
"gpt-4o-mini-search-preview",
]

View File

@ -40,7 +40,7 @@
},
"error": {
"model_not_supported": "This model is not supported, please select a different model",
"web_search_not_supported": "Web search is only supported for gpt-4o and gpt-4o-mini models"
"web_search_not_supported": "Web search is not supported by this model"
}
},
"selector": {