mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Update retiring OpenAI conversation and transcription models (#189608)
This commit is contained in:
@@ -583,7 +583,6 @@ class OpenAISubentryFlowHandler(ConfigSubentryFlow):
|
||||
"gpt-image-2.5-flare",
|
||||
"gpt-image-2",
|
||||
"gpt-image-1.5",
|
||||
"gpt-image-1",
|
||||
"gpt-image-1-mini",
|
||||
],
|
||||
mode=SelectSelectorMode.DROPDOWN,
|
||||
@@ -793,6 +792,7 @@ class OpenAISubentrySTTFlowHandler(ConfigSubentryFlow):
|
||||
): SelectSelector(
|
||||
SelectSelectorConfig(
|
||||
options=[
|
||||
"gpt-transcribe",
|
||||
"gpt-4o-transcribe",
|
||||
"gpt-4o-mini-transcribe",
|
||||
"whisper-1",
|
||||
|
||||
@@ -40,7 +40,7 @@ CONF_WEB_SEARCH_TIMEZONE = "timezone"
|
||||
CONF_WEB_SEARCH_INLINE_CITATIONS = "inline_citations"
|
||||
RECOMMENDED_CODE_INTERPRETER = False
|
||||
RECOMMENDED_DECISION_MODEL = "gpt-6-luna"
|
||||
RECOMMENDED_CHAT_MODEL = "gpt-4o-mini"
|
||||
RECOMMENDED_CHAT_MODEL = "gpt-6-luna"
|
||||
RECOMMENDED_IMAGE_MODEL = "gpt-image-2.5-flare"
|
||||
RECOMMENDED_MAX_TOKENS = 3000
|
||||
RECOMMENDED_PRO_MODE = False
|
||||
@@ -48,7 +48,7 @@ RECOMMENDED_REASONING_EFFORT = "low"
|
||||
RECOMMENDED_STORE_RESPONSES = False
|
||||
RECOMMENDED_REASONING_SUMMARY = "auto"
|
||||
RECOMMENDED_SERVICE_TIER = "auto"
|
||||
RECOMMENDED_STT_MODEL = "gpt-4o-mini-transcribe"
|
||||
RECOMMENDED_STT_MODEL = "gpt-transcribe"
|
||||
RECOMMENDED_TEMPERATURE = 1.0
|
||||
RECOMMENDED_TOP_P = 1.0
|
||||
RECOMMENDED_TTS_SPEED = 1.0
|
||||
|
||||
@@ -6,7 +6,7 @@ import logging
|
||||
from typing import TYPE_CHECKING, override
|
||||
import wave
|
||||
|
||||
from openai import OpenAIError
|
||||
from openai import OpenAIError, omit
|
||||
|
||||
from homeassistant.components import stt
|
||||
from homeassistant.const import CONF_PROMPT
|
||||
@@ -179,13 +179,17 @@ class OpenAISTTEntity(stt.SpeechToTextEntity, OpenAIBaseLLMEntity):
|
||||
|
||||
options = self.subentry.data
|
||||
client = self.entry.runtime_data
|
||||
model = options.get(CONF_CHAT_MODEL, RECOMMENDED_STT_MODEL)
|
||||
language = metadata.language.split("-")[0]
|
||||
is_gpt_transcribe = model.startswith("gpt-transcribe")
|
||||
|
||||
try:
|
||||
response = await client.audio.transcriptions.create(
|
||||
model=options.get(CONF_CHAT_MODEL, RECOMMENDED_STT_MODEL),
|
||||
model=model,
|
||||
file=(f"a.{metadata.format.value}", audio_data),
|
||||
response_format="json",
|
||||
language=metadata.language.split("-")[0],
|
||||
language=omit if is_gpt_transcribe else language,
|
||||
languages=[language] if is_gpt_transcribe else omit,
|
||||
prompt=options.get(CONF_PROMPT, DEFAULT_STT_PROMPT),
|
||||
)
|
||||
except OpenAIError:
|
||||
|
||||
@@ -48,9 +48,17 @@ def mock_conversation_subentry_data() -> dict[str, Any]:
|
||||
return {}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_stt_subentry_data(request: pytest.FixtureRequest) -> dict[str, Any]:
|
||||
"""Mock speech-to-text subentry data."""
|
||||
return getattr(request, "param", RECOMMENDED_STT_OPTIONS)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_config_entry(
|
||||
hass: HomeAssistant, mock_conversation_subentry_data: dict[str, Any]
|
||||
hass: HomeAssistant,
|
||||
mock_conversation_subentry_data: dict[str, Any],
|
||||
mock_stt_subentry_data: dict[str, Any],
|
||||
) -> MockConfigEntry:
|
||||
"""Mock a config entry."""
|
||||
entry = MockConfigEntry(
|
||||
@@ -81,7 +89,7 @@ def mock_config_entry(
|
||||
unique_id=None,
|
||||
),
|
||||
ConfigSubentryData(
|
||||
data=RECOMMENDED_STT_OPTIONS,
|
||||
data=mock_stt_subentry_data,
|
||||
subentry_type="stt",
|
||||
title=DEFAULT_STT_NAME,
|
||||
unique_id=None,
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
'labels': set({
|
||||
}),
|
||||
'manufacturer': 'OpenAI',
|
||||
'model': 'gpt-4o-mini',
|
||||
'model': 'gpt-6-luna',
|
||||
'model_id': None,
|
||||
'name': 'OpenAI Conversation',
|
||||
'name_by_user': None,
|
||||
|
||||
@@ -793,6 +793,10 @@ async def test_form_invalid_auth(
|
||||
CONF_TOP_P: RECOMMENDED_TOP_P,
|
||||
CONF_MAX_TOKENS: RECOMMENDED_MAX_TOKENS,
|
||||
CONF_STORE_RESPONSES: False,
|
||||
CONF_REASONING_EFFORT: "low",
|
||||
CONF_REASONING_SUMMARY: RECOMMENDED_REASONING_SUMMARY,
|
||||
CONF_PRO_MODE: False,
|
||||
CONF_VERBOSITY: "medium",
|
||||
CONF_SERVICE_TIER: "auto",
|
||||
CONF_WEB_SEARCH: True,
|
||||
CONF_WEB_SEARCH_CONTEXT_SIZE: "low",
|
||||
@@ -1311,6 +1315,10 @@ async def test_subentry_web_search_user_location(
|
||||
CONF_WEB_SEARCH_TIMEZONE: "America/Los_Angeles",
|
||||
CONF_WEB_SEARCH_INLINE_CITATIONS: False,
|
||||
CONF_CODE_INTERPRETER: False,
|
||||
CONF_REASONING_EFFORT: "low",
|
||||
CONF_REASONING_SUMMARY: RECOMMENDED_REASONING_SUMMARY,
|
||||
CONF_PRO_MODE: False,
|
||||
CONF_VERBOSITY: "medium",
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,11 +4,12 @@ from collections.abc import AsyncIterable
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import httpx2
|
||||
from openai import RateLimitError
|
||||
from openai import Omit, RateLimitError, omit
|
||||
import pytest
|
||||
from pytest_homeassistant.common import MockConfigEntry
|
||||
|
||||
from homeassistant.components import stt
|
||||
from homeassistant.components.openai_conversation.const import CONF_CHAT_MODEL
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
|
||||
@@ -96,7 +97,7 @@ async def test_stt_process_audio_stream_success_wav(
|
||||
|
||||
mock_create_transcription.assert_called_once()
|
||||
call_args = mock_create_transcription.call_args
|
||||
assert call_args.kwargs["model"] == "gpt-4o-mini-transcribe"
|
||||
assert call_args.kwargs["model"] == "gpt-transcribe"
|
||||
|
||||
contents = call_args.kwargs["file"]
|
||||
assert contents[0].endswith(".wav")
|
||||
@@ -104,10 +105,33 @@ async def test_stt_process_audio_stream_success_wav(
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_init_component")
|
||||
@pytest.mark.parametrize(
|
||||
("mock_stt_subentry_data", "model", "language", "languages"),
|
||||
[
|
||||
pytest.param(
|
||||
{},
|
||||
"gpt-transcribe",
|
||||
omit,
|
||||
["en"],
|
||||
id="recommended",
|
||||
),
|
||||
pytest.param(
|
||||
{CONF_CHAT_MODEL: "gpt-4o-mini-transcribe"},
|
||||
"gpt-4o-mini-transcribe",
|
||||
"en",
|
||||
omit,
|
||||
id="legacy",
|
||||
),
|
||||
],
|
||||
indirect=["mock_stt_subentry_data"],
|
||||
)
|
||||
async def test_stt_process_audio_stream_success_ogg(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_create_transcription: AsyncMock,
|
||||
model: str,
|
||||
language: str | Omit,
|
||||
languages: list[str] | Omit,
|
||||
) -> None:
|
||||
"""Test STT processing audio stream successfully."""
|
||||
entity = hass.data[stt.DOMAIN].get_entity("stt.openai_stt")
|
||||
@@ -149,7 +173,9 @@ async def test_stt_process_audio_stream_success_ogg(
|
||||
|
||||
mock_create_transcription.assert_called_once()
|
||||
call_args = mock_create_transcription.call_args
|
||||
assert call_args.kwargs["model"] == "gpt-4o-mini-transcribe"
|
||||
assert call_args.kwargs["model"] == model
|
||||
assert call_args.kwargs["language"] == language
|
||||
assert call_args.kwargs["languages"] == languages
|
||||
|
||||
contents = call_args.kwargs["file"]
|
||||
assert contents[0].endswith(".ogg")
|
||||
|
||||
Reference in New Issue
Block a user