import { EmbedderReference, EmbedderAction, z, GenerateRequest, ModelReference, StreamingCallback, GenerateResponseChunkData, GenerateResponseData, ToolRequestPart, MessageData, Role, Part, ActionMetadata } from 'genkit'; import { ModelInfo, ModelAction, ToolDefinition } from 'genkit/model'; import OpenAI, { ClientOptions } from 'openai'; import { Response } from 'openai/core.mjs'; import { TranslationCreateParams, TranslationCreateResponse, SpeechCreateParams, TranscriptionCreateParams, Transcription } from 'openai/resources/audio/index.mjs'; import * as genkit_plugin from 'genkit/plugin'; import { ResolvableAction } from 'genkit/plugin'; import { ActionType } from 'genkit/registry'; import { ImageGenerateParams } from 'openai/resources/images.mjs'; import { ChatCompletionCreateParams, ChatCompletion, ChatCompletionChunk, ChatCompletionMessageToolCall, ChatCompletionMessageParam, ChatCompletionRole, ChatCompletionContentPart, ChatCompletionTool } from '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. */ /** * Method to define a new Genkit Embedder that is compatibale with the Open AI * Embeddings API. * * @param params An object containing parameters for defining the OpenAI embedder. * @param params.ai The Genkit AI instance. * @param params.name The name of the embedder. * @param params.client The OpenAI client instance. * @param params.embedderRef Optional reference to the embedder's configuration and * custom options. * @returns the created {@link EmbedderAction} */ declare function defineCompatOpenAIEmbedder(params: { name: string; client: OpenAI; pluginOptions?: PluginOptions; embedderRef?: EmbedderReference; }): EmbedderAction; /** * 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. */ type ImageRequestBuilder = (req: GenerateRequest, params: ImageGenerateParams) => void; declare const IMAGE_GENERATION_MODEL_INFO: ModelInfo; declare const ImageGenerationCommonConfigSchema: z.ZodObject<{ size: z.ZodOptional>; style: z.ZodOptional>; user: z.ZodOptional; n: z.ZodDefault; quality: z.ZodOptional>; response_format: z.ZodOptional>>; }, "strip", z.ZodTypeAny, { n: number; response_format?: "url" | "b64_json" | undefined; user?: string | undefined; size?: "1024x1024" | "1792x1024" | "1024x1792" | undefined; style?: "vivid" | "natural" | undefined; quality?: "standard" | "hd" | undefined; }, { response_format?: "url" | "b64_json" | undefined; user?: string | undefined; n?: number | undefined; size?: "1024x1024" | "1792x1024" | "1024x1792" | undefined; style?: "vivid" | "natural" | undefined; quality?: "standard" | "hd" | undefined; }>; /** * Method to define a new Genkit Model that is compatible with Open AI * Images API. * * These models are to be used to create images from a user prompt. * * @param params An object containing parameters for defining the OpenAI * image model. * @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 defineCompatOpenAIImageModel(params: { name: string; client: OpenAI; pluginOptions?: PluginOptions; modelRef?: ModelReference; requestBuilder?: ImageRequestBuilder; }): ModelAction; /** Image generation ModelRef helper, with reasonable defaults for * OpenAI-compatible providers */ declare function compatOaiImageModelRef(params: { name: string; info?: ModelInfo; configSchema?: CustomOptions; config?: any; namespace?: string; }): ModelReference; /** * 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 VisualDetailLevelSchema: z.ZodOptional>; type VisualDetailLevel = z.infer; type ModelRequestBuilder = (req: GenerateRequest, params: ChatCompletionCreateParams) => void; declare const ChatCompletionCommonConfigSchema: z.ZodObject<{ version: z.ZodOptional; maxOutputTokens: z.ZodOptional; topK: z.ZodOptional; topP: z.ZodOptional; stopSequences: z.ZodOptional>; apiKey: z.ZodOptional; } & { temperature: z.ZodOptional; frequencyPenalty: z.ZodOptional; logProbs: z.ZodOptional; presencePenalty: z.ZodOptional; topLogProbs: z.ZodOptional; }, "passthrough", z.ZodTypeAny, z.objectOutputType<{ version: z.ZodOptional; maxOutputTokens: z.ZodOptional; topK: z.ZodOptional; topP: z.ZodOptional; stopSequences: z.ZodOptional>; apiKey: z.ZodOptional; } & { temperature: z.ZodOptional; frequencyPenalty: z.ZodOptional; logProbs: z.ZodOptional; presencePenalty: z.ZodOptional; topLogProbs: z.ZodOptional; }, z.ZodTypeAny, "passthrough">, z.objectInputType<{ version: z.ZodOptional; maxOutputTokens: z.ZodOptional; topK: z.ZodOptional; topP: z.ZodOptional; stopSequences: z.ZodOptional>; apiKey: z.ZodOptional; } & { temperature: z.ZodOptional; frequencyPenalty: z.ZodOptional; logProbs: z.ZodOptional; presencePenalty: z.ZodOptional; topLogProbs: z.ZodOptional; }, z.ZodTypeAny, "passthrough">>; declare function toOpenAIRole(role: Role): ChatCompletionRole; /** * Converts a Genkit ToolDefinition to an OpenAI ChatCompletionTool object. * @param tool The Genkit ToolDefinition to convert. * @returns The converted OpenAI ChatCompletionTool object. */ declare function toOpenAITool(tool: ToolDefinition): ChatCompletionTool; /** * Converts a Genkit Part to the corresponding OpenAI ChatCompletionContentPart. * @param part The Genkit Part to convert. * @param visualDetailLevel The visual detail level to use for media parts. * @returns The corresponding OpenAI ChatCompletionContentPart. * @throws Error if the part contains unsupported fields for the current message role. */ declare function toOpenAITextAndMedia(part: Part, visualDetailLevel: VisualDetailLevel): ChatCompletionContentPart; /** * Converts a Genkit MessageData array to an OpenAI ChatCompletionMessageParam array. * @param messages The Genkit MessageData array to convert. * @param visualDetailLevel The visual detail level to use for media parts. * @returns The converted OpenAI ChatCompletionMessageParam array. */ declare function toOpenAIMessages(messages: MessageData[], visualDetailLevel?: VisualDetailLevel): ChatCompletionMessageParam[]; /** * Converts an OpenAI tool call to a Genkit ToolRequestPart. * @param toolCall The OpenAI tool call to convert. * @returns The converted Genkit ToolRequestPart. */ declare function fromOpenAIToolCall(toolCall: ChatCompletionMessageToolCall | ChatCompletionChunk.Choice.Delta.ToolCall, choice: ChatCompletion.Choice | ChatCompletionChunk.Choice): ToolRequestPart; /** * Converts an OpenAI message event to a Genkit GenerateResponseData object. * @param choice The OpenAI message event to convert. * @param jsonMode Whether the event is a JSON response. * @returns The converted Genkit GenerateResponseData object. */ declare function fromOpenAIChoice(choice: ChatCompletion.Choice, jsonMode?: boolean): GenerateResponseData; /** * Converts an OpenAI message stream event to a Genkit GenerateResponseData * object. * @param choice The OpenAI message stream event to convert. * @param jsonMode Whether the event is a JSON response. * @returns The converted Genkit GenerateResponseData object. */ declare function fromOpenAIChunkChoice(choice: ChatCompletionChunk.Choice, jsonMode?: boolean): GenerateResponseData; /** * Converts an OpenAI request to an OpenAI API request body. * @param modelName The name of the OpenAI model to use. * @param request The Genkit GenerateRequest to convert. * @returns The converted OpenAI API request body. * @throws An error if the specified model is not supported or if an unsupported output format is requested. */ declare function toOpenAIRequestBody(modelName: string, request: GenerateRequest, requestBuilder?: ModelRequestBuilder): OpenAI.Chat.Completions.ChatCompletionCreateParamsNonStreaming; /** * Creates the runner used by Genkit to interact with an OpenAI compatible * model. * @param name The name of the GPT model. * @param client The OpenAI client instance. * @returns The runner that Genkit will call when the model is invoked. */ declare function openAIModelRunner(name: string, defaultClient: OpenAI, requestBuilder?: ModelRequestBuilder, pluginOptions?: Omit): (request: GenerateRequest, options?: { streamingRequested?: boolean; sendChunk?: StreamingCallback; abortSignal?: AbortSignal; }) => Promise; /** * Method to define a new Genkit Model that is compatible with Open AI * Chat Completions API. * * These models are to be used to chat with a large language model. * * @param params An object containing parameters for defining the OpenAI * Chat model. * @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 defineCompatOpenAIModel(params: { name: string; client: OpenAI; modelRef?: ModelReference; requestBuilder?: ModelRequestBuilder; pluginOptions?: PluginOptions; }): ModelAction; /** ModelRef helper, with reasonable defaults for OpenAI-compatible providers */ declare function compatOaiModelRef(params: { name: string; info?: ModelInfo; configSchema?: CustomOptions; config?: any; namespace?: string; }): ModelReference; /** * 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. */ type TranslationRequestBuilder = (req: GenerateRequest, params: TranslationCreateParams) => void; declare const TRANSLATION_MODEL_INFO: ModelInfo; declare const TranslationConfigSchema: z.ZodObject; temperature: z.ZodOptional; maxOutputTokens: z.ZodOptional; topK: z.ZodOptional; topP: z.ZodOptional; stopSequences: z.ZodOptional>; apiKey: z.ZodOptional; }, "temperature"> & { response_format: z.ZodOptional>; }, "passthrough", z.ZodTypeAny, z.objectOutputType; temperature: z.ZodOptional; maxOutputTokens: z.ZodOptional; topK: z.ZodOptional; topP: z.ZodOptional; stopSequences: z.ZodOptional>; apiKey: z.ZodOptional; }, "temperature"> & { response_format: z.ZodOptional>; }, z.ZodTypeAny, "passthrough">, z.objectInputType; temperature: z.ZodOptional; maxOutputTokens: z.ZodOptional; topK: z.ZodOptional; topP: z.ZodOptional; stopSequences: z.ZodOptional>; apiKey: z.ZodOptional; }, "temperature"> & { response_format: z.ZodOptional>; }, z.ZodTypeAny, "passthrough">>; declare function toTranslationRequest(modelName: string, request: GenerateRequest, requestBuilder?: TranslationRequestBuilder): TranslationCreateParams; declare function translationToGenerateResponse(result: TranslationCreateResponse | string): GenerateResponseData; /** * Method to define a new Genkit Model that is compatible with Open AI * Translation API. * * These models are to be used to translate audio to text. * * @param params An object containing parameters for defining the OpenAI * translation model. * @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 defineCompatOpenAITranslationModel(params: { name: string; client: OpenAI; pluginOptions?: PluginOptions; modelRef?: ModelReference; requestBuilder?: TranslationRequestBuilder; }): ModelAction; /** Translation ModelRef helper, with reasonable defaults for * OpenAI-compatible providers */ declare function compatOaiTranslationModelRef(params: { name: string; info?: ModelInfo; configSchema?: CustomOptions; config?: any; namespace?: string; }): ModelReference; interface PluginOptions extends Partial> { apiKey?: ClientOptions['apiKey'] | false; name: string; initializer?: (client: OpenAI) => Promise; resolver?: (client: OpenAI, actionType: ActionType, actionName: string) => Promise | ResolvableAction | undefined; listActions?: (client: OpenAI) => Promise; } /** * This module provides the `openAICompatible` plugin factory for Genkit. It * enables interaction with OpenAI-compatible API endpoints, allowing users to * leverage various AI models by configuring API keys and other client options. * * The core export is `openAICompatible`, a function that accepts * `PluginOptions` and returns a Genkit plugin. * * Key `PluginOptions` include: * - `name`: A string to uniquely identify this plugin instance * (e.g., 'deepSeek', 'customOpenAI'). * - `apiKey`: The API key for the service. If not provided directly, the * plugin will attempt to use the `OPENAI_API_KEY` environment variable. * - `initializer`: An optional asynchronous function for custom setup after * the OpenAI client is initialized. It receives the Genkit instance and the * OpenAI client. * - Additional properties from OpenAI's `ClientOptions` (like `baseURL`, * `timeout`, etc.) can be passed to customize the OpenAI client. * * The returned plugin initializes an OpenAI client tailored to the provided * options, making configured models available for use within Genkit flows. * * @param {PluginOptions} options - Configuration options for the plugin. * @returns A Genkit plugin configured for an OpenAI-compatible service. * * Usage: Import `openAICompatible` (or your chosen import name for the default * export) from this package (e.g., `genkitx-openai`). Then, invoke it within * the `plugins` array of `configureGenkit`, providing the necessary * `PluginOptions`. * * Example: * ```typescript * import myOpenAICompatiblePlugin from 'genkitx-openai'; // Default import * * export default configureGenkit({ * plugins: [ * myOpenAICompatiblePlugin({ * name: 'gpt4o', // Name for this specific plugin configuration * apiKey: process.env.OPENAI_API_KEY, * // For a non-OpenAI compatible endpoint: * // baseURL: 'https://api.custom-llm-provider.com/v1', * }), * myOpenAICompatiblePlugin({ * name: 'localLlama', * apiKey: 'ollama', // Or specific key if required by local server * baseURL: 'http://localhost:11434/v1', // Example for Ollama * }), * // ... other plugins * ], * }); * ``` */ declare const openAICompatible: (options: PluginOptions) => genkit_plugin.GenkitPluginV2Instance; /** * 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. */ type SpeechRequestBuilder = (req: GenerateRequest, params: SpeechCreateParams) => void; type TranscriptionRequestBuilder = (req: GenerateRequest, params: TranscriptionCreateParams) => void; declare const TRANSCRIPTION_MODEL_INFO: ModelInfo; declare const SPEECH_MODEL_INFO: ModelInfo; declare const TranscriptionConfigSchema: z.ZodObject; temperature: z.ZodOptional; maxOutputTokens: z.ZodOptional; topK: z.ZodOptional; topP: z.ZodOptional; stopSequences: z.ZodOptional>; apiKey: z.ZodOptional; }, "temperature"> & { chunking_strategy: z.ZodOptional, z.ZodObject<{ type: z.ZodString; prefix_padding_ms: z.ZodOptional; silence_duration_ms: z.ZodOptional; threshold: z.ZodOptional; }, "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>; language: z.ZodOptional; timestamp_granularities: z.ZodOptional, "many">>; response_format: z.ZodOptional>; }, "passthrough", z.ZodTypeAny, z.objectOutputType; temperature: z.ZodOptional; maxOutputTokens: z.ZodOptional; topK: z.ZodOptional; topP: z.ZodOptional; stopSequences: z.ZodOptional>; apiKey: z.ZodOptional; }, "temperature"> & { chunking_strategy: z.ZodOptional, z.ZodObject<{ type: z.ZodString; prefix_padding_ms: z.ZodOptional; silence_duration_ms: z.ZodOptional; threshold: z.ZodOptional; }, "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>; language: z.ZodOptional; timestamp_granularities: z.ZodOptional, "many">>; response_format: z.ZodOptional>; }, z.ZodTypeAny, "passthrough">, z.objectInputType; temperature: z.ZodOptional; maxOutputTokens: z.ZodOptional; topK: z.ZodOptional; topP: z.ZodOptional; stopSequences: z.ZodOptional>; apiKey: z.ZodOptional; }, "temperature"> & { chunking_strategy: z.ZodOptional, z.ZodObject<{ type: z.ZodString; prefix_padding_ms: z.ZodOptional; silence_duration_ms: z.ZodOptional; threshold: z.ZodOptional; }, "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>; language: z.ZodOptional; timestamp_granularities: z.ZodOptional, "many">>; response_format: z.ZodOptional>; }, z.ZodTypeAny, "passthrough">>; declare const SpeechConfigSchema: z.ZodObject<{ voice: z.ZodDefault>; speed: z.ZodOptional; response_format: z.ZodOptional>; }, "strip", z.ZodTypeAny, { voice: "alloy" | "echo" | "fable" | "onyx" | "nova" | "shimmer"; response_format?: "mp3" | "opus" | "aac" | "flac" | "wav" | "pcm" | undefined; speed?: number | undefined; }, { response_format?: "mp3" | "opus" | "aac" | "flac" | "wav" | "pcm" | undefined; voice?: "alloy" | "echo" | "fable" | "onyx" | "nova" | "shimmer" | undefined; speed?: number | undefined; }>; /** * Supported media formats for Audio generation */ declare const RESPONSE_FORMAT_MEDIA_TYPES: { mp3: string; opus: string; aac: string; flac: string; wav: string; pcm: string; }; declare function toTTSRequest(modelName: string, request: GenerateRequest, requestBuilder?: SpeechRequestBuilder): SpeechCreateParams; declare function speechToGenerateResponse(response: Response, responseFormat?: 'mp3' | 'opus' | 'aac' | 'flac' | 'wav' | 'pcm'): Promise; /** * Method to define a new Genkit Model that is compatible with the Open AI Audio * API. * * These models are to be used to create audio speech from a given request. * @param params An object containing parameters for defining the OpenAI speech * model. * @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 defineCompatOpenAISpeechModel(params: { name: string; client: OpenAI; modelRef?: ModelReference; requestBuilder?: SpeechRequestBuilder; pluginOptions: PluginOptions; }): ModelAction; /** Speech generation ModelRef helper, with reasonable defaults for * OpenAI-compatible providers */ declare function compatOaiSpeechModelRef(params: { name: string; info?: ModelInfo; configSchema?: CustomOptions; config?: any; namespace?: string; }): ModelReference; declare function toSttRequest(modelName: string, request: GenerateRequest, requestBuilder?: TranscriptionRequestBuilder): TranscriptionCreateParams; declare function transcriptionToGenerateResponse(result: Transcription | string): GenerateResponseData; /** * Method to define a new Genkit Model that is compatible with Open AI * Transcriptions API. * * These models are to be used to transcribe audio to text. * * @param params An object containing parameters for defining the OpenAI * transcription model. * @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 defineCompatOpenAITranscriptionModel(params: { name: string; client: OpenAI; pluginOptions?: PluginOptions; modelRef?: ModelReference; requestBuilder?: TranscriptionRequestBuilder; }): ModelAction; /** Transcription ModelRef helper, with reasonable defaults for * OpenAI-compatible providers */ declare function compatOaiTranscriptionModelRef(params: { name: string; info?: ModelInfo; configSchema?: CustomOptions; config?: any; namespace?: string; }): ModelReference; export { compatOaiTranscriptionModelRef as A, openAICompatible as B, ChatCompletionCommonConfigSchema as C, defineCompatOpenAISpeechModel as D, defineCompatOpenAITranscriptionModel as E, SPEECH_MODEL_INFO as F, TRANSCRIPTION_MODEL_INFO as G, speechToGenerateResponse as H, ImageGenerationCommonConfigSchema as I, toSttRequest as J, toTTSRequest as K, transcriptionToGenerateResponse as L, type ModelRequestBuilder as M, type PluginOptions as P, RESPONSE_FORMAT_MEDIA_TYPES as R, SpeechConfigSchema as S, TranscriptionConfigSchema as T, type ImageRequestBuilder as a, IMAGE_GENERATION_MODEL_INFO as b, compatOaiImageModelRef as c, defineCompatOpenAIEmbedder as d, defineCompatOpenAIImageModel as e, compatOaiModelRef as f, defineCompatOpenAIModel as g, fromOpenAIChoice as h, fromOpenAIChunkChoice as i, fromOpenAIToolCall as j, toOpenAIRequestBody as k, toOpenAIRole as l, toOpenAITextAndMedia as m, toOpenAITool as n, openAIModelRunner as o, TRANSLATION_MODEL_INFO as p, TranslationConfigSchema as q, type TranslationRequestBuilder as r, compatOaiTranslationModelRef as s, toOpenAIMessages as t, defineCompatOpenAITranslationModel as u, toTranslationRequest as v, translationToGenerateResponse as w, type SpeechRequestBuilder as x, type TranscriptionRequestBuilder as y, compatOaiSpeechModelRef as z };