UNPKG

@genkit-ai/compat-oai

Version:

Genkit AI framework plugin for OpenAI APIs.

131 lines 5.5 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var index_exports = {}; __export(index_exports, { ChatCompletionCommonConfigSchema: () => import_model2.ChatCompletionCommonConfigSchema, ImageGenerationCommonConfigSchema: () => import_image.ImageGenerationCommonConfigSchema, SpeechConfigSchema: () => import_audio.SpeechConfigSchema, TranscriptionConfigSchema: () => import_audio.TranscriptionConfigSchema, TranslationConfigSchema: () => import_translate.TranslationConfigSchema, compatOaiImageModelRef: () => import_image.compatOaiImageModelRef, compatOaiModelRef: () => import_model2.compatOaiModelRef, compatOaiSpeechModelRef: () => import_audio.compatOaiSpeechModelRef, compatOaiTranscriptionModelRef: () => import_audio.compatOaiTranscriptionModelRef, compatOaiTranslationModelRef: () => import_translate.compatOaiTranslationModelRef, default: () => index_default, defineCompatOpenAIEmbedder: () => import_embedder.defineCompatOpenAIEmbedder, defineCompatOpenAIImageModel: () => import_image.defineCompatOpenAIImageModel, defineCompatOpenAIModel: () => import_model2.defineCompatOpenAIModel, defineCompatOpenAISpeechModel: () => import_audio.defineCompatOpenAISpeechModel, defineCompatOpenAITranscriptionModel: () => import_audio.defineCompatOpenAITranscriptionModel, defineCompatOpenAITranslationModel: () => import_translate.defineCompatOpenAITranslationModel, openAICompatible: () => openAICompatible, openAIModelRunner: () => import_model2.openAIModelRunner }); module.exports = __toCommonJS(index_exports); var import_plugin = require("genkit/plugin"); var import_openai = __toESM(require("openai")); var import_model = require("./model.js"); var import_utils = require("./utils.js"); var import_audio = require("./audio.js"); var import_embedder = require("./embedder.js"); var import_image = require("./image.js"); var import_model2 = require("./model.js"); var import_translate = require("./translate.js"); const openAICompatible = (options) => { let listActionsCache; var client; function createClient() { if (client) return client; const { apiKey, ...restofOptions } = options; client = new import_openai.default({ ...restofOptions, apiKey: apiKey === false ? "placeholder" : apiKey }); return client; } return (0, import_plugin.genkitPluginV2)({ name: options.name, async init() { if (!options.initializer) { return []; } return await options.initializer(createClient()); }, async resolve(actionType, actionName) { if (options.resolver) { return await options.resolver(createClient(), actionType, actionName); } else { if (actionType === "model") { return (0, import_model.defineCompatOpenAIModel)({ name: (0, import_utils.toModelName)(actionName, options.name), client: createClient(), pluginOptions: options, modelRef: (0, import_model.compatOaiModelRef)({ name: actionName, namespace: options.name }) }); } return void 0; } }, list: ( // Don't attempt to list models if apiKey set to false options.listActions && options.apiKey !== false ? async () => { if (listActionsCache) return listActionsCache; listActionsCache = await options.listActions(createClient()); return listActionsCache; } : void 0 ) }); }; var index_default = openAICompatible; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { ChatCompletionCommonConfigSchema, ImageGenerationCommonConfigSchema, SpeechConfigSchema, TranscriptionConfigSchema, TranslationConfigSchema, compatOaiImageModelRef, compatOaiModelRef, compatOaiSpeechModelRef, compatOaiTranscriptionModelRef, compatOaiTranslationModelRef, defineCompatOpenAIEmbedder, defineCompatOpenAIImageModel, defineCompatOpenAIModel, defineCompatOpenAISpeechModel, defineCompatOpenAITranscriptionModel, defineCompatOpenAITranslationModel, openAICompatible, openAIModelRunner }); //# sourceMappingURL=index.js.map