UNPKG

@genkit-ai/compat-oai

Version:

Genkit AI framework plugin for OpenAI APIs.

80 lines (75 loc) 3.29 kB
import { GenerateRequest, z, Genkit, ModelReference } from 'genkit'; import { ModelInfo, ModelAction } from 'genkit/model'; import OpenAI from 'openai'; import { ImageGenerateParams } from 'openai/resources/images.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 ImageRequestBuilder = (req: GenerateRequest, params: ImageGenerateParams) => void; declare const IMAGE_GENERATION_MODEL_INFO: ModelInfo; declare const ImageGenerationCommonConfigSchema: z.ZodObject<{ size: z.ZodOptional<z.ZodEnum<["1024x1024", "1792x1024", "1024x1792"]>>; style: z.ZodOptional<z.ZodEnum<["vivid", "natural"]>>; user: z.ZodOptional<z.ZodString>; n: z.ZodDefault<z.ZodNumber>; quality: z.ZodOptional<z.ZodEnum<["standard", "hd"]>>; response_format: z.ZodOptional<z.ZodDefault<z.ZodEnum<["b64_json", "url"]>>>; }, "strip", z.ZodTypeAny, { n: number; size?: "1024x1024" | "1792x1024" | "1024x1792" | undefined; style?: "vivid" | "natural" | undefined; user?: string | undefined; quality?: "standard" | "hd" | undefined; response_format?: "b64_json" | "url" | undefined; }, { size?: "1024x1024" | "1792x1024" | "1024x1792" | undefined; style?: "vivid" | "natural" | undefined; user?: string | undefined; n?: number | undefined; quality?: "standard" | "hd" | undefined; response_format?: "b64_json" | "url" | 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<CustomOptions extends z.ZodTypeAny = z.ZodTypeAny>(params: { ai: Genkit; name: string; client: OpenAI; modelRef?: ModelReference<CustomOptions>; requestBuilder?: ImageRequestBuilder; }): ModelAction<CustomOptions>; /** Image generation ModelRef helper, with reasonable defaults for * OpenAI-compatible providers */ declare function compatOaiImageModelRef<CustomOptions extends z.ZodTypeAny = z.ZodTypeAny>(params: { name: string; info?: ModelInfo; configSchema?: CustomOptions; config?: any; }): ModelReference<CustomOptions | z.AnyZodObject>; export { IMAGE_GENERATION_MODEL_INFO, ImageGenerationCommonConfigSchema, type ImageRequestBuilder, compatOaiImageModelRef, defineCompatOpenAIImageModel };