Skip to content
Open
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
18 changes: 16 additions & 2 deletions js/plugins/compat-oai/src/openai/whisper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.'
),
});

/**
Expand Down Expand Up @@ -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,
Expand Down
17 changes: 16 additions & 1 deletion js/plugins/compat-oai/tests/openai_whisper_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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();
});
});
Loading