Skip to content

Commit 275670a

Browse files
authored
Add support for gpt-5.1 (home-assistant#156612)
1 parent d0d6252 commit 275670a

File tree

4 files changed

+63
-4
lines changed

4 files changed

+63
-4
lines changed

homeassistant/components/openai_conversation/config_flow.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,16 +338,21 @@ async def async_step_model(
338338
options.pop(CONF_CODE_INTERPRETER)
339339

340340
if model.startswith(("o", "gpt-5")) and not model.startswith("gpt-5-pro"):
341+
if model.startswith("gpt-5.1"):
342+
reasoning_options = ["none", "low", "medium", "high"]
343+
elif model.startswith("gpt-5"):
344+
reasoning_options = ["minimal", "low", "medium", "high"]
345+
else:
346+
reasoning_options = ["low", "medium", "high"]
347+
341348
step_schema.update(
342349
{
343350
vol.Optional(
344351
CONF_REASONING_EFFORT,
345352
default=RECOMMENDED_REASONING_EFFORT,
346353
): SelectSelector(
347354
SelectSelectorConfig(
348-
options=["low", "medium", "high"]
349-
if model.startswith("o")
350-
else ["minimal", "low", "medium", "high"],
355+
options=reasoning_options,
351356
translation_key=CONF_REASONING_EFFORT,
352357
mode=SelectSelectorMode.DROPDOWN,
353358
)

homeassistant/components/openai_conversation/entity.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,9 @@ async def _async_handle_chat_log(
510510
"verbosity": options.get(CONF_VERBOSITY, RECOMMENDED_VERBOSITY)
511511
}
512512

513+
if model_args["model"].startswith("gpt-5.1"):
514+
model_args["prompt_cache_retention"] = "24h"
515+
513516
tools: list[ToolParam] = []
514517
if chat_log.llm_api:
515518
tools = [

homeassistant/components/openai_conversation/strings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@
146146
"high": "[%key:common::state::high%]",
147147
"low": "[%key:common::state::low%]",
148148
"medium": "[%key:common::state::medium%]",
149-
"minimal": "Minimal"
149+
"minimal": "Minimal",
150+
"none": "None"
150151
}
151152
},
152153
"search_context_size": {

tests/components/openai_conversation/test_config_flow.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,56 @@ async def test_subentry_unsupported_model(
235235
assert subentry_flow["errors"] == {"chat_model": "model_not_supported"}
236236

237237

238+
@pytest.mark.parametrize(
239+
("model", "reasoning_effort_options"),
240+
[
241+
("o4-mini", ["low", "medium", "high"]),
242+
("gpt-5", ["minimal", "low", "medium", "high"]),
243+
("gpt-5.1", ["none", "low", "medium", "high"]),
244+
],
245+
)
246+
async def test_subentry_reasoning_effort_list(
247+
hass: HomeAssistant,
248+
mock_config_entry,
249+
mock_init_component,
250+
model,
251+
reasoning_effort_options,
252+
) -> None:
253+
"""Test the list reasoning effort options."""
254+
subentry = next(iter(mock_config_entry.subentries.values()))
255+
subentry_flow = await mock_config_entry.start_subentry_reconfigure_flow(
256+
hass, subentry.subentry_id
257+
)
258+
assert subentry_flow["type"] is FlowResultType.FORM
259+
assert subentry_flow["step_id"] == "init"
260+
261+
# Configure initial step
262+
subentry_flow = await hass.config_entries.subentries.async_configure(
263+
subentry_flow["flow_id"],
264+
{
265+
CONF_RECOMMENDED: False,
266+
CONF_PROMPT: "Speak like a pirate",
267+
CONF_LLM_HASS_API: ["assist"],
268+
},
269+
)
270+
assert subentry_flow["type"] is FlowResultType.FORM
271+
assert subentry_flow["step_id"] == "advanced"
272+
273+
# Configure advanced step
274+
subentry_flow = await hass.config_entries.subentries.async_configure(
275+
subentry_flow["flow_id"],
276+
{
277+
CONF_CHAT_MODEL: model,
278+
},
279+
)
280+
assert subentry_flow["type"] is FlowResultType.FORM
281+
assert subentry_flow["step_id"] == "model"
282+
assert (
283+
subentry_flow["data_schema"].schema[CONF_REASONING_EFFORT].config["options"]
284+
== reasoning_effort_options
285+
)
286+
287+
238288
async def test_subentry_websearch_unsupported_reasoning_effort(
239289
hass: HomeAssistant, mock_config_entry, mock_init_component
240290
) -> None:

0 commit comments

Comments
 (0)