diff --git a/js/plugins/compat-oai/src/openai/whisper.ts b/js/plugins/compat-oai/src/openai/whisper.ts index 91d2ba67a6..e20c0d1628 100644 --- a/js/plugins/compat-oai/src/openai/whisper.ts +++ b/js/plugins/compat-oai/src/openai/whisper.ts @@ -18,6 +18,7 @@ import type { ModelReference } from 'genkit'; import { modelRef, z } from 'genkit'; import type { ModelAction, ModelInfo } from 'genkit/model'; +import { logger } from 'genkit/logging'; import { model } from 'genkit/plugin'; import OpenAI from 'openai'; import { @@ -47,8 +48,18 @@ export const WHISPER_MODEL_INFO: ModelInfo = { * a `translate` flag that switches between transcription and translation APIs. */ export const WhisperConfigSchema = TranscriptionConfigSchema.extend({ - /** When true, uses Translation API instead of Transcription. Default: false */ - translate: z.boolean().optional().default(false), + /** + * Deprecated. When true, uses the /v1/audio/translations endpoint, 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. + */ + translate: z + .boolean() + .optional() + .default(false) + .describe( + 'Deprecated: uses /v1/audio/translations, scheduled to shut down on February 26, 2027. Realtime translation requires a Realtime session.' + ), }); /** @@ -95,6 +106,9 @@ export function defineOpenAIWhisperModel< ); if (translate === true) { + logger.warn( + "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" + ); const params = toTranslationRequest(modelName, cleanRequest); const result = await client.audio.translations.create(params, { signal: abortSignal, diff --git a/js/plugins/compat-oai/tests/openai_whisper_test.ts b/js/plugins/compat-oai/tests/openai_whisper_test.ts index bee08ada08..0152ee742d 100644 --- a/js/plugins/compat-oai/tests/openai_whisper_test.ts +++ b/js/plugins/compat-oai/tests/openai_whisper_test.ts @@ -16,12 +16,16 @@ */ import { describe, expect, it, jest } from '@jest/globals'; +import { logger } from 'genkit/logging'; import OpenAI from 'openai'; import type { Transcription, Translation, } from 'openai/resources/audio/index.mjs'; -import { defineOpenAIWhisperModel } from '../src/openai/whisper'; +import { + defineOpenAIWhisperModel, + WhisperConfigSchema, +} from '../src/openai/whisper'; jest.mock('genkit/model', () => { const originalModule = @@ -149,6 +153,12 @@ describe('defineOpenAIWhisperModel runner — transcription (default)', () => { }); describe('defineOpenAIWhisperModel runner — translation (translate: true)', () => { + it('marks translate as deprecated in the model config schema', () => { + expect(WhisperConfigSchema.shape.translate.description).toContain( + 'February 26, 2027' + ); + }); + it('should call translations.create when translate is true', async () => { const result: Translation = { text: 'Hello in English', @@ -165,6 +175,7 @@ describe('defineOpenAIWhisperModel runner — translation (translate: true)', () }, }; const abortSignal = jest.fn(); + const warning = jest.spyOn(logger, 'warn').mockImplementation(() => {}); const runner = defineOpenAIWhisperModel({ name: 'whisper-1', @@ -203,5 +214,9 @@ describe('defineOpenAIWhisperModel runner — translation (translate: true)', () { signal: abortSignal } ); expect(openaiClient.audio.transcriptions.create).not.toHaveBeenCalled(); + expect(warning).toHaveBeenCalledWith( + expect.stringContaining('February 26, 2027') + ); + warning.mockRestore(); }); });