diff --git a/js/plugins/compat-oai/src/audio.ts b/js/plugins/compat-oai/src/audio.ts index 37c422eefd..1e27f5327e 100644 --- a/js/plugins/compat-oai/src/audio.ts +++ b/js/plugins/compat-oai/src/audio.ts @@ -358,15 +358,16 @@ export function defineCompatOpenAITranscriptionModel< requestBuilder?: TranscriptionRequestBuilder; }): ModelAction { const { - name: modelName, + name, pluginOptions, client: defaultClient, modelRef, requestBuilder, } = params; - + const modelName = toModelName(name, pluginOptions?.name); const actionName = modelRef?.name ?? `${pluginOptions?.name ?? 'compat-oai'}/${modelName}`; + return model( { name: actionName, diff --git a/js/testapps/compat-oai/audio.mp3 b/js/testapps/compat-oai/audio.mp3 new file mode 100644 index 0000000000..8aa31b4de3 Binary files /dev/null and b/js/testapps/compat-oai/audio.mp3 differ diff --git a/js/testapps/compat-oai/src/index.ts b/js/testapps/compat-oai/src/index.ts index 187c1c9e19..d5ce6ca8da 100644 --- a/js/testapps/compat-oai/src/index.ts +++ b/js/testapps/compat-oai/src/index.ts @@ -358,6 +358,25 @@ async function toWav( }); } +// STT sample +ai.defineFlow('transcribe', async () => { + const audioFile = fs.readFileSync('audio.mp3'); + + const { text } = await ai.generate({ + model: openAI.model('whisper-1'), + prompt: [ + { + media: { + contentType: 'audio/mp3', + url: `data:audio/mp3;base64,${audioFile.toString('base64')}`, + }, + }, + ], + }); + + return text; +}); + // PDF file input example ai.defineFlow( {