@genkit-ai/compat-oai
Version:
Genkit AI framework plugin for OpenAI APIs.
81 lines (77 loc) • 3.97 kB
text/typescript
import { z, ModelReference, EmbedderReference } from 'genkit';
import { GenkitPlugin } from 'genkit/plugin';
import { SpeechConfigSchema, TranscriptionConfigSchema } from '../audio.mjs';
import { ImageGenerationCommonConfigSchema } from '../image.mjs';
import { PluginOptions } from '../index.mjs';
import { SUPPORTED_IMAGE_MODELS } from './dalle.mjs';
import { SUPPORTED_EMBEDDING_MODELS, TextEmbeddingConfigSchema } from './embedder.mjs';
import { SUPPORTED_GPT_MODELS, OpenAIChatCompletionConfigSchema } from './gpt.mjs';
import { SUPPORTED_TTS_MODELS } from './tts.mjs';
import { SUPPORTED_STT_MODELS } from './whisper.mjs';
import 'genkit/model';
import 'openai';
import 'openai/resources/audio/index.mjs';
import 'openai/resources/images.mjs';
import 'genkit/registry';
import '../embedder.mjs';
import '../model.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.
*/
type OpenAIPluginOptions = Omit<PluginOptions, 'name' | 'baseURL'>;
declare function openAIPlugin(options?: OpenAIPluginOptions): GenkitPlugin;
type OpenAIPlugin = {
(params?: OpenAIPluginOptions): GenkitPlugin;
model(name: keyof typeof SUPPORTED_GPT_MODELS | (`gpt-${string}` & {}) | (`o${number}` & {}), config?: z.infer<typeof OpenAIChatCompletionConfigSchema>): ModelReference<typeof OpenAIChatCompletionConfigSchema>;
model(name: keyof typeof SUPPORTED_IMAGE_MODELS | (`dall-e${string}` & {}) | (`gpt-image-${string}` & {}), config?: z.infer<typeof ImageGenerationCommonConfigSchema>): ModelReference<typeof ImageGenerationCommonConfigSchema>;
model(name: keyof typeof SUPPORTED_TTS_MODELS | (`tts-${string}` & {}) | (`${string}-tts` & {}), config?: z.infer<typeof SpeechConfigSchema>): ModelReference<typeof SpeechConfigSchema>;
model(name: keyof typeof SUPPORTED_STT_MODELS | (`whisper-${string}` & {}) | (`${string}-transcribe` & {}), config?: z.infer<typeof TranscriptionConfigSchema>): ModelReference<typeof TranscriptionConfigSchema>;
model(name: string, config?: any): ModelReference<z.ZodTypeAny>;
embedder(name: keyof typeof SUPPORTED_EMBEDDING_MODELS | (`${string}-embedding-${string}` & {}), config?: z.infer<typeof TextEmbeddingConfigSchema>): EmbedderReference<typeof TextEmbeddingConfigSchema>;
embedder(name: string, config?: any): EmbedderReference<z.ZodTypeAny>;
};
/**
* This module provides an interface to the OpenAI models through the Genkit
* plugin system. It allows users to interact with various models by providing
* an API key and optional configuration.
*
* The main export is the `openai` plugin, which can be configured with an API
* key either directly or through environment variables. It initializes the
* OpenAI client and makes available the models for use.
*
* Exports:
* - openai: The main plugin function to interact with OpenAI.
*
* Usage:
* To use the models, initialize the openai plugin inside `configureGenkit` and
* pass the configuration options. If no API key is provided in the options, the
* environment variable `OPENAI_API_KEY` must be set.
*
* Example:
* ```
* import { openAI } from '@genkit-ai/compat-oai/openai';
*
* export default configureGenkit({
* plugins: [
* openai()
* ... // other plugins
* ]
* });
* ```
*/
declare const openAI: OpenAIPlugin;
export { type OpenAIPlugin, type OpenAIPluginOptions, openAI as default, openAI, openAIPlugin };