UNPKG

@genkit-ai/compat-oai

Version:

Genkit AI framework plugin for OpenAI APIs.

161 lines (157 loc) 6.83 kB
import { ModelReference, z } from 'genkit'; import { ModelInfo, ModelAction } from 'genkit/model'; import OpenAI from 'openai'; import { P as PluginOptions } from '../audio-CW-qdV9D.js'; import 'openai/core.mjs'; import 'openai/resources/audio/index.mjs'; import 'genkit/plugin'; import 'genkit/registry'; import 'openai/resources/images.mjs'; import 'openai/resources/index.mjs'; /** * Copyright 2024 The Fire Company * Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ declare const WHISPER_MODEL_INFO: ModelInfo; /** * Config schema for Whisper models. Extends the transcription config with * a `translate` flag that switches between transcription and translation APIs. */ declare const WhisperConfigSchema: z.ZodObject<Pick<{ version: z.ZodOptional<z.ZodString>; temperature: z.ZodOptional<z.ZodNumber>; maxOutputTokens: z.ZodOptional<z.ZodNumber>; topK: z.ZodOptional<z.ZodNumber>; topP: z.ZodOptional<z.ZodNumber>; stopSequences: z.ZodOptional<z.ZodArray<z.ZodString, "many">>; apiKey: z.ZodOptional<z.ZodString>; }, "temperature"> & { chunking_strategy: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"auto">, z.ZodObject<{ type: z.ZodString; prefix_padding_ms: z.ZodOptional<z.ZodNumber>; silence_duration_ms: z.ZodOptional<z.ZodNumber>; threshold: z.ZodOptional<z.ZodNumber>; }, "strip", z.ZodTypeAny, { type: string; prefix_padding_ms?: number | undefined; silence_duration_ms?: number | undefined; threshold?: number | undefined; }, { type: string; prefix_padding_ms?: number | undefined; silence_duration_ms?: number | undefined; threshold?: number | undefined; }>]>>; include: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>; language: z.ZodOptional<z.ZodString>; timestamp_granularities: z.ZodOptional<z.ZodArray<z.ZodEnum<["word", "segment"]>, "many">>; response_format: z.ZodOptional<z.ZodEnum<["json", "text", "srt", "verbose_json", "vtt"]>>; } & { /** When true, uses Translation API instead of Transcription. Default: false */ translate: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>; }, "passthrough", z.ZodTypeAny, z.objectOutputType<Pick<{ version: z.ZodOptional<z.ZodString>; temperature: z.ZodOptional<z.ZodNumber>; maxOutputTokens: z.ZodOptional<z.ZodNumber>; topK: z.ZodOptional<z.ZodNumber>; topP: z.ZodOptional<z.ZodNumber>; stopSequences: z.ZodOptional<z.ZodArray<z.ZodString, "many">>; apiKey: z.ZodOptional<z.ZodString>; }, "temperature"> & { chunking_strategy: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"auto">, z.ZodObject<{ type: z.ZodString; prefix_padding_ms: z.ZodOptional<z.ZodNumber>; silence_duration_ms: z.ZodOptional<z.ZodNumber>; threshold: z.ZodOptional<z.ZodNumber>; }, "strip", z.ZodTypeAny, { type: string; prefix_padding_ms?: number | undefined; silence_duration_ms?: number | undefined; threshold?: number | undefined; }, { type: string; prefix_padding_ms?: number | undefined; silence_duration_ms?: number | undefined; threshold?: number | undefined; }>]>>; include: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>; language: z.ZodOptional<z.ZodString>; timestamp_granularities: z.ZodOptional<z.ZodArray<z.ZodEnum<["word", "segment"]>, "many">>; response_format: z.ZodOptional<z.ZodEnum<["json", "text", "srt", "verbose_json", "vtt"]>>; } & { /** When true, uses Translation API instead of Transcription. Default: false */ translate: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>; }, z.ZodTypeAny, "passthrough">, z.objectInputType<Pick<{ version: z.ZodOptional<z.ZodString>; temperature: z.ZodOptional<z.ZodNumber>; maxOutputTokens: z.ZodOptional<z.ZodNumber>; topK: z.ZodOptional<z.ZodNumber>; topP: z.ZodOptional<z.ZodNumber>; stopSequences: z.ZodOptional<z.ZodArray<z.ZodString, "many">>; apiKey: z.ZodOptional<z.ZodString>; }, "temperature"> & { chunking_strategy: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"auto">, z.ZodObject<{ type: z.ZodString; prefix_padding_ms: z.ZodOptional<z.ZodNumber>; silence_duration_ms: z.ZodOptional<z.ZodNumber>; threshold: z.ZodOptional<z.ZodNumber>; }, "strip", z.ZodTypeAny, { type: string; prefix_padding_ms?: number | undefined; silence_duration_ms?: number | undefined; threshold?: number | undefined; }, { type: string; prefix_padding_ms?: number | undefined; silence_duration_ms?: number | undefined; threshold?: number | undefined; }>]>>; include: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>; language: z.ZodOptional<z.ZodString>; timestamp_granularities: z.ZodOptional<z.ZodArray<z.ZodEnum<["word", "segment"]>, "many">>; response_format: z.ZodOptional<z.ZodEnum<["json", "text", "srt", "verbose_json", "vtt"]>>; } & { /** When true, uses Translation API instead of Transcription. Default: false */ translate: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>; }, z.ZodTypeAny, "passthrough">>; /** * Method to define an OpenAI Whisper model that can perform both transcription and * translation based on the `translate` config flag. * * @param params.ai The Genkit AI instance. * @param params.name The name of the model. * @param params.client The OpenAI client instance. * @param params.modelRef Optional reference to the model's configuration and * custom options. * * @returns the created {@link ModelAction} */ declare function defineOpenAIWhisperModel<CustomOptions extends z.ZodTypeAny = z.ZodTypeAny>(params: { name: string; client: OpenAI; modelRef?: ModelReference<CustomOptions>; pluginOptions?: PluginOptions; }): ModelAction; /** OpenAI whisper ModelRef helper. */ declare function openAIWhisperModelRef<CustomOptions extends z.ZodTypeAny = z.ZodTypeAny>(params: { name: string; info?: ModelInfo; configSchema?: CustomOptions; config?: any; }): ModelReference<any>; declare const SUPPORTED_WHISPER_MODELS: { 'whisper-1': ModelReference<any>; }; export { SUPPORTED_WHISPER_MODELS, WHISPER_MODEL_INFO, WhisperConfigSchema, defineOpenAIWhisperModel, openAIWhisperModelRef };