@genkit-ai/compat-oai 1.15.1 → 1.15.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
  var deepseek_exports = {};
30
20
  __export(deepseek_exports, {
@@ -35,7 +25,7 @@ __export(deepseek_exports, {
35
25
  module.exports = __toCommonJS(deepseek_exports);
36
26
  var import_genkit = require("genkit");
37
27
  var import_logging = require("genkit/logging");
38
- var import__ = __toESM(require("../index.js"));
28
+ var import__ = require("../index.js");
39
29
  var import_model = require("../model.js");
40
30
  var import_deepseek = require("./deepseek.js");
41
31
  const resolver = async (ai, client, actionType, actionName) => {
@@ -76,7 +66,7 @@ function deepSeekPlugin(options) {
76
66
  message: "Please pass in the API key or set the DEEPSEEK_API_KEY environment variable."
77
67
  });
78
68
  }
79
- return (0, import__.default)({
69
+ return (0, import__.openAICompatible)({
80
70
  name: "deepseek",
81
71
  baseURL: "https://api.deepseek.com",
82
72
  apiKey,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/deepseek/index.ts"],"sourcesContent":["/**\n * Copyright 2024 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n ActionMetadata,\n Genkit,\n GenkitError,\n modelActionMetadata,\n ModelReference,\n z,\n} from 'genkit';\nimport { logger } from 'genkit/logging';\nimport { GenkitPlugin } from 'genkit/plugin';\nimport { ActionType } from 'genkit/registry';\nimport OpenAI from 'openai';\nimport openAICompatible, { PluginOptions } from '../index.js';\nimport { defineCompatOpenAIModel } from '../model.js';\nimport {\n DeepSeekChatCompletionConfigSchema,\n deepSeekModelRef,\n deepSeekRequestBuilder,\n SUPPORTED_DEEPSEEK_MODELS,\n} from './deepseek.js';\n\nexport type DeepSeekPluginOptions = Omit<PluginOptions, 'name' | 'baseURL'>;\n\nconst resolver = async (\n ai: Genkit,\n client: OpenAI,\n actionType: ActionType,\n actionName: string\n) => {\n if (actionType === 'model') {\n const modelRef = deepSeekModelRef({\n name: `deepseek/${actionName}`,\n });\n defineCompatOpenAIModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n requestBuilder: deepSeekRequestBuilder,\n });\n } else {\n logger.warn('Only model actions are supported by the DeepSeek plugin');\n }\n};\n\nconst listActions = async (client: OpenAI): Promise<ActionMetadata[]> => {\n return await client.models.list().then((response) =>\n response.data\n .filter((model) => model.object === 'model')\n .map((model: OpenAI.Model) => {\n const modelRef =\n SUPPORTED_DEEPSEEK_MODELS[model.id] ??\n deepSeekModelRef({\n name: `deepseek/${model.id}`,\n });\n return modelActionMetadata({\n name: modelRef.name,\n info: modelRef.info,\n configSchema: modelRef.configSchema,\n });\n })\n );\n};\n\nexport function deepSeekPlugin(options?: DeepSeekPluginOptions): GenkitPlugin {\n const apiKey = options?.apiKey ?? process.env.DEEPSEEK_API_KEY;\n if (!apiKey) {\n throw new GenkitError({\n status: 'FAILED_PRECONDITION',\n message:\n 'Please pass in the API key or set the DEEPSEEK_API_KEY environment variable.',\n });\n }\n return openAICompatible({\n name: 'deepseek',\n baseURL: 'https://api.deepseek.com',\n apiKey,\n ...options,\n initializer: async (ai, client) => {\n Object.values(SUPPORTED_DEEPSEEK_MODELS).forEach((modelRef) =>\n defineCompatOpenAIModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n requestBuilder: deepSeekRequestBuilder,\n })\n );\n },\n resolver,\n listActions,\n });\n}\n\nexport type DeepSeekPlugin = {\n (params?: DeepSeekPluginOptions): GenkitPlugin;\n model(\n name: keyof typeof SUPPORTED_DEEPSEEK_MODELS,\n config?: z.infer<typeof DeepSeekChatCompletionConfigSchema>\n ): ModelReference<typeof DeepSeekChatCompletionConfigSchema>;\n model(name: string, config?: any): ModelReference<z.ZodTypeAny>;\n};\n\nconst model = ((name: string, config?: any): ModelReference<z.ZodTypeAny> => {\n return deepSeekModelRef({\n name: `deepseek/${name}`,\n config,\n });\n}) as DeepSeekPlugin['model'];\n\n/**\n * This module provides an interface to the DeepSeek models through the Genkit\n * plugin system. It allows users to interact with various models by providing\n * an API key and optional configuration.\n *\n * The main export is the `deepseek` plugin, which can be configured with an API\n * key either directly or through environment variables. It initializes the\n * OpenAI client and makes available the models for use.\n *\n * Exports:\n * - deepSeek: The main plugin function to interact with DeepSeek, via OpenAI\n * compatible API.\n *\n * Usage: To use the models, initialize the deepseek plugin inside\n * `configureGenkit` and pass the configuration options. If no API key is\n * provided in the options, the environment variable `OPENAI_API_KEY` must be\n * set.\n *\n * Example:\n * ```\n * import { deepSeek } from '@genkit-ai/compat-oai/deepseek';\n *\n * export default configureGenkit({\n * plugins: [\n * deepSeek()\n * ... // other plugins\n * ]\n * });\n * ```\n */\nexport const deepSeek: DeepSeekPlugin = Object.assign(deepSeekPlugin, {\n model,\n});\n\nexport default deepSeek;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBA,oBAOO;AACP,qBAAuB;AAIvB,eAAgD;AAChD,mBAAwC;AACxC,sBAKO;AAIP,MAAM,WAAW,OACf,IACA,QACA,YACA,eACG;AACH,MAAI,eAAe,SAAS;AAC1B,UAAM,eAAW,kCAAiB;AAAA,MAChC,MAAM,YAAY,UAAU;AAAA,IAC9B,CAAC;AACD,8CAAwB;AAAA,MACtB;AAAA,MACA,MAAM,SAAS;AAAA,MACf;AAAA,MACA;AAAA,MACA,gBAAgB;AAAA,IAClB,CAAC;AAAA,EACH,OAAO;AACL,0BAAO,KAAK,yDAAyD;AAAA,EACvE;AACF;AAEA,MAAM,cAAc,OAAO,WAA8C;AACvE,SAAO,MAAM,OAAO,OAAO,KAAK,EAAE;AAAA,IAAK,CAAC,aACtC,SAAS,KACN,OAAO,CAACA,WAAUA,OAAM,WAAW,OAAO,EAC1C,IAAI,CAACA,WAAwB;AAC5B,YAAM,WACJ,0CAA0BA,OAAM,EAAE,SAClC,kCAAiB;AAAA,QACf,MAAM,YAAYA,OAAM,EAAE;AAAA,MAC5B,CAAC;AACH,iBAAO,mCAAoB;AAAA,QACzB,MAAM,SAAS;AAAA,QACf,MAAM,SAAS;AAAA,QACf,cAAc,SAAS;AAAA,MACzB,CAAC;AAAA,IACH,CAAC;AAAA,EACL;AACF;AAEO,SAAS,eAAe,SAA+C;AAC5E,QAAM,SAAS,SAAS,UAAU,QAAQ,IAAI;AAC9C,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI,0BAAY;AAAA,MACpB,QAAQ;AAAA,MACR,SACE;AAAA,IACJ,CAAC;AAAA,EACH;AACA,aAAO,SAAAC,SAAiB;AAAA,IACtB,MAAM;AAAA,IACN,SAAS;AAAA,IACT;AAAA,IACA,GAAG;AAAA,IACH,aAAa,OAAO,IAAI,WAAW;AACjC,aAAO,OAAO,yCAAyB,EAAE;AAAA,QAAQ,CAAC,iBAChD,sCAAwB;AAAA,UACtB;AAAA,UACA,MAAM,SAAS;AAAA,UACf;AAAA,UACA;AAAA,UACA,gBAAgB;AAAA,QAClB,CAAC;AAAA,MACH;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACH;AAWA,MAAM,QAAS,CAAC,MAAc,WAA+C;AAC3E,aAAO,kCAAiB;AAAA,IACtB,MAAM,YAAY,IAAI;AAAA,IACtB;AAAA,EACF,CAAC;AACH;AAgCO,MAAM,WAA2B,OAAO,OAAO,gBAAgB;AAAA,EACpE;AACF,CAAC;AAED,IAAO,mBAAQ;","names":["model","openAICompatible"]}
1
+ {"version":3,"sources":["../../src/deepseek/index.ts"],"sourcesContent":["/**\n * Copyright 2024 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n ActionMetadata,\n Genkit,\n GenkitError,\n modelActionMetadata,\n ModelReference,\n z,\n} from 'genkit';\nimport { logger } from 'genkit/logging';\nimport { GenkitPlugin } from 'genkit/plugin';\nimport { ActionType } from 'genkit/registry';\nimport OpenAI from 'openai';\nimport { openAICompatible, PluginOptions } from '../index.js';\nimport { defineCompatOpenAIModel } from '../model.js';\nimport {\n DeepSeekChatCompletionConfigSchema,\n deepSeekModelRef,\n deepSeekRequestBuilder,\n SUPPORTED_DEEPSEEK_MODELS,\n} from './deepseek.js';\n\nexport type DeepSeekPluginOptions = Omit<PluginOptions, 'name' | 'baseURL'>;\n\nconst resolver = async (\n ai: Genkit,\n client: OpenAI,\n actionType: ActionType,\n actionName: string\n) => {\n if (actionType === 'model') {\n const modelRef = deepSeekModelRef({\n name: `deepseek/${actionName}`,\n });\n defineCompatOpenAIModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n requestBuilder: deepSeekRequestBuilder,\n });\n } else {\n logger.warn('Only model actions are supported by the DeepSeek plugin');\n }\n};\n\nconst listActions = async (client: OpenAI): Promise<ActionMetadata[]> => {\n return await client.models.list().then((response) =>\n response.data\n .filter((model) => model.object === 'model')\n .map((model: OpenAI.Model) => {\n const modelRef =\n SUPPORTED_DEEPSEEK_MODELS[model.id] ??\n deepSeekModelRef({\n name: `deepseek/${model.id}`,\n });\n return modelActionMetadata({\n name: modelRef.name,\n info: modelRef.info,\n configSchema: modelRef.configSchema,\n });\n })\n );\n};\n\nexport function deepSeekPlugin(options?: DeepSeekPluginOptions): GenkitPlugin {\n const apiKey = options?.apiKey ?? process.env.DEEPSEEK_API_KEY;\n if (!apiKey) {\n throw new GenkitError({\n status: 'FAILED_PRECONDITION',\n message:\n 'Please pass in the API key or set the DEEPSEEK_API_KEY environment variable.',\n });\n }\n return openAICompatible({\n name: 'deepseek',\n baseURL: 'https://api.deepseek.com',\n apiKey,\n ...options,\n initializer: async (ai, client) => {\n Object.values(SUPPORTED_DEEPSEEK_MODELS).forEach((modelRef) =>\n defineCompatOpenAIModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n requestBuilder: deepSeekRequestBuilder,\n })\n );\n },\n resolver,\n listActions,\n });\n}\n\nexport type DeepSeekPlugin = {\n (params?: DeepSeekPluginOptions): GenkitPlugin;\n model(\n name: keyof typeof SUPPORTED_DEEPSEEK_MODELS,\n config?: z.infer<typeof DeepSeekChatCompletionConfigSchema>\n ): ModelReference<typeof DeepSeekChatCompletionConfigSchema>;\n model(name: string, config?: any): ModelReference<z.ZodTypeAny>;\n};\n\nconst model = ((name: string, config?: any): ModelReference<z.ZodTypeAny> => {\n return deepSeekModelRef({\n name: `deepseek/${name}`,\n config,\n });\n}) as DeepSeekPlugin['model'];\n\n/**\n * This module provides an interface to the DeepSeek models through the Genkit\n * plugin system. It allows users to interact with various models by providing\n * an API key and optional configuration.\n *\n * The main export is the `deepseek` plugin, which can be configured with an API\n * key either directly or through environment variables. It initializes the\n * OpenAI client and makes available the models for use.\n *\n * Exports:\n * - deepSeek: The main plugin function to interact with DeepSeek, via OpenAI\n * compatible API.\n *\n * Usage: To use the models, initialize the deepseek plugin inside\n * `configureGenkit` and pass the configuration options. If no API key is\n * provided in the options, the environment variable `OPENAI_API_KEY` must be\n * set.\n *\n * Example:\n * ```\n * import { deepSeek } from '@genkit-ai/compat-oai/deepseek';\n *\n * export default configureGenkit({\n * plugins: [\n * deepSeek()\n * ... // other plugins\n * ]\n * });\n * ```\n */\nexport const deepSeek: DeepSeekPlugin = Object.assign(deepSeekPlugin, {\n model,\n});\n\nexport default deepSeek;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBA,oBAOO;AACP,qBAAuB;AAIvB,eAAgD;AAChD,mBAAwC;AACxC,sBAKO;AAIP,MAAM,WAAW,OACf,IACA,QACA,YACA,eACG;AACH,MAAI,eAAe,SAAS;AAC1B,UAAM,eAAW,kCAAiB;AAAA,MAChC,MAAM,YAAY,UAAU;AAAA,IAC9B,CAAC;AACD,8CAAwB;AAAA,MACtB;AAAA,MACA,MAAM,SAAS;AAAA,MACf;AAAA,MACA;AAAA,MACA,gBAAgB;AAAA,IAClB,CAAC;AAAA,EACH,OAAO;AACL,0BAAO,KAAK,yDAAyD;AAAA,EACvE;AACF;AAEA,MAAM,cAAc,OAAO,WAA8C;AACvE,SAAO,MAAM,OAAO,OAAO,KAAK,EAAE;AAAA,IAAK,CAAC,aACtC,SAAS,KACN,OAAO,CAACA,WAAUA,OAAM,WAAW,OAAO,EAC1C,IAAI,CAACA,WAAwB;AAC5B,YAAM,WACJ,0CAA0BA,OAAM,EAAE,SAClC,kCAAiB;AAAA,QACf,MAAM,YAAYA,OAAM,EAAE;AAAA,MAC5B,CAAC;AACH,iBAAO,mCAAoB;AAAA,QACzB,MAAM,SAAS;AAAA,QACf,MAAM,SAAS;AAAA,QACf,cAAc,SAAS;AAAA,MACzB,CAAC;AAAA,IACH,CAAC;AAAA,EACL;AACF;AAEO,SAAS,eAAe,SAA+C;AAC5E,QAAM,SAAS,SAAS,UAAU,QAAQ,IAAI;AAC9C,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI,0BAAY;AAAA,MACpB,QAAQ;AAAA,MACR,SACE;AAAA,IACJ,CAAC;AAAA,EACH;AACA,aAAO,2BAAiB;AAAA,IACtB,MAAM;AAAA,IACN,SAAS;AAAA,IACT;AAAA,IACA,GAAG;AAAA,IACH,aAAa,OAAO,IAAI,WAAW;AACjC,aAAO,OAAO,yCAAyB,EAAE;AAAA,QAAQ,CAAC,iBAChD,sCAAwB;AAAA,UACtB;AAAA,UACA,MAAM,SAAS;AAAA,UACf;AAAA,UACA;AAAA,UACA,gBAAgB;AAAA,QAClB,CAAC;AAAA,MACH;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACH;AAWA,MAAM,QAAS,CAAC,MAAc,WAA+C;AAC3E,aAAO,kCAAiB;AAAA,IACtB,MAAM,YAAY,IAAI;AAAA,IACtB;AAAA,EACF,CAAC;AACH;AAgCO,MAAM,WAA2B,OAAO,OAAO,gBAAgB;AAAA,EACpE;AACF,CAAC;AAED,IAAO,mBAAQ;","names":["model"]}
@@ -3,7 +3,7 @@ import {
3
3
  modelActionMetadata
4
4
  } from "genkit";
5
5
  import { logger } from "genkit/logging";
6
- import openAICompatible from "../index.js";
6
+ import { openAICompatible } from "../index.js";
7
7
  import { defineCompatOpenAIModel } from "../model.js";
8
8
  import {
9
9
  deepSeekModelRef,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/deepseek/index.ts"],"sourcesContent":["/**\n * Copyright 2024 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n ActionMetadata,\n Genkit,\n GenkitError,\n modelActionMetadata,\n ModelReference,\n z,\n} from 'genkit';\nimport { logger } from 'genkit/logging';\nimport { GenkitPlugin } from 'genkit/plugin';\nimport { ActionType } from 'genkit/registry';\nimport OpenAI from 'openai';\nimport openAICompatible, { PluginOptions } from '../index.js';\nimport { defineCompatOpenAIModel } from '../model.js';\nimport {\n DeepSeekChatCompletionConfigSchema,\n deepSeekModelRef,\n deepSeekRequestBuilder,\n SUPPORTED_DEEPSEEK_MODELS,\n} from './deepseek.js';\n\nexport type DeepSeekPluginOptions = Omit<PluginOptions, 'name' | 'baseURL'>;\n\nconst resolver = async (\n ai: Genkit,\n client: OpenAI,\n actionType: ActionType,\n actionName: string\n) => {\n if (actionType === 'model') {\n const modelRef = deepSeekModelRef({\n name: `deepseek/${actionName}`,\n });\n defineCompatOpenAIModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n requestBuilder: deepSeekRequestBuilder,\n });\n } else {\n logger.warn('Only model actions are supported by the DeepSeek plugin');\n }\n};\n\nconst listActions = async (client: OpenAI): Promise<ActionMetadata[]> => {\n return await client.models.list().then((response) =>\n response.data\n .filter((model) => model.object === 'model')\n .map((model: OpenAI.Model) => {\n const modelRef =\n SUPPORTED_DEEPSEEK_MODELS[model.id] ??\n deepSeekModelRef({\n name: `deepseek/${model.id}`,\n });\n return modelActionMetadata({\n name: modelRef.name,\n info: modelRef.info,\n configSchema: modelRef.configSchema,\n });\n })\n );\n};\n\nexport function deepSeekPlugin(options?: DeepSeekPluginOptions): GenkitPlugin {\n const apiKey = options?.apiKey ?? process.env.DEEPSEEK_API_KEY;\n if (!apiKey) {\n throw new GenkitError({\n status: 'FAILED_PRECONDITION',\n message:\n 'Please pass in the API key or set the DEEPSEEK_API_KEY environment variable.',\n });\n }\n return openAICompatible({\n name: 'deepseek',\n baseURL: 'https://api.deepseek.com',\n apiKey,\n ...options,\n initializer: async (ai, client) => {\n Object.values(SUPPORTED_DEEPSEEK_MODELS).forEach((modelRef) =>\n defineCompatOpenAIModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n requestBuilder: deepSeekRequestBuilder,\n })\n );\n },\n resolver,\n listActions,\n });\n}\n\nexport type DeepSeekPlugin = {\n (params?: DeepSeekPluginOptions): GenkitPlugin;\n model(\n name: keyof typeof SUPPORTED_DEEPSEEK_MODELS,\n config?: z.infer<typeof DeepSeekChatCompletionConfigSchema>\n ): ModelReference<typeof DeepSeekChatCompletionConfigSchema>;\n model(name: string, config?: any): ModelReference<z.ZodTypeAny>;\n};\n\nconst model = ((name: string, config?: any): ModelReference<z.ZodTypeAny> => {\n return deepSeekModelRef({\n name: `deepseek/${name}`,\n config,\n });\n}) as DeepSeekPlugin['model'];\n\n/**\n * This module provides an interface to the DeepSeek models through the Genkit\n * plugin system. It allows users to interact with various models by providing\n * an API key and optional configuration.\n *\n * The main export is the `deepseek` plugin, which can be configured with an API\n * key either directly or through environment variables. It initializes the\n * OpenAI client and makes available the models for use.\n *\n * Exports:\n * - deepSeek: The main plugin function to interact with DeepSeek, via OpenAI\n * compatible API.\n *\n * Usage: To use the models, initialize the deepseek plugin inside\n * `configureGenkit` and pass the configuration options. If no API key is\n * provided in the options, the environment variable `OPENAI_API_KEY` must be\n * set.\n *\n * Example:\n * ```\n * import { deepSeek } from '@genkit-ai/compat-oai/deepseek';\n *\n * export default configureGenkit({\n * plugins: [\n * deepSeek()\n * ... // other plugins\n * ]\n * });\n * ```\n */\nexport const deepSeek: DeepSeekPlugin = Object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AW;AACjC,aAAO,OAAO,yBAAyB,EAAE;AAAA,QAAQ,CAAC,aAChD,wBAAwB;AAAA,UACtB;AAAA,UACA,MAAM,SAAS;AAAA,UACf;AAAA,UACA;AAAA,UACA,gBAAgB;AAAA,QAClB,CAAC;AAAA,MACH;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACH;AAWA,MAAM,QAAS,CAAC,MAAc,WAA+C;AAC3E,SAAO,iBAAiB;AAAA,IACtB,MAAM,YAAY,IAAI;AAAA,IACtB;AAAA,EACF,CAAC;AACH;AAgCO,MAAM,WAA2B,OAAO,OAAO,gBAAgB;AAAA,EACpE;AACF,CAAC;AAED,IAAO,mBAAQ;","names":["model"]}
1
+ {"version":3,"sources":["../../src/deepseek/index.ts"],"sourcesContent":["/**\n * Copyright 2024 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n ActionMetadata,\n Genkit,\n GenkitError,\n modelActionMetadata,\n ModelReference,\n z,\n} from 'genkit';\nimport { logger } from 'genkit/logging';\nimport { GenkitPlugin } from 'genkit/plugin';\nimport { ActionType } from 'genkit/registry';\nimport OpenAI from 'openai';\nimport { openAICompatible, PluginOptions } from '../index.js';\nimport { defineCompatOpenAIModel } from '../model.js';\nimport {\n DeepSeekChatCompletionConfigSchema,\n deepSeekModelRef,\n deepSeekRequestBuilder,\n SUPPORTED_DEEPSEEK_MODELS,\n} from './deepseek.js';\n\nexport type DeepSeekPluginOptions = Omit<PluginOptions, 'name' | 'baseURL'>;\n\nconst resolver = async (\n ai: Genkit,\n client: OpenAI,\n actionType: ActionType,\n actionName: string\n) => {\n if (actionType === 'model') {\n const modelRef = deepSeekModelRef({\n name: `deepseek/${actionName}`,\n });\n defineCompatOpenAIModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n requestBuilder: deepSeekRequestBuilder,\n });\n } else {\n logger.warn('Only model actions are supported by the DeepSeek plugin');\n }\n};\n\nconst listActions = async (client: OpenAI): Promise<ActionMetadata[]> => {\n return await client.models.list().then((response) =>\n response.data\n .filter((model) => model.object === 'model')\n .map((model: OpenAI.Model) => {\n const modelRef =\n SUPPORTED_DEEPSEEK_MODELS[model.id] ??\n deepSeekModelRef({\n name: `deepseek/${model.id}`,\n });\n return modelActionMetadata({\n name: modelRef.name,\n info: modelRef.info,\n configSchema: modelRef.configSchema,\n });\n })\n );\n};\n\nexport function deepSeekPlugin(options?: DeepSeekPluginOptions): GenkitPlugin {\n const apiKey = options?.apiKey ?? process.env.DEEPSEEK_API_KEY;\n if (!apiKey) {\n throw new GenkitError({\n status: 'FAILED_PRECONDITION',\n message:\n 'Please pass in the API key or set the DEEPSEEK_API_KEY environment variable.',\n });\n }\n return openAICompatible({\n name: 'deepseek',\n baseURL: 'https://api.deepseek.com',\n apiKey,\n ...options,\n initializer: async (ai, client) => {\n Object.values(SUPPORTED_DEEPSEEK_MODELS).forEach((modelRef) =>\n defineCompatOpenAIModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n requestBuilder: deepSeekRequestBuilder,\n })\n );\n },\n resolver,\n listActions,\n });\n}\n\nexport type DeepSeekPlugin = {\n (params?: DeepSeekPluginOptions): GenkitPlugin;\n model(\n name: keyof typeof SUPPORTED_DEEPSEEK_MODELS,\n config?: z.infer<typeof DeepSeekChatCompletionConfigSchema>\n ): ModelReference<typeof DeepSeekChatCompletionConfigSchema>;\n model(name: string, config?: any): ModelReference<z.ZodTypeAny>;\n};\n\nconst model = ((name: string, config?: any): ModelReference<z.ZodTypeAny> => {\n return deepSeekModelRef({\n name: `deepseek/${name}`,\n config,\n });\n}) as DeepSeekPlugin['model'];\n\n/**\n * This module provides an interface to the DeepSeek models through the Genkit\n * plugin system. It allows users to interact with various models by providing\n * an API key and optional configuration.\n *\n * The main export is the `deepseek` plugin, which can be configured with an API\n * key either directly or through environment variables. It initializes the\n * OpenAI client and makes available the models for use.\n *\n * Exports:\n * - deepSeek: The main plugin function to interact with DeepSeek, via OpenAI\n * compatible API.\n *\n * Usage: To use the models, initialize the deepseek plugin inside\n * `configureGenkit` and pass the configuration options. If no API key is\n * provided in the options, the environment variable `OPENAI_API_KEY` must be\n * set.\n *\n * Example:\n * ```\n * import { deepSeek } from '@genkit-ai/compat-oai/deepseek';\n *\n * export default configureGenkit({\n * plugins: [\n * deepSeek()\n * ... // other plugins\n * ]\n * });\n * ```\n */\nexport const deepSeek: DeepSeekPlugin = Object.assign(deepSeekPlugin, {\n model,\n});\n\nexport default deepSeek;\n"],"mappings":"AAgBA;AAAA,EAGE;AAAA,EACA;AAAA,OAGK;AACP,SAAS,cAAc;AAIvB,SAAS,wBAAuC;AAChD,SAAS,+BAA+B;AACxC;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAIP,MAAM,WAAW,OACf,IACA,QACA,YACA,eACG;AACH,MAAI,eAAe,SAAS;AAC1B,UAAM,WAAW,iBAAiB;AAAA,MAChC,MAAM,YAAY,UAAU;AAAA,IAC9B,CAAC;AACD,4BAAwB;AAAA,MACtB;AAAA,MACA,MAAM,SAAS;AAAA,MACf;AAAA,MACA;AAAA,MACA,gBAAgB;AAAA,IAClB,CAAC;AAAA,EACH,OAAO;AACL,WAAO,KAAK,yDAAyD;AAAA,EACvE;AACF;AAEA,MAAM,cAAc,OAAO,WAA8C;AACvE,SAAO,MAAM,OAAO,OAAO,KAAK,EAAE;AAAA,IAAK,CAAC,aACtC,SAAS,KACN,OAAO,CAACA,WAAUA,OAAM,WAAW,OAAO,EAC1C,IAAI,CAACA,WAAwB;AAC5B,YAAM,WACJ,0BAA0BA,OAAM,EAAE,KAClC,iBAAiB;AAAA,QACf,MAAM,YAAYA,OAAM,EAAE;AAAA,MAC5B,CAAC;AACH,aAAO,oBAAoB;AAAA,QACzB,MAAM,SAAS;AAAA,QACf,MAAM,SAAS;AAAA,QACf,cAAc,SAAS;AAAA,MACzB,CAAC;AAAA,IACH,CAAC;AAAA,EACL;AACF;AAEO,SAAS,eAAe,SAA+C;AAC5E,QAAM,SAAS,SAAS,UAAU,QAAQ,IAAI;AAC9C,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI,YAAY;AAAA,MACpB,QAAQ;AAAA,MACR,SACE;AAAA,IACJ,CAAC;AAAA,EACH;AACA,SAAO,iBAAiB;AAAA,IACtB,MAAM;AAAA,IACN,SAAS;AAAA,IACT;AAAA,IACA,GAAG;AAAA,IACH,aAAa,OAAO,IAAI,WAAW;AACjC,aAAO,OAAO,yBAAyB,EAAE;AAAA,QAAQ,CAAC,aAChD,wBAAwB;AAAA,UACtB;AAAA,UACA,MAAM,SAAS;AAAA,UACf;AAAA,UACA;AAAA,UACA,gBAAgB;AAAA,QAClB,CAAC;AAAA,MACH;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACH;AAWA,MAAM,QAAS,CAAC,MAAc,WAA+C;AAC3E,SAAO,iBAAiB;AAAA,IACtB,MAAM,YAAY,IAAI;AAAA,IACtB;AAAA,EACF,CAAC;AACH;AAgCO,MAAM,WAA2B,OAAO,OAAO,gBAAgB;AAAA,EACpE;AACF,CAAC;AAED,IAAO,mBAAQ;","names":["model"]}
package/lib/image.d.mts CHANGED
@@ -31,18 +31,18 @@ declare const ImageGenerationCommonConfigSchema: z.ZodObject<{
31
31
  response_format: z.ZodOptional<z.ZodEnum<["b64_json", "url"]>>;
32
32
  }, "strip", z.ZodTypeAny, {
33
33
  n: number;
34
- size?: "1024x1024" | "1792x1024" | "1024x1792" | undefined;
35
- style?: "vivid" | "natural" | undefined;
36
34
  user?: string | undefined;
37
- quality?: "standard" | "hd" | undefined;
38
35
  response_format?: "b64_json" | "url" | undefined;
39
- }, {
40
36
  size?: "1024x1024" | "1792x1024" | "1024x1792" | undefined;
41
37
  style?: "vivid" | "natural" | undefined;
38
+ quality?: "standard" | "hd" | undefined;
39
+ }, {
42
40
  user?: string | undefined;
43
41
  n?: number | undefined;
44
- quality?: "standard" | "hd" | undefined;
45
42
  response_format?: "b64_json" | "url" | undefined;
43
+ size?: "1024x1024" | "1792x1024" | "1024x1792" | undefined;
44
+ style?: "vivid" | "natural" | undefined;
45
+ quality?: "standard" | "hd" | undefined;
46
46
  }>;
47
47
  /**
48
48
  * Method to define a new Genkit Model that is compatible with Open AI
package/lib/image.d.ts CHANGED
@@ -31,18 +31,18 @@ declare const ImageGenerationCommonConfigSchema: z.ZodObject<{
31
31
  response_format: z.ZodOptional<z.ZodEnum<["b64_json", "url"]>>;
32
32
  }, "strip", z.ZodTypeAny, {
33
33
  n: number;
34
- size?: "1024x1024" | "1792x1024" | "1024x1792" | undefined;
35
- style?: "vivid" | "natural" | undefined;
36
34
  user?: string | undefined;
37
- quality?: "standard" | "hd" | undefined;
38
35
  response_format?: "b64_json" | "url" | undefined;
39
- }, {
40
36
  size?: "1024x1024" | "1792x1024" | "1024x1792" | undefined;
41
37
  style?: "vivid" | "natural" | undefined;
38
+ quality?: "standard" | "hd" | undefined;
39
+ }, {
42
40
  user?: string | undefined;
43
41
  n?: number | undefined;
44
- quality?: "standard" | "hd" | undefined;
45
42
  response_format?: "b64_json" | "url" | undefined;
43
+ size?: "1024x1024" | "1792x1024" | "1024x1792" | undefined;
44
+ style?: "vivid" | "natural" | undefined;
45
+ quality?: "standard" | "hd" | undefined;
46
46
  }>;
47
47
  /**
48
48
  * Method to define a new Genkit Model that is compatible with Open AI
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
  var openai_exports = {};
30
20
  __export(openai_exports, {
@@ -37,7 +27,7 @@ var import_genkit = require("genkit");
37
27
  var import_audio = require("../audio.js");
38
28
  var import_embedder = require("../embedder.js");
39
29
  var import_image = require("../image.js");
40
- var import__ = __toESM(require("../index.js"));
30
+ var import__ = require("../index.js");
41
31
  var import_model = require("../model.js");
42
32
  var import_dalle = require("./dalle.js");
43
33
  var import_embedder2 = require("./embedder.js");
@@ -124,7 +114,7 @@ const listActions = async (client) => {
124
114
  );
125
115
  };
126
116
  function openAIPlugin(options) {
127
- return (0, import__.default)({
117
+ return (0, import__.openAICompatible)({
128
118
  name: "openai",
129
119
  ...options,
130
120
  initializer: async (ai, client) => {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/openai/index.ts"],"sourcesContent":["/**\n * Copyright 2024 The Fire Company\n * Copyright 2024 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n ActionMetadata,\n embedderActionMetadata,\n embedderRef,\n EmbedderReference,\n Genkit,\n modelActionMetadata,\n ModelReference,\n z,\n} from 'genkit';\nimport { GenkitPlugin } from 'genkit/plugin';\nimport { ActionType } from 'genkit/registry';\nimport OpenAI from 'openai';\nimport {\n defineCompatOpenAISpeechModel,\n defineCompatOpenAITranscriptionModel,\n SpeechConfigSchema,\n TranscriptionConfigSchema,\n} from '../audio.js';\nimport { defineCompatOpenAIEmbedder } from '../embedder.js';\nimport {\n defineCompatOpenAIImageModel,\n ImageGenerationCommonConfigSchema,\n} from '../image.js';\nimport openAICompatible, { PluginOptions } from '../index.js';\nimport { defineCompatOpenAIModel } from '../model.js';\nimport { openAIImageModelRef, SUPPORTED_IMAGE_MODELS } from './dalle.js';\nimport {\n SUPPORTED_EMBEDDING_MODELS,\n TextEmbeddingConfigSchema,\n} from './embedder.js';\nimport {\n OpenAIChatCompletionConfigSchema,\n openAIModelRef,\n SUPPORTED_GPT_MODELS,\n} from './gpt.js';\nimport { openAISpeechModelRef, SUPPORTED_TTS_MODELS } from './tts.js';\nimport {\n openAITranscriptionModelRef,\n SUPPORTED_STT_MODELS,\n} from './whisper.js';\n\nexport type OpenAIPluginOptions = Omit<PluginOptions, 'name' | 'baseURL'>;\n\nconst UNSUPPORTED_MODEL_MATCHERS = ['babbage', 'davinci', 'codex'];\n\nconst resolver = async (\n ai: Genkit,\n client: OpenAI,\n actionType: ActionType,\n actionName: string\n) => {\n if (actionType === 'embedder') {\n defineCompatOpenAIEmbedder({ ai, name: `openai/${actionName}`, client });\n } else if (\n actionName.includes('gpt-image-1') ||\n actionName.includes('dall-e')\n ) {\n const modelRef = openAIImageModelRef({ name: `openai/${actionName}` });\n defineCompatOpenAIImageModel({ ai, name: modelRef.name, client, modelRef });\n } else if (actionName.includes('tts')) {\n const modelRef = openAISpeechModelRef({ name: `openai/${actionName}` });\n defineCompatOpenAISpeechModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n });\n } else if (\n actionName.includes('whisper') ||\n actionName.includes('transcribe')\n ) {\n const modelRef = openAITranscriptionModelRef({\n name: `openai/${actionName}`,\n });\n defineCompatOpenAITranscriptionModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n });\n } else {\n const modelRef = openAIModelRef({ name: `openai/${actionName}` });\n defineCompatOpenAIModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n });\n }\n};\n\nfunction filterOpenAiModels(model: OpenAI.Model): boolean {\n return !UNSUPPORTED_MODEL_MATCHERS.some((m) => model.id.includes(m));\n}\n\nconst listActions = async (client: OpenAI): Promise<ActionMetadata[]> => {\n return await client.models.list().then((response) =>\n response.data.filter(filterOpenAiModels).map((model: OpenAI.Model) => {\n if (model.id.includes('embedding')) {\n return embedderActionMetadata({\n name: `openai/${model.id}`,\n configSchema: TextEmbeddingConfigSchema,\n info: SUPPORTED_EMBEDDING_MODELS[model.id]?.info,\n });\n } else if (\n model.id.includes('gpt-image-1') ||\n model.id.includes('dall-e')\n ) {\n const modelRef =\n SUPPORTED_IMAGE_MODELS[model.id] ??\n openAIImageModelRef({ name: `openai/${model.id}` });\n return modelActionMetadata({\n name: modelRef.name,\n info: modelRef.info,\n configSchema: modelRef.configSchema,\n });\n } else if (model.id.includes('tts')) {\n const modelRef =\n SUPPORTED_TTS_MODELS[model.id] ??\n openAISpeechModelRef({ name: `openai/${model.id}` });\n return modelActionMetadata({\n name: modelRef.name,\n info: modelRef.info,\n configSchema: modelRef.configSchema,\n });\n } else if (\n model.id.includes('whisper') ||\n model.id.includes('transcribe')\n ) {\n const modelRef =\n SUPPORTED_STT_MODELS[model.id] ??\n openAITranscriptionModelRef({ name: `openai/${model.id}` });\n return modelActionMetadata({\n name: modelRef.name,\n info: modelRef.info,\n configSchema: modelRef.configSchema,\n });\n } else {\n const modelRef =\n SUPPORTED_GPT_MODELS[model.id] ??\n openAIModelRef({ name: `openai/${model.id}` });\n return modelActionMetadata({\n name: modelRef.name,\n info: modelRef.info,\n configSchema: modelRef.configSchema,\n });\n }\n })\n );\n};\n\nexport function openAIPlugin(options?: OpenAIPluginOptions): GenkitPlugin {\n return openAICompatible({\n name: 'openai',\n ...options,\n initializer: async (ai, client) => {\n Object.values(SUPPORTED_GPT_MODELS).forEach((modelRef) =>\n defineCompatOpenAIModel({ ai, name: modelRef.name, client, modelRef })\n );\n Object.values(SUPPORTED_EMBEDDING_MODELS).forEach((embedderRef) =>\n defineCompatOpenAIEmbedder({\n ai,\n name: embedderRef.name,\n client,\n embedderRef,\n })\n );\n Object.values(SUPPORTED_TTS_MODELS).forEach((modelRef) =>\n defineCompatOpenAISpeechModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n })\n );\n Object.values(SUPPORTED_STT_MODELS).forEach((modelRef) =>\n defineCompatOpenAITranscriptionModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n })\n );\n Object.values(SUPPORTED_IMAGE_MODELS).forEach((modelRef) =>\n defineCompatOpenAIImageModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n })\n );\n },\n resolver,\n listActions,\n });\n}\n\nexport type OpenAIPlugin = {\n (params?: OpenAIPluginOptions): GenkitPlugin;\n model(\n name:\n | keyof typeof SUPPORTED_GPT_MODELS\n | (`gpt-${string}` & {})\n | (`o${number}` & {}),\n config?: z.infer<typeof OpenAIChatCompletionConfigSchema>\n ): ModelReference<typeof OpenAIChatCompletionConfigSchema>;\n model(\n name:\n | keyof typeof SUPPORTED_IMAGE_MODELS\n | (`dall-e${string}` & {})\n | (`gpt-image-${string}` & {}),\n config?: z.infer<typeof ImageGenerationCommonConfigSchema>\n ): ModelReference<typeof ImageGenerationCommonConfigSchema>;\n model(\n name:\n | keyof typeof SUPPORTED_TTS_MODELS\n | (`tts-${string}` & {})\n | (`${string}-tts` & {}),\n config?: z.infer<typeof SpeechConfigSchema>\n ): ModelReference<typeof SpeechConfigSchema>;\n model(\n name:\n | keyof typeof SUPPORTED_STT_MODELS\n | (`whisper-${string}` & {})\n | (`${string}-transcribe` & {}),\n config?: z.infer<typeof TranscriptionConfigSchema>\n ): ModelReference<typeof TranscriptionConfigSchema>;\n model(name: string, config?: any): ModelReference<z.ZodTypeAny>;\n embedder(\n name:\n | keyof typeof SUPPORTED_EMBEDDING_MODELS\n | (`${string}-embedding-${string}` & {}),\n config?: z.infer<typeof TextEmbeddingConfigSchema>\n ): EmbedderReference<typeof TextEmbeddingConfigSchema>;\n embedder(name: string, config?: any): EmbedderReference<z.ZodTypeAny>;\n};\n\nconst model = ((name: string, config?: any): ModelReference<z.ZodTypeAny> => {\n if (name.includes('gpt-image-1') || name.includes('dall-e')) {\n return openAIImageModelRef({\n name: `openai/${name}`,\n config,\n });\n }\n if (name.includes('tts')) {\n return openAISpeechModelRef({\n name: `openai/${name}`,\n config,\n });\n }\n if (name.includes('whisper') || name.includes('transcribe')) {\n return openAITranscriptionModelRef({\n name: `openai/${name}`,\n config,\n });\n }\n return openAIModelRef({\n name: `openai/${name}`,\n config,\n });\n}) as OpenAIPlugin['model'];\n\nconst embedder = ((\n name: string,\n config?: any\n): EmbedderReference<z.ZodTypeAny> => {\n return embedderRef({\n name: `openai/${name}`,\n config,\n configSchema: TextEmbeddingConfigSchema,\n });\n}) as OpenAIPlugin['embedder'];\n\n/**\n * This module provides an interface to the OpenAI models through the Genkit\n * plugin system. It allows users to interact with various models by providing\n * an API key and optional configuration.\n *\n * The main export is the `openai` plugin, which can be configured with an API\n * key either directly or through environment variables. It initializes the\n * OpenAI client and makes available the models for use.\n *\n * Exports:\n * - openai: The main plugin function to interact with OpenAI.\n *\n * Usage:\n * To use the models, initialize the openai plugin inside `configureGenkit` and\n * pass the configuration options. If no API key is provided in the options, the\n * environment variable `OPENAI_API_KEY` must be set.\n *\n * Example:\n * ```\n * import { openAI } from '@genkit-ai/compat-oai/openai';\n *\n * export default configureGenkit({\n * plugins: [\n * openai()\n * ... // other plugins\n * ]\n * });\n * ```\n */\nexport const openAI: OpenAI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,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACH;AA0CA,MAAM,QAAS,CAAC,MAAc,WAA+C;AAC3E,MAAI,KAAK,SAAS,aAAa,KAAK,KAAK,SAAS,QAAQ,GAAG;AAC3D,eAAO,kCAAoB;AAAA,MACzB,MAAM,UAAU,IAAI;AAAA,MACpB;AAAA,IACF,CAAC;AAAA,EACH;AACA,MAAI,KAAK,SAAS,KAAK,GAAG;AACxB,eAAO,iCAAqB;AAAA,MAC1B,MAAM,UAAU,IAAI;AAAA,MACpB;AAAA,IACF,CAAC;AAAA,EACH;AACA,MAAI,KAAK,SAAS,SAAS,KAAK,KAAK,SAAS,YAAY,GAAG;AAC3D,eAAO,4CAA4B;AAAA,MACjC,MAAM,UAAU,IAAI;AAAA,MACpB;AAAA,IACF,CAAC;AAAA,EACH;AACA,aAAO,2BAAe;AAAA,IACpB,MAAM,UAAU,IAAI;AAAA,IACpB;AAAA,EACF,CAAC;AACH;AAEA,MAAM,WAAY,CAChB,MACA,WACoC;AACpC,aAAO,2BAAY;AAAA,IACjB,MAAM,UAAU,IAAI;AAAA,IACpB;AAAA,IACA,cAAc;AAAA,EAChB,CAAC;AACH;AA+BO,MAAM,SAAuB,OAAO,OAAO,cAAc;AAAA,EAC9D;AAAA,EACA;AACF,CAAC;AAED,IAAO,iBAAQ;","names":["import_embedder","model","openAICompatible","embedderRef"]}
1
+ {"version":3,"sources":["../../src/openai/index.ts"],"sourcesContent":["/**\n * Copyright 2024 The Fire Company\n * Copyright 2024 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n ActionMetadata,\n embedderActionMetadata,\n embedderRef,\n EmbedderReference,\n Genkit,\n modelActionMetadata,\n ModelReference,\n z,\n} from 'genkit';\nimport { GenkitPlugin } from 'genkit/plugin';\nimport { ActionType } from 'genkit/registry';\nimport OpenAI from 'openai';\nimport {\n defineCompatOpenAISpeechModel,\n defineCompatOpenAITranscriptionModel,\n SpeechConfigSchema,\n TranscriptionConfigSchema,\n} from '../audio.js';\nimport { defineCompatOpenAIEmbedder } from '../embedder.js';\nimport {\n defineCompatOpenAIImageModel,\n ImageGenerationCommonConfigSchema,\n} from '../image.js';\nimport { openAICompatible, PluginOptions } from '../index.js';\nimport { defineCompatOpenAIModel } from '../model.js';\nimport { openAIImageModelRef, SUPPORTED_IMAGE_MODELS } from './dalle.js';\nimport {\n SUPPORTED_EMBEDDING_MODELS,\n TextEmbeddingConfigSchema,\n} from './embedder.js';\nimport {\n OpenAIChatCompletionConfigSchema,\n openAIModelRef,\n SUPPORTED_GPT_MODELS,\n} from './gpt.js';\nimport { openAISpeechModelRef, SUPPORTED_TTS_MODELS } from './tts.js';\nimport {\n openAITranscriptionModelRef,\n SUPPORTED_STT_MODELS,\n} from './whisper.js';\n\nexport type OpenAIPluginOptions = Omit<PluginOptions, 'name' | 'baseURL'>;\n\nconst UNSUPPORTED_MODEL_MATCHERS = ['babbage', 'davinci', 'codex'];\n\nconst resolver = async (\n ai: Genkit,\n client: OpenAI,\n actionType: ActionType,\n actionName: string\n) => {\n if (actionType === 'embedder') {\n defineCompatOpenAIEmbedder({ ai, name: `openai/${actionName}`, client });\n } else if (\n actionName.includes('gpt-image-1') ||\n actionName.includes('dall-e')\n ) {\n const modelRef = openAIImageModelRef({ name: `openai/${actionName}` });\n defineCompatOpenAIImageModel({ ai, name: modelRef.name, client, modelRef });\n } else if (actionName.includes('tts')) {\n const modelRef = openAISpeechModelRef({ name: `openai/${actionName}` });\n defineCompatOpenAISpeechModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n });\n } else if (\n actionName.includes('whisper') ||\n actionName.includes('transcribe')\n ) {\n const modelRef = openAITranscriptionModelRef({\n name: `openai/${actionName}`,\n });\n defineCompatOpenAITranscriptionModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n });\n } else {\n const modelRef = openAIModelRef({ name: `openai/${actionName}` });\n defineCompatOpenAIModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n });\n }\n};\n\nfunction filterOpenAiModels(model: OpenAI.Model): boolean {\n return !UNSUPPORTED_MODEL_MATCHERS.some((m) => model.id.includes(m));\n}\n\nconst listActions = async (client: OpenAI): Promise<ActionMetadata[]> => {\n return await client.models.list().then((response) =>\n response.data.filter(filterOpenAiModels).map((model: OpenAI.Model) => {\n if (model.id.includes('embedding')) {\n return embedderActionMetadata({\n name: `openai/${model.id}`,\n configSchema: TextEmbeddingConfigSchema,\n info: SUPPORTED_EMBEDDING_MODELS[model.id]?.info,\n });\n } else if (\n model.id.includes('gpt-image-1') ||\n model.id.includes('dall-e')\n ) {\n const modelRef =\n SUPPORTED_IMAGE_MODELS[model.id] ??\n openAIImageModelRef({ name: `openai/${model.id}` });\n return modelActionMetadata({\n name: modelRef.name,\n info: modelRef.info,\n configSchema: modelRef.configSchema,\n });\n } else if (model.id.includes('tts')) {\n const modelRef =\n SUPPORTED_TTS_MODELS[model.id] ??\n openAISpeechModelRef({ name: `openai/${model.id}` });\n return modelActionMetadata({\n name: modelRef.name,\n info: modelRef.info,\n configSchema: modelRef.configSchema,\n });\n } else if (\n model.id.includes('whisper') ||\n model.id.includes('transcribe')\n ) {\n const modelRef =\n SUPPORTED_STT_MODELS[model.id] ??\n openAITranscriptionModelRef({ name: `openai/${model.id}` });\n return modelActionMetadata({\n name: modelRef.name,\n info: modelRef.info,\n configSchema: modelRef.configSchema,\n });\n } else {\n const modelRef =\n SUPPORTED_GPT_MODELS[model.id] ??\n openAIModelRef({ name: `openai/${model.id}` });\n return modelActionMetadata({\n name: modelRef.name,\n info: modelRef.info,\n configSchema: modelRef.configSchema,\n });\n }\n })\n );\n};\n\nexport function openAIPlugin(options?: OpenAIPluginOptions): GenkitPlugin {\n return openAICompatible({\n name: 'openai',\n ...options,\n initializer: async (ai, client) => {\n Object.values(SUPPORTED_GPT_MODELS).forEach((modelRef) =>\n defineCompatOpenAIModel({ ai, name: modelRef.name, client, modelRef })\n );\n Object.values(SUPPORTED_EMBEDDING_MODELS).forEach((embedderRef) =>\n defineCompatOpenAIEmbedder({\n ai,\n name: embedderRef.name,\n client,\n embedderRef,\n })\n );\n Object.values(SUPPORTED_TTS_MODELS).forEach((modelRef) =>\n defineCompatOpenAISpeechModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n })\n );\n Object.values(SUPPORTED_STT_MODELS).forEach((modelRef) =>\n defineCompatOpenAITranscriptionModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n })\n );\n Object.values(SUPPORTED_IMAGE_MODELS).forEach((modelRef) =>\n defineCompatOpenAIImageModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n })\n );\n },\n resolver,\n listActions,\n });\n}\n\nexport type OpenAIPlugin = {\n (params?: OpenAIPluginOptions): GenkitPlugin;\n model(\n name:\n | keyof typeof SUPPORTED_GPT_MODELS\n | (`gpt-${string}` & {})\n | (`o${number}` & {}),\n config?: z.infer<typeof OpenAIChatCompletionConfigSchema>\n ): ModelReference<typeof OpenAIChatCompletionConfigSchema>;\n model(\n name:\n | keyof typeof SUPPORTED_IMAGE_MODELS\n | (`dall-e${string}` & {})\n | (`gpt-image-${string}` & {}),\n config?: z.infer<typeof ImageGenerationCommonConfigSchema>\n ): ModelReference<typeof ImageGenerationCommonConfigSchema>;\n model(\n name:\n | keyof typeof SUPPORTED_TTS_MODELS\n | (`tts-${string}` & {})\n | (`${string}-tts` & {}),\n config?: z.infer<typeof SpeechConfigSchema>\n ): ModelReference<typeof SpeechConfigSchema>;\n model(\n name:\n | keyof typeof SUPPORTED_STT_MODELS\n | (`whisper-${string}` & {})\n | (`${string}-transcribe` & {}),\n config?: z.infer<typeof TranscriptionConfigSchema>\n ): ModelReference<typeof TranscriptionConfigSchema>;\n model(name: string, config?: any): ModelReference<z.ZodTypeAny>;\n embedder(\n name:\n | keyof typeof SUPPORTED_EMBEDDING_MODELS\n | (`${string}-embedding-${string}` & {}),\n config?: z.infer<typeof TextEmbeddingConfigSchema>\n ): EmbedderReference<typeof TextEmbeddingConfigSchema>;\n embedder(name: string, config?: any): EmbedderReference<z.ZodTypeAny>;\n};\n\nconst model = ((name: string, config?: any): ModelReference<z.ZodTypeAny> => {\n if (name.includes('gpt-image-1') || name.includes('dall-e')) {\n return openAIImageModelRef({\n name: `openai/${name}`,\n config,\n });\n }\n if (name.includes('tts')) {\n return openAISpeechModelRef({\n name: `openai/${name}`,\n config,\n });\n }\n if (name.includes('whisper') || name.includes('transcribe')) {\n return openAITranscriptionModelRef({\n name: `openai/${name}`,\n config,\n });\n }\n return openAIModelRef({\n name: `openai/${name}`,\n config,\n });\n}) as OpenAIPlugin['model'];\n\nconst embedder = ((\n name: string,\n config?: any\n): EmbedderReference<z.ZodTypeAny> => {\n return embedderRef({\n name: `openai/${name}`,\n config,\n configSchema: TextEmbeddingConfigSchema,\n });\n}) as OpenAIPlugin['embedder'];\n\n/**\n * This module provides an interface to the OpenAI models through the Genkit\n * plugin system. It allows users to interact with various models by providing\n * an API key and optional configuration.\n *\n * The main export is the `openai` plugin, which can be configured with an API\n * key either directly or through environment variables. It initializes the\n * OpenAI client and makes available the models for use.\n *\n * Exports:\n * - openai: The main plugin function to interact with OpenAI.\n *\n * Usage:\n * To use the models, initialize the openai plugin inside `configureGenkit` and\n * pass the configuration options. If no API key is provided in the options, the\n * environment variable `OPENAI_API_KEY` must be set.\n *\n * Example:\n * ```\n * import { openAI } from '@genkit-ai/compat-oai/openai';\n *\n * export default configureGenkit({\n * plugins: [\n * openai()\n * ... // other plugins\n * ]\n * });\n * ```\n */\nexport const openAI: OpenAIPlugin = Object.assign(openAIPlugin, {\n model,\n embedder,\n});\n\nexport default openAI;\n"],"mappings":";;;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AAI,KAAK,SAAS,aAAa,KAAK,KAAK,SAAS,QAAQ,GAAG;AAC3D,eAAO,kCAAoB;AAAA,MACzB,MAAM,UAAU,IAAI;AAAA,MACpB;AAAA,IACF,CAAC;AAAA,EACH;AACA,MAAI,KAAK,SAAS,KAAK,GAAG;AACxB,eAAO,iCAAqB;AAAA,MAC1B,MAAM,UAAU,IAAI;AAAA,MACpB;AAAA,IACF,CAAC;AAAA,EACH;AACA,MAAI,KAAK,SAAS,SAAS,KAAK,KAAK,SAAS,YAAY,GAAG;AAC3D,eAAO,4CAA4B;AAAA,MACjC,MAAM,UAAU,IAAI;AAAA,MACpB;AAAA,IACF,CAAC;AAAA,EACH;AACA,aAAO,2BAAe;AAAA,IACpB,MAAM,UAAU,IAAI;AAAA,IACpB;AAAA,EACF,CAAC;AACH;AAEA,MAAM,WAAY,CAChB,MACA,WACoC;AACpC,aAAO,2BAAY;AAAA,IACjB,MAAM,UAAU,IAAI;AAAA,IACpB;AAAA,IACA,cAAc;AAAA,EAChB,CAAC;AACH;AA+BO,MAAM,SAAuB,OAAO,OAAO,cAAc;AAAA,EAC9D;AAAA,EACA;AACF,CAAC;AAED,IAAO,iBAAQ;","names":["import_embedder","model","embedderRef"]}
@@ -11,7 +11,7 @@ import { defineCompatOpenAIEmbedder } from "../embedder.js";
11
11
  import {
12
12
  defineCompatOpenAIImageModel
13
13
  } from "../image.js";
14
- import openAICompatible from "../index.js";
14
+ import { openAICompatible } from "../index.js";
15
15
  import { defineCompatOpenAIModel } from "../model.js";
16
16
  import { openAIImageModelRef, SUPPORTED_IMAGE_MODELS } from "./dalle.js";
17
17
  import {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/openai/index.ts"],"sourcesContent":["/**\n * Copyright 2024 The Fire Company\n * Copyright 2024 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n ActionMetadata,\n embedderActionMetadata,\n embedderRef,\n EmbedderReference,\n Genkit,\n modelActionMetadata,\n ModelReference,\n z,\n} from 'genkit';\nimport { GenkitPlugin } from 'genkit/plugin';\nimport { ActionType } from 'genkit/registry';\nimport OpenAI from 'openai';\nimport {\n defineCompatOpenAISpeechModel,\n defineCompatOpenAITranscriptionModel,\n SpeechConfigSchema,\n TranscriptionConfigSchema,\n} from '../audio.js';\nimport { defineCompatOpenAIEmbedder } from '../embedder.js';\nimport {\n defineCompatOpenAIImageModel,\n ImageGenerationCommonConfigSchema,\n} from '../image.js';\nimport openAICompatible, { PluginOptions } from '../index.js';\nimport { defineCompatOpenAIModel } from '../model.js';\nimport { openAIImageModelRef, SUPPORTED_IMAGE_MODELS } from './dalle.js';\nimport {\n SUPPORTED_EMBEDDING_MODELS,\n TextEmbeddingConfigSchema,\n} from './embedder.js';\nimport {\n OpenAIChatCompletionConfigSchema,\n openAIModelRef,\n SUPPORTED_GPT_MODELS,\n} from './gpt.js';\nimport { openAISpeechModelRef, SUPPORTED_TTS_MODELS } from './tts.js';\nimport {\n openAITranscriptionModelRef,\n SUPPORTED_STT_MODELS,\n} from './whisper.js';\n\nexport type OpenAIPluginOptions = Omit<PluginOptions, 'name' | 'baseURL'>;\n\nconst UNSUPPORTED_MODEL_MATCHERS = ['babbage', 'davinci', 'codex'];\n\nconst resolver = async (\n ai: Genkit,\n client: OpenAI,\n actionType: ActionType,\n actionName: string\n) => {\n if (actionType === 'embedder') {\n defineCompatOpenAIEmbedder({ ai, name: `openai/${actionName}`, client });\n } else if (\n actionName.includes('gpt-image-1') ||\n actionName.includes('dall-e')\n ) {\n const modelRef = openAIImageModelRef({ name: `openai/${actionName}` });\n defineCompatOpenAIImageModel({ ai, name: modelRef.name, client, modelRef });\n } else if (actionName.includes('tts')) {\n const modelRef = openAISpeechModelRef({ name: `openai/${actionName}` });\n defineCompatOpenAISpeechModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n });\n } else if (\n actionName.includes('whisper') ||\n actionName.includes('transcribe')\n ) {\n const modelRef = openAITranscriptionModelRef({\n name: `openai/${actionName}`,\n });\n defineCompatOpenAITranscriptionModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n });\n } else {\n const modelRef = openAIModelRef({ name: `openai/${actionName}` });\n defineCompatOpenAIModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n });\n }\n};\n\nfunction filterOpenAiModels(model: OpenAI.Model): boolean {\n return !UNSUPPORTED_MODEL_MATCHERS.some((m) => model.id.includes(m));\n}\n\nconst listActions = async (client: OpenAI): Promise<ActionMetadata[]> => {\n return await client.models.list().then((response) =>\n response.data.filter(filterOpenAiModels).map((model: OpenAI.Model) => {\n if (model.id.includes('embedding')) {\n return embedderActionMetadata({\n name: `openai/${model.id}`,\n configSchema: TextEmbeddingConfigSchema,\n info: SUPPORTED_EMBEDDING_MODELS[model.id]?.info,\n });\n } else if (\n model.id.includes('gpt-image-1') ||\n model.id.includes('dall-e')\n ) {\n const modelRef =\n SUPPORTED_IMAGE_MODELS[model.id] ??\n openAIImageModelRef({ name: `openai/${model.id}` });\n return modelActionMetadata({\n name: modelRef.name,\n info: modelRef.info,\n configSchema: modelRef.configSchema,\n });\n } else if (model.id.includes('tts')) {\n const modelRef =\n SUPPORTED_TTS_MODELS[model.id] ??\n openAISpeechModelRef({ name: `openai/${model.id}` });\n return modelActionMetadata({\n name: modelRef.name,\n info: modelRef.info,\n configSchema: modelRef.configSchema,\n });\n } else if (\n model.id.includes('whisper') ||\n model.id.includes('transcribe')\n ) {\n const modelRef =\n SUPPORTED_STT_MODELS[model.id] ??\n openAITranscriptionModelRef({ name: `openai/${model.id}` });\n return modelActionMetadata({\n name: modelRef.name,\n info: modelRef.info,\n configSchema: modelRef.configSchema,\n });\n } else {\n const modelRef =\n SUPPORTED_GPT_MODELS[model.id] ??\n openAIModelRef({ name: `openai/${model.id}` });\n return modelActionMetadata({\n name: modelRef.name,\n info: modelRef.info,\n configSchema: modelRef.configSchema,\n });\n }\n })\n );\n};\n\nexport function openAIPlugin(options?: OpenAIPluginOptions): GenkitPlugin {\n return openAICompatible({\n name: 'openai',\n ...options,\n initializer: async (ai, client) => {\n Object.values(SUPPORTED_GPT_MODELS).forEach((modelRef) =>\n defineCompatOpenAIModel({ ai, name: modelRef.name, client, modelRef })\n );\n Object.values(SUPPORTED_EMBEDDING_MODELS).forEach((embedderRef) =>\n defineCompatOpenAIEmbedder({\n ai,\n name: embedderRef.name,\n client,\n embedderRef,\n })\n );\n Object.values(SUPPORTED_TTS_MODELS).forEach((modelRef) =>\n defineCompatOpenAISpeechModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n })\n );\n Object.values(SUPPORTED_STT_MODELS).forEach((modelRef) =>\n defineCompatOpenAITranscriptionModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n })\n );\n Object.values(SUPPORTED_IMAGE_MODELS).forEach((modelRef) =>\n defineCompatOpenAIImageModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n })\n );\n },\n resolver,\n listActions,\n });\n}\n\nexport type OpenAIPlugin = {\n (params?: OpenAIPluginOptions): GenkitPlugin;\n model(\n name:\n | keyof typeof SUPPORTED_GPT_MODELS\n | (`gpt-${string}` & {})\n | (`o${number}` & {}),\n config?: z.infer<typeof OpenAIChatCompletionConfigSchema>\n ): ModelReference<typeof OpenAIChatCompletionConfigSchema>;\n model(\n name:\n | keyof typeof SUPPORTED_IMAGE_MODELS\n | (`dall-e${string}` & {})\n | (`gpt-image-${string}` & {}),\n config?: z.infer<typeof ImageGenerationCommonConfigSchema>\n ): ModelReference<typeof ImageGenerationCommonConfigSchema>;\n model(\n name:\n | keyof typeof SUPPORTED_TTS_MODELS\n | (`tts-${string}` & {})\n | (`${string}-tts` & {}),\n config?: z.infer<typeof SpeechConfigSchema>\n ): ModelReference<typeof SpeechConfigSchema>;\n model(\n name:\n | keyof typeof SUPPORTED_STT_MODELS\n | (`whisper-${string}` & {})\n | (`${string}-transcribe` & {}),\n config?: z.infer<typeof TranscriptionConfigSchema>\n ): ModelReference<typeof TranscriptionConfigSchema>;\n model(name: string, config?: any): ModelReference<z.ZodTypeAny>;\n embedder(\n name:\n | keyof typeof SUPPORTED_EMBEDDING_MODELS\n | (`${string}-embedding-${string}` & {}),\n config?: z.infer<typeof TextEmbeddingConfigSchema>\n ): EmbedderReference<typeof TextEmbeddingConfigSchema>;\n embedder(name: string, config?: any): EmbedderReference<z.ZodTypeAny>;\n};\n\nconst model = ((name: string, config?: any): ModelReference<z.ZodTypeAny> => {\n if (name.includes('gpt-image-1') || name.includes('dall-e')) {\n return openAIImageModelRef({\n name: `openai/${name}`,\n config,\n });\n }\n if (name.includes('tts')) {\n return openAISpeechModelRef({\n name: `openai/${name}`,\n config,\n });\n }\n if (name.includes('whisper') || name.includes('transcribe')) {\n return openAITranscriptionModelRef({\n name: `openai/${name}`,\n config,\n });\n }\n return openAIModelRef({\n name: `openai/${name}`,\n config,\n });\n}) as OpenAIPlugin['model'];\n\nconst embedder = ((\n name: string,\n config?: any\n): EmbedderReference<z.ZodTypeAny> => {\n return embedderRef({\n name: `openai/${name}`,\n config,\n configSchema: TextEmbeddingConfigSchema,\n });\n}) as OpenAIPlugin['embedder'];\n\n/**\n * This module provides an interface to the OpenAI models through the Genkit\n * plugin system. It allows users to interact with various models by providing\n * an API key and optional configuration.\n *\n * The main export is the `openai` plugin, which can be configured with an API\n * key either directly or through environment variables. It initializes the\n * OpenAI client and makes available the models for use.\n *\n * Exports:\n * - openai: The main plugin function to interact with OpenAI.\n *\n * Usage:\n * To use the models, initialize the openai plugin inside `configureGenkit` and\n * pass the configuration options. If no API key is provided in the options, the\n * environment variable `OPENAI_API_KEY` must be set.\n *\n * Example:\n * ```\n * import { openAI } from '@genkit-ai/compat-oai/openai';\n *\n * export default configureGenkit({\n * plugins: [\n * openai()\n * ... // other plugins\n * ]\n * });\n * ```\n */\nexport const openAI: OpenAIPlugin = Object.assign(openAIPlugin, {\n model,\n embedder,\n});\n\nexport default openAI;\n"],"mappings":"AAiBA;AAAA,EAEE;AAAA,EACA;AAAA,EAGA;AAAA,OAGK;AAIP;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AACP,SAAS,kCAAkC;AAC3C;AAAA,EACE;AAAA,OAEK;AACP,OAAO,sBAAyC;AAChD,SAAS,+BAA+B;AACxC,SAAS,qBAAqB,8BAA8B;AAC5D;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP;AAAA,EAEE;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB,4BAA4B;AAC3D;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAIP,MAAM,6BAA6B,CAAC,WAAW,WAAW,OAAO;AAEjE,MAAM,WAAW,OACf,IACA,QACA,YACA,eACG;AACH,MAAI,eAAe,YAAY;AAC7B,+BAA2B,EAAE,IAAI,MAAM,UAAU,UAAU,IAAI,OAAO,CAAC;AAAA,EACzE,WACE,WAAW,SAAS,aAAa,KACjC,WAAW,SAAS,QAAQ,GAC5B;AACA,UAAM,WAAW,oBAAoB,EAAE,MAAM,UAAU,UAAU,GAAG,CAAC;AACrE,iCAA6B,EAAE,IAAI,MAAM,SAAS,MAAM,QAAQ,SAAS,CAAC;AAAA,EAC5E,WAAW,WAAW,SAAS,KAAK,GAAG;AACrC,UAAM,WAAW,qBAAqB,EAAE,MAAM,UAAU,UAAU,GAAG,CAAC;AACtE,kCAA8B;AAAA,MAC5B;AAAA,MACA,MAAM,SAAS;AAAA,MACf;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH,WACE,WAAW,SAAS,SAAS,KAC7B,WAAW,SAAS,YAAY,GAChC;AACA,UAAM,WAAW,4BAA4B;AAAA,MAC3C,MAAM,UAAU,UAAU;AAAA,IAC5B,CAAC;AACD,y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f;AAAA,UACA;AAAA,QACF,CAAC;AAAA,MACH;AACA,aAAO,OAAO,sBAAsB,EAAE;AAAA,QAAQ,CAAC,aAC7C,6BAA6B;AAAA,UAC3B;AAAA,UACA,MAAM,SAAS;AAAA,UACf;AAAA,UACA;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACH;AA0CA,MAAM,QAAS,CAAC,MAAc,WAA+C;AAC3E,MAAI,KAAK,SAAS,aAAa,KAAK,KAAK,SAAS,QAAQ,GAAG;AAC3D,WAAO,oBAAoB;AAAA,MACzB,MAAM,UAAU,IAAI;AAAA,MACpB;AAAA,IACF,CAAC;AAAA,EACH;AACA,MAAI,KAAK,SAAS,KAAK,GAAG;AACxB,WAAO,qBAAqB;AAAA,MAC1B,MAAM,UAAU,IAAI;AAAA,MACpB;AAAA,IACF,CAAC;AAAA,EACH;AACA,MAAI,KAAK,SAAS,SAAS,KAAK,KAAK,SAAS,YAAY,GAAG;AAC3D,WAAO,4BAA4B;AAAA,MACjC,MAAM,UAAU,IAAI;AAAA,MACpB;AAAA,IACF,CAAC;AAAA,EACH;AACA,SAAO,eAAe;AAAA,IACpB,MAAM,UAAU,IAAI;AAAA,IACpB;AAAA,EACF,CAAC;AACH;AAEA,MAAM,WAAY,CAChB,MACA,WACoC;AACpC,SAAO,YAAY;AAAA,IACjB,MAAM,UAAU,IAAI;AAAA,IACpB;AAAA,IACA,cAAc;AAAA,EAChB,CAAC;AACH;AA+BO,MAAM,SAAuB,OAAO,OAAO,cAAc;AAAA,EAC9D;AAAA,EACA;AACF,CAAC;AAED,IAAO,iBAAQ;","names":["model","embedderRef"]}
1
+ {"version":3,"sources":["../../src/openai/index.ts"],"sourcesContent":["/**\n * Copyright 2024 The Fire Company\n * Copyright 2024 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n ActionMetadata,\n embedderActionMetadata,\n embedderRef,\n EmbedderReference,\n Genkit,\n modelActionMetadata,\n ModelReference,\n z,\n} from 'genkit';\nimport { GenkitPlugin } from 'genkit/plugin';\nimport { ActionType } from 'genkit/registry';\nimport OpenAI from 'openai';\nimport {\n defineCompatOpenAISpeechModel,\n defineCompatOpenAITranscriptionModel,\n SpeechConfigSchema,\n TranscriptionConfigSchema,\n} from '../audio.js';\nimport { defineCompatOpenAIEmbedder } from '../embedder.js';\nimport {\n defineCompatOpenAIImageModel,\n ImageGenerationCommonConfigSchema,\n} from '../image.js';\nimport { openAICompatible, PluginOptions } from '../index.js';\nimport { defineCompatOpenAIModel } from '../model.js';\nimport { openAIImageModelRef, SUPPORTED_IMAGE_MODELS } from './dalle.js';\nimport {\n SUPPORTED_EMBEDDING_MODELS,\n TextEmbeddingConfigSchema,\n} from './embedder.js';\nimport {\n OpenAIChatCompletionConfigSchema,\n openAIModelRef,\n SUPPORTED_GPT_MODELS,\n} from './gpt.js';\nimport { openAISpeechModelRef, SUPPORTED_TTS_MODELS } from './tts.js';\nimport {\n openAITranscriptionModelRef,\n SUPPORTED_STT_MODELS,\n} from './whisper.js';\n\nexport type OpenAIPluginOptions = Omit<PluginOptions, 'name' | 'baseURL'>;\n\nconst UNSUPPORTED_MODEL_MATCHERS = ['babbage', 'davinci', 'codex'];\n\nconst resolver = async (\n ai: Genkit,\n client: OpenAI,\n actionType: ActionType,\n actionName: string\n) => {\n if (actionType === 'embedder') {\n defineCompatOpenAIEmbedder({ ai, name: `openai/${actionName}`, client });\n } else if (\n actionName.includes('gpt-image-1') ||\n actionName.includes('dall-e')\n ) {\n const modelRef = openAIImageModelRef({ name: `openai/${actionName}` });\n defineCompatOpenAIImageModel({ ai, name: modelRef.name, client, modelRef });\n } else if (actionName.includes('tts')) {\n const modelRef = openAISpeechModelRef({ name: `openai/${actionName}` });\n defineCompatOpenAISpeechModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n });\n } else if (\n actionName.includes('whisper') ||\n actionName.includes('transcribe')\n ) {\n const modelRef = openAITranscriptionModelRef({\n name: `openai/${actionName}`,\n });\n defineCompatOpenAITranscriptionModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n });\n } else {\n const modelRef = openAIModelRef({ name: `openai/${actionName}` });\n defineCompatOpenAIModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n });\n }\n};\n\nfunction filterOpenAiModels(model: OpenAI.Model): boolean {\n return !UNSUPPORTED_MODEL_MATCHERS.some((m) => model.id.includes(m));\n}\n\nconst listActions = async (client: OpenAI): Promise<ActionMetadata[]> => {\n return await client.models.list().then((response) =>\n response.data.filter(filterOpenAiModels).map((model: OpenAI.Model) => {\n if (model.id.includes('embedding')) {\n return embedderActionMetadata({\n name: `openai/${model.id}`,\n configSchema: TextEmbeddingConfigSchema,\n info: SUPPORTED_EMBEDDING_MODELS[model.id]?.info,\n });\n } else if (\n model.id.includes('gpt-image-1') ||\n model.id.includes('dall-e')\n ) {\n const modelRef =\n SUPPORTED_IMAGE_MODELS[model.id] ??\n openAIImageModelRef({ name: `openai/${model.id}` });\n return modelActionMetadata({\n name: modelRef.name,\n info: modelRef.info,\n configSchema: modelRef.configSchema,\n });\n } else if (model.id.includes('tts')) {\n const modelRef =\n SUPPORTED_TTS_MODELS[model.id] ??\n openAISpeechModelRef({ name: `openai/${model.id}` });\n return modelActionMetadata({\n name: modelRef.name,\n info: modelRef.info,\n configSchema: modelRef.configSchema,\n });\n } else if (\n model.id.includes('whisper') ||\n model.id.includes('transcribe')\n ) {\n const modelRef =\n SUPPORTED_STT_MODELS[model.id] ??\n openAITranscriptionModelRef({ name: `openai/${model.id}` });\n return modelActionMetadata({\n name: modelRef.name,\n info: modelRef.info,\n configSchema: modelRef.configSchema,\n });\n } else {\n const modelRef =\n SUPPORTED_GPT_MODELS[model.id] ??\n openAIModelRef({ name: `openai/${model.id}` });\n return modelActionMetadata({\n name: modelRef.name,\n info: modelRef.info,\n configSchema: modelRef.configSchema,\n });\n }\n })\n );\n};\n\nexport function openAIPlugin(options?: OpenAIPluginOptions): GenkitPlugin {\n return openAICompatible({\n name: 'openai',\n ...options,\n initializer: async (ai, client) => {\n Object.values(SUPPORTED_GPT_MODELS).forEach((modelRef) =>\n defineCompatOpenAIModel({ ai, name: modelRef.name, client, modelRef })\n );\n Object.values(SUPPORTED_EMBEDDING_MODELS).forEach((embedderRef) =>\n defineCompatOpenAIEmbedder({\n ai,\n name: embedderRef.name,\n client,\n embedderRef,\n })\n );\n Object.values(SUPPORTED_TTS_MODELS).forEach((modelRef) =>\n defineCompatOpenAISpeechModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n })\n );\n Object.values(SUPPORTED_STT_MODELS).forEach((modelRef) =>\n defineCompatOpenAITranscriptionModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n })\n );\n Object.values(SUPPORTED_IMAGE_MODELS).forEach((modelRef) =>\n defineCompatOpenAIImageModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n })\n );\n },\n resolver,\n listActions,\n });\n}\n\nexport type OpenAIPlugin = {\n (params?: OpenAIPluginOptions): GenkitPlugin;\n model(\n name:\n | keyof typeof SUPPORTED_GPT_MODELS\n | (`gpt-${string}` & {})\n | (`o${number}` & {}),\n config?: z.infer<typeof OpenAIChatCompletionConfigSchema>\n ): ModelReference<typeof OpenAIChatCompletionConfigSchema>;\n model(\n name:\n | keyof typeof SUPPORTED_IMAGE_MODELS\n | (`dall-e${string}` & {})\n | (`gpt-image-${string}` & {}),\n config?: z.infer<typeof ImageGenerationCommonConfigSchema>\n ): ModelReference<typeof ImageGenerationCommonConfigSchema>;\n model(\n name:\n | keyof typeof SUPPORTED_TTS_MODELS\n | (`tts-${string}` & {})\n | (`${string}-tts` & {}),\n config?: z.infer<typeof SpeechConfigSchema>\n ): ModelReference<typeof SpeechConfigSchema>;\n model(\n name:\n | keyof typeof SUPPORTED_STT_MODELS\n | (`whisper-${string}` & {})\n | (`${string}-transcribe` & {}),\n config?: z.infer<typeof TranscriptionConfigSchema>\n ): ModelReference<typeof TranscriptionConfigSchema>;\n model(name: string, config?: any): ModelReference<z.ZodTypeAny>;\n embedder(\n name:\n | keyof typeof SUPPORTED_EMBEDDING_MODELS\n | (`${string}-embedding-${string}` & {}),\n config?: z.infer<typeof TextEmbeddingConfigSchema>\n ): EmbedderReference<typeof TextEmbeddingConfigSchema>;\n embedder(name: string, config?: any): EmbedderReference<z.ZodTypeAny>;\n};\n\nconst model = ((name: string, config?: any): ModelReference<z.ZodTypeAny> => {\n if (name.includes('gpt-image-1') || name.includes('dall-e')) {\n return openAIImageModelRef({\n name: `openai/${name}`,\n config,\n });\n }\n if (name.includes('tts')) {\n return openAISpeechModelRef({\n name: `openai/${name}`,\n config,\n });\n }\n if (name.includes('whisper') || name.includes('transcribe')) {\n return openAITranscriptionModelRef({\n name: `openai/${name}`,\n config,\n });\n }\n return openAIModelRef({\n name: `openai/${name}`,\n config,\n });\n}) as OpenAIPlugin['model'];\n\nconst embedder = ((\n name: string,\n config?: any\n): EmbedderReference<z.ZodTypeAny> => {\n return embedderRef({\n name: `openai/${name}`,\n config,\n configSchema: TextEmbeddingConfigSchema,\n });\n}) as OpenAIPlugin['embedder'];\n\n/**\n * This module provides an interface to the OpenAI models through the Genkit\n * plugin system. It allows users to interact with various models by providing\n * an API key and optional configuration.\n *\n * The main export is the `openai` plugin, which can be configured with an API\n * key either directly or through environment variables. It initializes the\n * OpenAI client and makes available the models for use.\n *\n * Exports:\n * - openai: The main plugin function to interact with OpenAI.\n *\n * Usage:\n * To use the models, initialize the openai plugin inside `configureGenkit` and\n * pass the configuration options. If no API key is provided in the options, the\n * environment variable `OPENAI_API_KEY` must be set.\n *\n * Example:\n * ```\n * import { openAI } from '@genkit-ai/compat-oai/openai';\n *\n * export default configureGenkit({\n * plugins: [\n * openai()\n * ... // other plugins\n * ]\n * });\n * ```\n */\nexport const openAI: OpenAIPlugin = Object.assign(openAIPlugin, {\n model,\n embedder,\n});\n\nexport default openAI;\n"],"mappings":"AAiBA;AAAA,EAEE;AAAA,EACA;AAAA,EAGA;AAAA,OAGK;AAIP;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AACP,SAAS,kCAAkC;AAC3C;AAAA,EACE;AAAA,OAEK;AACP,SAAS,wBAAuC;AAChD,SAAS,+BAA+B;AACxC,SAAS,qBAAqB,8BAA8B;AAC5D;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP;AAAA,EAEE;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB,4BAA4B;AAC3D;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAIP,MAAM,6BAA6B,CAAC,WAAW,WAAW,OAAO;AAEjE,MAAM,WAAW,OACf,IACA,QACA,YACA,eACG;AACH,MAAI,eAAe,YAAY;AAC7B,+BAA2B,EAAE,IAAI,MAAM,UAAU,UAAU,IAAI,OAAO,CAAC;AAAA,EACzE,WACE,WAAW,SAAS,aAAa,KACjC,WAAW,SAAS,QAAQ,GAC5B;AACA,UAAM,WAAW,oBAAoB,EAAE,MAAM,UAAU,UAAU,GAAG,CAAC;AACrE,iCAA6B,EAAE,IAAI,MAAM,SAAS,MAAM,QAAQ,SAAS,CAAC;AAAA,EAC5E,WAAW,WAAW,SAAS,KAAK,GAAG;AACrC,UAAM,WAAW,qBAAqB,EAAE,MAAM,UAAU,UAAU,GAAG,CAAC;AACtE,kCAA8B;AAAA,MAC5B;AAAA,MACA,MAAM,SAAS;AAAA,MACf;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH,WACE,WAAW,SAAS,SAAS,KAC7B,WAAW,SAAS,YAAY,GAChC;AACA,UAAM,WAAW,4BAA4B;AAAA,MAC3C,MAAM,UAAU,UAAU;AAA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,MAAM,SAAS;AAAA,UACf;AAAA,UACA;AAAA,QACF,CAAC;AAAA,MACH;AACA,aAAO,OAAO,sBAAsB,EAAE;AAAA,QAAQ,CAAC,aAC7C,6BAA6B;AAAA,UAC3B;AAAA,UACA,MAAM,SAAS;AAAA,UACf;AAAA,UACA;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACH;AA0CA,MAAM,QAAS,CAAC,MAAc,WAA+C;AAC3E,MAAI,KAAK,SAAS,aAAa,KAAK,KAAK,SAAS,QAAQ,GAAG;AAC3D,WAAO,oBAAoB;AAAA,MACzB,MAAM,UAAU,IAAI;AAAA,MACpB;AAAA,IACF,CAAC;AAAA,EACH;AACA,MAAI,KAAK,SAAS,KAAK,GAAG;AACxB,WAAO,qBAAqB;AAAA,MAC1B,MAAM,UAAU,IAAI;AAAA,MACpB;AAAA,IACF,CAAC;AAAA,EACH;AACA,MAAI,KAAK,SAAS,SAAS,KAAK,KAAK,SAAS,YAAY,GAAG;AAC3D,WAAO,4BAA4B;AAAA,MACjC,MAAM,UAAU,IAAI;AAAA,MACpB;AAAA,IACF,CAAC;AAAA,EACH;AACA,SAAO,eAAe;AAAA,IACpB,MAAM,UAAU,IAAI;AAAA,IACpB;AAAA,EACF,CAAC;AACH;AAEA,MAAM,WAAY,CAChB,MACA,WACoC;AACpC,SAAO,YAAY;AAAA,IACjB,MAAM,UAAU,IAAI;AAAA,IACpB;AAAA,IACA,cAAc;AAAA,EAChB,CAAC;AACH;AA+BO,MAAM,SAAuB,OAAO,OAAO,cAAc;AAAA,EAC9D;AAAA,EACA;AACF,CAAC;AAED,IAAO,iBAAQ;","names":["model","embedderRef"]}
package/lib/xai/index.js CHANGED
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
  var xai_exports = {};
30
20
  __export(xai_exports, {
@@ -36,7 +26,7 @@ module.exports = __toCommonJS(xai_exports);
36
26
  var import_genkit = require("genkit");
37
27
  var import_logging = require("genkit/logging");
38
28
  var import_image = require("../image.js");
39
- var import__ = __toESM(require("../index.js"));
29
+ var import__ = require("../index.js");
40
30
  var import_model = require("../model.js");
41
31
  var import_grok_image = require("./grok-image.js");
42
32
  var import_grok = require("./grok.js");
@@ -83,7 +73,7 @@ function xAIPlugin(options) {
83
73
  message: "Please pass in the API key or set the XAI_API_KEY environment variable."
84
74
  });
85
75
  }
86
- return (0, import__.default)({
76
+ return (0, import__.openAICompatible)({
87
77
  name: "xai",
88
78
  baseURL: "https://api.x.ai/v1",
89
79
  apiKey,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/xai/index.ts"],"sourcesContent":["/**\n * Copyright 2024 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n ActionMetadata,\n Genkit,\n GenkitError,\n modelActionMetadata,\n ModelReference,\n z,\n} from 'genkit';\nimport { logger } from 'genkit/logging';\nimport { GenkitPlugin } from 'genkit/plugin';\nimport { ActionType } from 'genkit/registry';\nimport OpenAI from 'openai';\nimport {\n defineCompatOpenAIImageModel,\n ImageGenerationCommonConfigSchema,\n} from '../image.js';\nimport openAICompatible, { PluginOptions } from '../index.js';\nimport { defineCompatOpenAIModel } from '../model.js';\nimport { SUPPORTED_IMAGE_MODELS, xaiImageModelRef } from './grok-image.js';\nimport {\n grokRequestBuilder,\n SUPPORTED_LANGUAGE_MODELS,\n XaiChatCompletionConfigSchema,\n xaiModelRef,\n} from './grok.js';\n\nexport type XAIPluginOptions = Omit<PluginOptions, 'name' | 'baseURL'>;\n\nconst resolver = async (\n ai: Genkit,\n client: OpenAI,\n actionType: ActionType,\n actionName: string\n) => {\n if (actionType === 'model') {\n const modelRef = xaiModelRef({ name: `xai/${actionName}` });\n defineCompatOpenAIModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n requestBuilder: grokRequestBuilder,\n });\n } else {\n logger.warn('Only model actions are supported by the XAI plugin');\n }\n};\n\nconst listActions = async (client: OpenAI): Promise<ActionMetadata[]> => {\n return await client.models.list().then((response) =>\n response.data\n .filter((model) => model.object === 'model')\n .map((model: OpenAI.Model) => {\n if (model.id.includes('image')) {\n const modelRef =\n SUPPORTED_IMAGE_MODELS[model.id] ??\n xaiImageModelRef({ name: `xai/${model.id}` });\n return modelActionMetadata({\n name: modelRef.name,\n info: modelRef.info,\n configSchema: modelRef.configSchema,\n });\n } else {\n const modelRef =\n SUPPORTED_LANGUAGE_MODELS[model.id] ??\n xaiModelRef({ name: `xai/${model.id}` });\n return modelActionMetadata({\n name: modelRef.name,\n info: modelRef.info,\n configSchema: modelRef.configSchema,\n });\n }\n })\n );\n};\n\nexport function xAIPlugin(options?: XAIPluginOptions): GenkitPlugin {\n const apiKey = options?.apiKey ?? process.env.XAI_API_KEY;\n if (!apiKey) {\n throw new GenkitError({\n status: 'FAILED_PRECONDITION',\n message:\n 'Please pass in the API key or set the XAI_API_KEY environment variable.',\n });\n }\n return openAICompatible({\n name: 'xai',\n baseURL: 'https://api.x.ai/v1',\n apiKey,\n ...options,\n initializer: async (ai, client) => {\n Object.values(SUPPORTED_LANGUAGE_MODELS).forEach((modelRef) =>\n defineCompatOpenAIModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n requestBuilder: grokRequestBuilder,\n })\n );\n Object.values(SUPPORTED_IMAGE_MODELS).forEach((modelRef) =>\n defineCompatOpenAIImageModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n })\n );\n },\n resolver,\n listActions,\n });\n}\n\nexport type XAIPlugin = {\n (params?: XAIPluginOptions): GenkitPlugin;\n model(\n name: keyof typeof SUPPORTED_LANGUAGE_MODELS,\n config?: z.infer<typeof XaiChatCompletionConfigSchema>\n ): ModelReference<typeof XaiChatCompletionConfigSchema>;\n model(\n name: keyof typeof SUPPORTED_IMAGE_MODELS,\n config?: z.infer<typeof ImageGenerationCommonConfigSchema>\n ): ModelReference<typeof ImageGenerationCommonConfigSchema>;\n model(name: string, config?: any): ModelReference<z.ZodTypeAny>;\n};\n\nconst model = ((name: string, config?: any): ModelReference<z.ZodTypeAny> => {\n if (name.includes('image')) {\n return xaiImageModelRef({\n name: `xai/${name}`,\n config,\n });\n }\n return xaiModelRef({\n name: `xai/${name}`,\n config,\n });\n}) as XAIPlugin['model'];\n\n/**\n * This module provides an interface to the XAI models through the Genkit\n * plugin system. It allows users to interact with various models by providing\n * an API key and optional configuration.\n *\n * The main export is the `xai` plugin, which can be configured with an API\n * key either directly or through environment variables. It initializes the\n * OpenAI client and makes available the models for use.\n *\n * Exports:\n * - xAI: The main plugin function to interact with XAI, via OpenAI\n * compatible API.\n *\n * Usage: To use the models, initialize the xAI plugin inside\n * `configureGenkit` and pass the configuration options. If no API key is\n * provided in the options, the environment variable `OPENAI_API_KEY` must be\n * set.\n *\n * Example:\n * ```\n * import { xAI } from '@genkit-ai/compat-oai/xai';\n *\n * export default configureGenkit({\n * plugins: [\n * xAI()\n * ... // other plugins\n * ]\n * });\n * ```\n */\nexport const xAI: XAIPlugin = Object.assign(xAIPlugin, {\n model,\n});\n\nexport default xAI;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBA,oBAOO;AACP,qBAAuB;AAIvB,mBAGO;AACP,eAAgD;AAChD,mBAAwC;AACxC,wBAAyD;AACzD,kBAKO;AAIP,MAAM,WAAW,OACf,IACA,QACA,YACA,eACG;AACH,MAAI,eAAe,SAAS;AAC1B,UAAM,eAAW,yBAAY,EAAE,MAAM,OAAO,UAAU,GAAG,CAAC;AAC1D,8CAAwB;AAAA,MACtB;AAAA,MACA,MAAM,SAAS;AAAA,MACf;AAAA,MACA;AAAA,MACA,gBAAgB;AAAA,IAClB,CAAC;AAAA,EACH,OAAO;AACL,0BAAO,KAAK,oDAAoD;AAAA,EAClE;AACF;AAEA,MAAM,cAAc,OAAO,WAA8C;AACvE,SAAO,MAAM,OAAO,OAAO,KAAK,EAAE;AAAA,IAAK,CAAC,aACtC,SAAS,KACN,OAAO,CAACA,WAAUA,OAAM,WAAW,OAAO,EAC1C,IAAI,CAACA,WAAwB;AAC5B,UAAIA,OAAM,GAAG,SAAS,OAAO,GAAG;AAC9B,cAAM,WACJ,yCAAuBA,OAAM,EAAE,SAC/B,oCAAiB,EAAE,MAAM,OAAOA,OAAM,EAAE,GAAG,CAAC;AAC9C,mBAAO,mCAAoB;AAAA,UACzB,MAAM,SAAS;AAAA,UACf,MAAM,SAAS;AAAA,UACf,cAAc,SAAS;AAAA,QACzB,CAAC;AAAA,MACH,OAAO;AACL,cAAM,WACJ,sCAA0BA,OAAM,EAAE,SAClC,yBA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
+ {"version":3,"sources":["../../src/xai/index.ts"],"sourcesContent":["/**\n * Copyright 2024 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n ActionMetadata,\n Genkit,\n GenkitError,\n modelActionMetadata,\n ModelReference,\n z,\n} from 'genkit';\nimport { logger } from 'genkit/logging';\nimport { GenkitPlugin } from 'genkit/plugin';\nimport { ActionType } from 'genkit/registry';\nimport OpenAI from 'openai';\nimport {\n defineCompatOpenAIImageModel,\n ImageGenerationCommonConfigSchema,\n} from '../image.js';\nimport { openAICompatible, PluginOptions } from '../index.js';\nimport { defineCompatOpenAIModel } from '../model.js';\nimport { SUPPORTED_IMAGE_MODELS, xaiImageModelRef } from './grok-image.js';\nimport {\n grokRequestBuilder,\n SUPPORTED_LANGUAGE_MODELS,\n XaiChatCompletionConfigSchema,\n xaiModelRef,\n} from './grok.js';\n\nexport type XAIPluginOptions = Omit<PluginOptions, 'name' | 'baseURL'>;\n\nconst resolver = async (\n ai: Genkit,\n client: OpenAI,\n actionType: ActionType,\n actionName: string\n) => {\n if (actionType === 'model') {\n const modelRef = xaiModelRef({ name: `xai/${actionName}` });\n defineCompatOpenAIModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n requestBuilder: grokRequestBuilder,\n });\n } else {\n logger.warn('Only model actions are supported by the XAI plugin');\n }\n};\n\nconst listActions = async (client: OpenAI): Promise<ActionMetadata[]> => {\n return await client.models.list().then((response) =>\n response.data\n .filter((model) => model.object === 'model')\n .map((model: OpenAI.Model) => {\n if (model.id.includes('image')) {\n const modelRef =\n SUPPORTED_IMAGE_MODELS[model.id] ??\n xaiImageModelRef({ name: `xai/${model.id}` });\n return modelActionMetadata({\n name: modelRef.name,\n info: modelRef.info,\n configSchema: modelRef.configSchema,\n });\n } else {\n const modelRef =\n SUPPORTED_LANGUAGE_MODELS[model.id] ??\n xaiModelRef({ name: `xai/${model.id}` });\n return modelActionMetadata({\n name: modelRef.name,\n info: modelRef.info,\n configSchema: modelRef.configSchema,\n });\n }\n })\n );\n};\n\nexport function xAIPlugin(options?: XAIPluginOptions): GenkitPlugin {\n const apiKey = options?.apiKey ?? process.env.XAI_API_KEY;\n if (!apiKey) {\n throw new GenkitError({\n status: 'FAILED_PRECONDITION',\n message:\n 'Please pass in the API key or set the XAI_API_KEY environment variable.',\n });\n }\n return openAICompatible({\n name: 'xai',\n baseURL: 'https://api.x.ai/v1',\n apiKey,\n ...options,\n initializer: async (ai, client) => {\n Object.values(SUPPORTED_LANGUAGE_MODELS).forEach((modelRef) =>\n defineCompatOpenAIModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n requestBuilder: grokRequestBuilder,\n })\n );\n Object.values(SUPPORTED_IMAGE_MODELS).forEach((modelRef) =>\n defineCompatOpenAIImageModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n })\n );\n },\n resolver,\n listActions,\n });\n}\n\nexport type XAIPlugin = {\n (params?: XAIPluginOptions): GenkitPlugin;\n model(\n name: keyof typeof SUPPORTED_LANGUAGE_MODELS,\n config?: z.infer<typeof XaiChatCompletionConfigSchema>\n ): ModelReference<typeof XaiChatCompletionConfigSchema>;\n model(\n name: keyof typeof SUPPORTED_IMAGE_MODELS,\n config?: z.infer<typeof ImageGenerationCommonConfigSchema>\n ): ModelReference<typeof ImageGenerationCommonConfigSchema>;\n model(name: string, config?: any): ModelReference<z.ZodTypeAny>;\n};\n\nconst model = ((name: string, config?: any): ModelReference<z.ZodTypeAny> => {\n if (name.includes('image')) {\n return xaiImageModelRef({\n name: `xai/${name}`,\n config,\n });\n }\n return xaiModelRef({\n name: `xai/${name}`,\n config,\n });\n}) as XAIPlugin['model'];\n\n/**\n * This module provides an interface to the XAI models through the Genkit\n * plugin system. It allows users to interact with various models by providing\n * an API key and optional configuration.\n *\n * The main export is the `xai` plugin, which can be configured with an API\n * key either directly or through environment variables. It initializes the\n * OpenAI client and makes available the models for use.\n *\n * Exports:\n * - xAI: The main plugin function to interact with XAI, via OpenAI\n * compatible API.\n *\n * Usage: To use the models, initialize the xAI plugin inside\n * `configureGenkit` and pass the configuration options. If no API key is\n * provided in the options, the environment variable `OPENAI_API_KEY` must be\n * set.\n *\n * Example:\n * ```\n * import { xAI } from '@genkit-ai/compat-oai/xai';\n *\n * export default configureGenkit({\n * plugins: [\n * xAI()\n * ... // other plugins\n * ]\n * });\n * ```\n */\nexport const xAI: XAIPlugin = Object.assign(xAIPlugin, {\n model,\n});\n\nexport default xAI;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBA,oBAOO;AACP,qBAAuB;AAIvB,mBAGO;AACP,eAAgD;AAChD,mBAAwC;AACxC,wBAAyD;AACzD,kBAKO;AAIP,MAAM,WAAW,OACf,IACA,QACA,YACA,eACG;AACH,MAAI,eAAe,SAAS;AAC1B,UAAM,eAAW,yBAAY,EAAE,MAAM,OAAO,UAAU,GAAG,CAAC;AAC1D,8CAAwB;AAAA,MACtB;AAAA,MACA,MAAM,SAAS;AAAA,MACf;AAAA,MACA;AAAA,MACA,gBAAgB;AAAA,IAClB,CAAC;AAAA,EACH,OAAO;AACL,0BAAO,KAAK,oDAAoD;AAAA,EAClE;AACF;AAEA,MAAM,cAAc,OAAO,WAA8C;AACvE,SAAO,MAAM,OAAO,OAAO,KAAK,EAAE;AAAA,IAAK,CAAC,aACtC,SAAS,KACN,OAAO,CAACA,WAAUA,OAAM,WAAW,OAAO,EAC1C,IAAI,CAACA,WAAwB;AAC5B,UAAIA,OAAM,GAAG,SAAS,OAAO,GAAG;AAC9B,cAAM,WACJ,yCAAuBA,OAAM,EAAE,SAC/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I;AAAA,MACjB;AAAA,IACF,CAAC;AAAA,EACH;AACA,aAAO,yBAAY;AAAA,IACjB,MAAM,OAAO,IAAI;AAAA,IACjB;AAAA,EACF,CAAC;AACH;AAgCO,MAAM,MAAiB,OAAO,OAAO,WAAW;AAAA,EACrD;AACF,CAAC;AAED,IAAO,cAAQ;","names":["model"]}
package/lib/xai/index.mjs CHANGED
@@ -6,7 +6,7 @@ import { logger } from "genkit/logging";
6
6
  import {
7
7
  defineCompatOpenAIImageModel
8
8
  } from "../image.js";
9
- import openAICompatible from "../index.js";
9
+ import { openAICompatible } from "../index.js";
10
10
  import { defineCompatOpenAIModel } from "../model.js";
11
11
  import { SUPPORTED_IMAGE_MODELS, xaiImageModelRef } from "./grok-image.js";
12
12
  import {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/xai/index.ts"],"sourcesContent":["/**\n * Copyright 2024 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n ActionMetadata,\n Genkit,\n GenkitError,\n modelActionMetadata,\n ModelReference,\n z,\n} from 'genkit';\nimport { logger } from 'genkit/logging';\nimport { GenkitPlugin } from 'genkit/plugin';\nimport { ActionType } from 'genkit/registry';\nimport OpenAI from 'openai';\nimport {\n defineCompatOpenAIImageModel,\n ImageGenerationCommonConfigSchema,\n} from '../image.js';\nimport openAICompatible, { PluginOptions } from '../index.js';\nimport { defineCompatOpenAIModel } from '../model.js';\nimport { SUPPORTED_IMAGE_MODELS, xaiImageModelRef } from './grok-image.js';\nimport {\n grokRequestBuilder,\n SUPPORTED_LANGUAGE_MODELS,\n XaiChatCompletionConfigSchema,\n xaiModelRef,\n} from './grok.js';\n\nexport type XAIPluginOptions = Omit<PluginOptions, 'name' | 'baseURL'>;\n\nconst resolver = async (\n ai: Genkit,\n client: OpenAI,\n actionType: ActionType,\n actionName: string\n) => {\n if (actionType === 'model') {\n const modelRef = xaiModelRef({ name: `xai/${actionName}` });\n defineCompatOpenAIModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n requestBuilder: grokRequestBuilder,\n });\n } else {\n logger.warn('Only model actions are supported by the XAI plugin');\n }\n};\n\nconst listActions = async (client: OpenAI): Promise<ActionMetadata[]> => {\n return await client.models.list().then((response) =>\n response.data\n .filter((model) => model.object === 'model')\n .map((model: OpenAI.Model) => {\n if (model.id.includes('image')) {\n const modelRef =\n SUPPORTED_IMAGE_MODELS[model.id] ??\n xaiImageModelRef({ name: `xai/${model.id}` });\n return modelActionMetadata({\n name: modelRef.name,\n info: modelRef.info,\n configSchema: modelRef.configSchema,\n });\n } else {\n const modelRef =\n SUPPORTED_LANGUAGE_MODELS[model.id] ??\n xaiModelRef({ name: `xai/${model.id}` });\n return modelActionMetadata({\n name: modelRef.name,\n info: modelRef.info,\n configSchema: modelRef.configSchema,\n });\n }\n })\n );\n};\n\nexport function xAIPlugin(options?: XAIPluginOptions): GenkitPlugin {\n const apiKey = options?.apiKey ?? process.env.XAI_API_KEY;\n if (!apiKey) {\n throw new GenkitError({\n status: 'FAILED_PRECONDITION',\n message:\n 'Please pass in the API key or set the XAI_API_KEY environment variable.',\n });\n }\n return openAICompatible({\n name: 'xai',\n baseURL: 'https://api.x.ai/v1',\n apiKey,\n ...options,\n initializer: async (ai, client) => {\n Object.values(SUPPORTED_LANGUAGE_MODELS).forEach((modelRef) =>\n defineCompatOpenAIModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n requestBuilder: grokRequestBuilder,\n })\n );\n Object.values(SUPPORTED_IMAGE_MODELS).forEach((modelRef) =>\n defineCompatOpenAIImageModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n })\n );\n },\n resolver,\n listActions,\n });\n}\n\nexport type XAIPlugin = {\n (params?: XAIPluginOptions): GenkitPlugin;\n model(\n name: keyof typeof SUPPORTED_LANGUAGE_MODELS,\n config?: z.infer<typeof XaiChatCompletionConfigSchema>\n ): ModelReference<typeof XaiChatCompletionConfigSchema>;\n model(\n name: keyof typeof SUPPORTED_IMAGE_MODELS,\n config?: z.infer<typeof ImageGenerationCommonConfigSchema>\n ): ModelReference<typeof ImageGenerationCommonConfigSchema>;\n model(name: string, config?: any): ModelReference<z.ZodTypeAny>;\n};\n\nconst model = ((name: string, config?: any): ModelReference<z.ZodTypeAny> => {\n if (name.includes('image')) {\n return xaiImageModelRef({\n name: `xai/${name}`,\n config,\n });\n }\n return xaiModelRef({\n name: `xai/${name}`,\n config,\n });\n}) as XAIPlugin['model'];\n\n/**\n * This module provides an interface to the XAI models through the Genkit\n * plugin system. It allows users to interact with various models by providing\n * an API key and optional configuration.\n *\n * The main export is the `xai` plugin, which can be configured with an API\n * key either directly or through environment variables. It initializes the\n * OpenAI client and makes available the models for use.\n *\n * Exports:\n * - xAI: The main plugin function to interact with XAI, via OpenAI\n * compatible API.\n *\n * Usage: To use the models, initialize the xAI plugin inside\n * `configureGenkit` and pass the configuration options. If no API key is\n * provided in the options, the environment variable `OPENAI_API_KEY` must be\n * set.\n *\n * Example:\n * ```\n * import { xAI } from '@genkit-ai/compat-oai/xai';\n *\n * export default configureGenkit({\n * plugins: [\n * xAI()\n * ... // other plugins\n * ]\n * });\n * ```\n */\nexport const xAI: XAIPlugin = Object.assign(xAIPlugin, {\n model,\n});\n\nexport default xAI;\n"],"mappings":"AAgBA;AAAA,EAGE;AAAA,EACA;AAAA,OAGK;AACP,SAAS,cAAc;AAIvB;AAAA,EACE;AAAA,OAEK;AACP,OAAO,sBAAyC;AAChD,SAAS,+BAA+B;AACxC,SAAS,wBAAwB,wBAAwB;AACzD;AAAA,EACE;AAAA,EACA;AAAA,EAEA;AAAA,OACK;AAIP,MAAM,WAAW,OACf,I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,aAAa,OAAO,IAAI,WAAW;AACjC,aAAO,OAAO,yBAAyB,EAAE;AAAA,QAAQ,CAAC,aAChD,wBAAwB;AAAA,UACtB;AAAA,UACA,MAAM,SAAS;AAAA,UACf;AAAA,UACA;AAAA,UACA,gBAAgB;AAAA,QAClB,CAAC;AAAA,MACH;AACA,aAAO,OAAO,sBAAsB,EAAE;AAAA,QAAQ,CAAC,aAC7C,6BAA6B;AAAA,UAC3B;AAAA,UACA,MAAM,SAAS;AAAA,UACf;AAAA,UACA;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACH;AAeA,MAAM,QAAS,CAAC,MAAc,WAA+C;AAC3E,MAAI,KAAK,SAAS,OAAO,GAAG;AAC1B,WAAO,iBAAiB;AAAA,MACtB,MAAM,OAAO,IAAI;AAAA,MACjB;AAAA,IACF,CAAC;AAAA,EACH;AACA,SAAO,YAAY;AAAA,IACjB,MAAM,OAAO,IAAI;AAAA,IACjB;AAAA,EACF,CAAC;AACH;AAgCO,MAAM,MAAiB,OAAO,OAAO,WAAW;AAAA,EACrD;AACF,CAAC;AAED,IAAO,cAAQ;","names":["model"]}
1
+ {"version":3,"sources":["../../src/xai/index.ts"],"sourcesContent":["/**\n * Copyright 2024 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n ActionMetadata,\n Genkit,\n GenkitError,\n modelActionMetadata,\n ModelReference,\n z,\n} from 'genkit';\nimport { logger } from 'genkit/logging';\nimport { GenkitPlugin } from 'genkit/plugin';\nimport { ActionType } from 'genkit/registry';\nimport OpenAI from 'openai';\nimport {\n defineCompatOpenAIImageModel,\n ImageGenerationCommonConfigSchema,\n} from '../image.js';\nimport { openAICompatible, PluginOptions } from '../index.js';\nimport { defineCompatOpenAIModel } from '../model.js';\nimport { SUPPORTED_IMAGE_MODELS, xaiImageModelRef } from './grok-image.js';\nimport {\n grokRequestBuilder,\n SUPPORTED_LANGUAGE_MODELS,\n XaiChatCompletionConfigSchema,\n xaiModelRef,\n} from './grok.js';\n\nexport type XAIPluginOptions = Omit<PluginOptions, 'name' | 'baseURL'>;\n\nconst resolver = async (\n ai: Genkit,\n client: OpenAI,\n actionType: ActionType,\n actionName: string\n) => {\n if (actionType === 'model') {\n const modelRef = xaiModelRef({ name: `xai/${actionName}` });\n defineCompatOpenAIModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n requestBuilder: grokRequestBuilder,\n });\n } else {\n logger.warn('Only model actions are supported by the XAI plugin');\n }\n};\n\nconst listActions = async (client: OpenAI): Promise<ActionMetadata[]> => {\n return await client.models.list().then((response) =>\n response.data\n .filter((model) => model.object === 'model')\n .map((model: OpenAI.Model) => {\n if (model.id.includes('image')) {\n const modelRef =\n SUPPORTED_IMAGE_MODELS[model.id] ??\n xaiImageModelRef({ name: `xai/${model.id}` });\n return modelActionMetadata({\n name: modelRef.name,\n info: modelRef.info,\n configSchema: modelRef.configSchema,\n });\n } else {\n const modelRef =\n SUPPORTED_LANGUAGE_MODELS[model.id] ??\n xaiModelRef({ name: `xai/${model.id}` });\n return modelActionMetadata({\n name: modelRef.name,\n info: modelRef.info,\n configSchema: modelRef.configSchema,\n });\n }\n })\n );\n};\n\nexport function xAIPlugin(options?: XAIPluginOptions): GenkitPlugin {\n const apiKey = options?.apiKey ?? process.env.XAI_API_KEY;\n if (!apiKey) {\n throw new GenkitError({\n status: 'FAILED_PRECONDITION',\n message:\n 'Please pass in the API key or set the XAI_API_KEY environment variable.',\n });\n }\n return openAICompatible({\n name: 'xai',\n baseURL: 'https://api.x.ai/v1',\n apiKey,\n ...options,\n initializer: async (ai, client) => {\n Object.values(SUPPORTED_LANGUAGE_MODELS).forEach((modelRef) =>\n defineCompatOpenAIModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n requestBuilder: grokRequestBuilder,\n })\n );\n Object.values(SUPPORTED_IMAGE_MODELS).forEach((modelRef) =>\n defineCompatOpenAIImageModel({\n ai,\n name: modelRef.name,\n client,\n modelRef,\n })\n );\n },\n resolver,\n listActions,\n });\n}\n\nexport type XAIPlugin = {\n (params?: XAIPluginOptions): GenkitPlugin;\n model(\n name: keyof typeof SUPPORTED_LANGUAGE_MODELS,\n config?: z.infer<typeof XaiChatCompletionConfigSchema>\n ): ModelReference<typeof XaiChatCompletionConfigSchema>;\n model(\n name: keyof typeof SUPPORTED_IMAGE_MODELS,\n config?: z.infer<typeof ImageGenerationCommonConfigSchema>\n ): ModelReference<typeof ImageGenerationCommonConfigSchema>;\n model(name: string, config?: any): ModelReference<z.ZodTypeAny>;\n};\n\nconst model = ((name: string, config?: any): ModelReference<z.ZodTypeAny> => {\n if (name.includes('image')) {\n return xaiImageModelRef({\n name: `xai/${name}`,\n config,\n });\n }\n return xaiModelRef({\n name: `xai/${name}`,\n config,\n });\n}) as XAIPlugin['model'];\n\n/**\n * This module provides an interface to the XAI models through the Genkit\n * plugin system. It allows users to interact with various models by providing\n * an API key and optional configuration.\n *\n * The main export is the `xai` plugin, which can be configured with an API\n * key either directly or through environment variables. It initializes the\n * OpenAI client and makes available the models for use.\n *\n * Exports:\n * - xAI: The main plugin function to interact with XAI, via OpenAI\n * compatible API.\n *\n * Usage: To use the models, initialize the xAI plugin inside\n * `configureGenkit` and pass the configuration options. If no API key is\n * provided in the options, the environment variable `OPENAI_API_KEY` must be\n * set.\n *\n * Example:\n * ```\n * import { xAI } from '@genkit-ai/compat-oai/xai';\n *\n * export default configureGenkit({\n * plugins: [\n * xAI()\n * ... // other plugins\n * ]\n * });\n * ```\n */\nexport const xAI: XAIPlugin = Object.assign(xAIPlugin, {\n model,\n});\n\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AA0C;AAClE,QAAM,SAAS,SAAS,UAAU,QAAQ,IAAI;AAC9C,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI,YAAY;AAAA,MACpB,QAAQ;AAAA,MACR,SACE;AAAA,IACJ,CAAC;AAAA,EACH;AACA,SAAO,iBAAiB;AAAA,IACtB,MAAM;AAAA,IACN,SAAS;AAAA,IACT;AAAA,IACA,GAAG;AAAA,IACH,aAAa,OAAO,IAAI,WAAW;AACjC,aAAO,OAAO,yBAAyB,EAAE;AAAA,QAAQ,CAAC,aAChD,wBAAwB;AAAA,UACtB;AAAA,UACA,MAAM,SAAS;AAAA,UACf;AAAA,UACA;AAAA,UACA,gBAAgB;AAAA,QAClB,CAAC;AAAA,MACH;AACA,aAAO,OAAO,sBAAsB,EAAE;AAAA,QAAQ,CAAC,aAC7C,6BAA6B;AAAA,UAC3B;AAAA,UACA,MAAM,SAAS;AAAA,UACf;AAAA,UACA;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACH;AAeA,MAAM,QAAS,CAAC,MAAc,WAA+C;AAC3E,MAAI,KAAK,SAAS,OAAO,GAAG;AAC1B,WAAO,iBAAiB;AAAA,MACtB,MAAM,OAAO,IAAI;AAAA,MACjB;AAAA,IACF,CAAC;AAAA,EACH;AACA,SAAO,YAAY;AAAA,IACjB,MAAM,OAAO,IAAI;AAAA,IACjB;AAAA,EACF,CAAC;AACH;AAgCO,MAAM,MAAiB,OAAO,OAAO,WAAW;AAAA,EACrD;AACF,CAAC;AAED,IAAO,cAAQ;","names":["model"]}
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "genai",
12
12
  "generative-ai"
13
13
  ],
14
- "version": "1.15.1",
14
+ "version": "1.15.4",
15
15
  "type": "commonjs",
16
16
  "repository": {
17
17
  "type": "git",
@@ -24,7 +24,7 @@
24
24
  "openai": "^4.95.0"
25
25
  },
26
26
  "peerDependencies": {
27
- "genkit": "^1.15.1"
27
+ "genkit": "^1.15.4"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@jest/globals": "^29.7.0",