Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions packages/genkit-openai/src/genkit_openai/_models/_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,18 @@
from openai.types.audio import Transcription, Translation
from pydantic import Field

from genkit import FinishReason, GenkitError, Message, ModelResponse, Part, Role
from genkit import FinishReason, GenkitError, Message, ModelResponse, Part, Role, get_logger
from genkit.model import ModelContext, ModelInfo, ModelRequest, ModelStage, ModelSupports
from genkit.plugin_api import GenkitConfig

logger = get_logger(__name__)

_TRANSLATION_DEPRECATION_MESSAGE = (
"OpenAI's /v1/audio/translations endpoint used by whisper-1 translate=True is scheduled to shut down on "
'February 26, 2027. Realtime translation is the replacement, but it requires a Realtime session rather than '
'a file-upload request: https://developers.openai.com/api/docs/guides/realtime-translation'
)

_AUDIO_EXTRA_DESCRIPTION = (
'Audio API fields this class does not declare, in API wire names, sent as the request body. '
'Fields Genkit builds from the request are rejected here. Not checked; do not put API keys here.'
Expand Down Expand Up @@ -77,7 +85,12 @@ class OpenAISttConfig(GenkitConfig):
response_format: str | None = None
prompt: str | None = None
translate: bool | None = Field(
default=None, description='Translate the audio to English with the translations API. whisper-1 only.'
default=None,
deprecated=True,
description=(
'Deprecated: translates audio to English with the /v1/audio/translations endpoint, scheduled to shut '
'down on February 26, 2027. whisper-1 only.'
),
)
extra: dict[str, Any] | None = Field(default=None, description=_AUDIO_EXTRA_DESCRIPTION)

Expand Down Expand Up @@ -375,6 +388,8 @@ async def generate(self, request: ModelRequest, ctx: ModelContext) -> ModelRespo
f"model '{self._model_name}' cannot use translate=True."
),
)
if translate:
logger.warning(_TRANSLATION_DEPRECATION_MESSAGE)

try:
params = _to_stt_params(self._model_name, request)
Expand Down
16 changes: 14 additions & 2 deletions packages/genkit-openai/tests/audio_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
from __future__ import annotations

import base64
from unittest.mock import AsyncMock, MagicMock
from unittest.mock import AsyncMock, MagicMock, patch

import pytest
from genkit_openai._models._audio import (
SUPPORTED_STT_MODELS,
SUPPORTED_TTS_MODELS,
OpenAISttConfig,
OpenAISTTModel,
OpenAITtsConfig,
OpenAITTSModel,
Expand Down Expand Up @@ -364,7 +365,11 @@ async def test_generate_calls_translation_create_when_translate_is_enabled(self)
},
)

got = await model.generate(request, MagicMock())
with patch('genkit_openai._models._audio.logger.warning') as warning:
got = await model.generate(request, MagicMock())

warning.assert_called_once()
assert 'February 26, 2027' in warning.call_args.args[0]

mock_client.audio.translations.create.assert_called_once()
mock_client.audio.transcriptions.create.assert_not_called()
Expand All @@ -377,6 +382,13 @@ async def test_generate_calls_translation_create_when_translate_is_enabled(self)
assert part.text is not None
assert part.text == 'Translated text'

def test_translate_config_is_marked_deprecated(self) -> None:
"""Expose the endpoint retirement in the generated config schema."""
schema = OpenAISttConfig.model_json_schema()

assert schema['properties']['translate']['deprecated'] is True
assert 'February 26, 2027' in schema['properties']['translate']['description']

@pytest.mark.parametrize('model_name', ['gpt-4o-transcribe', 'gpt-4o-mini-transcribe'])
@pytest.mark.asyncio
async def test_generate_rejects_translation_for_non_whisper_models(self, model_name: str) -> None:
Expand Down