@genkit-ai/compat-oai 1.30.0-rc.0 → 1.31.0

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.
Files changed (47) hide show
  1. package/lib/{audio-Cr0WtG4I.d.mts → audio-CW-qdV9D.d.mts} +3 -3
  2. package/lib/{audio-Cr0WtG4I.d.ts → audio-CW-qdV9D.d.ts} +3 -3
  3. package/lib/audio.d.mts +1 -1
  4. package/lib/audio.d.ts +1 -1
  5. package/lib/deepseek/deepseek.d.mts +2 -2
  6. package/lib/deepseek/deepseek.d.ts +2 -2
  7. package/lib/deepseek/index.d.mts +1 -1
  8. package/lib/deepseek/index.d.ts +1 -1
  9. package/lib/deepseek/index.js +2 -2
  10. package/lib/deepseek/index.js.map +1 -1
  11. package/lib/deepseek/index.mjs +2 -2
  12. package/lib/deepseek/index.mjs.map +1 -1
  13. package/lib/embedder.d.mts +1 -1
  14. package/lib/embedder.d.ts +1 -1
  15. package/lib/image.d.mts +1 -1
  16. package/lib/image.d.ts +1 -1
  17. package/lib/index.d.mts +1 -1
  18. package/lib/index.d.ts +1 -1
  19. package/lib/model.d.mts +1 -1
  20. package/lib/model.d.ts +1 -1
  21. package/lib/openai/dalle.d.mts +1 -1
  22. package/lib/openai/dalle.d.ts +1 -1
  23. package/lib/openai/embedder.d.mts +1 -1
  24. package/lib/openai/embedder.d.ts +1 -1
  25. package/lib/openai/gpt.d.mts +1 -1
  26. package/lib/openai/gpt.d.ts +1 -1
  27. package/lib/openai/index.d.mts +1 -1
  28. package/lib/openai/index.d.ts +1 -1
  29. package/lib/openai/index.js +4 -4
  30. package/lib/openai/index.js.map +1 -1
  31. package/lib/openai/index.mjs +4 -4
  32. package/lib/openai/index.mjs.map +1 -1
  33. package/lib/openai/whisper.d.mts +1 -1
  34. package/lib/openai/whisper.d.ts +1 -1
  35. package/lib/translate.d.mts +1 -1
  36. package/lib/translate.d.ts +1 -1
  37. package/lib/utils.d.mts +1 -1
  38. package/lib/utils.d.ts +1 -1
  39. package/lib/xai/grok.d.mts +2 -2
  40. package/lib/xai/grok.d.ts +2 -2
  41. package/lib/xai/index.d.mts +1 -1
  42. package/lib/xai/index.d.ts +1 -1
  43. package/lib/xai/index.js +2 -2
  44. package/lib/xai/index.js.map +1 -1
  45. package/lib/xai/index.mjs +2 -2
  46. package/lib/xai/index.mjs.map +1 -1
  47. package/package.json +3 -3
@@ -1,4 +1,4 @@
1
- import { EmbedderReference, EmbedderAction, GenerateRequest, z, ModelReference, StreamingCallback, GenerateResponseChunkData, GenerateResponseData, Role, Part, MessageData, ToolRequestPart, ActionMetadata } from 'genkit';
1
+ import { EmbedderReference, EmbedderAction, z, GenerateRequest, ModelReference, StreamingCallback, GenerateResponseChunkData, GenerateResponseData, ToolRequestPart, MessageData, Role, Part, ActionMetadata } from 'genkit';
2
2
  import { ModelInfo, ModelAction, ToolDefinition } from 'genkit/model';
3
3
  import OpenAI, { ClientOptions } from 'openai';
4
4
  import { Response } from 'openai/core.mjs';
@@ -7,7 +7,7 @@ import * as genkit_plugin from 'genkit/plugin';
7
7
  import { ResolvableAction } from 'genkit/plugin';
8
8
  import { ActionType } from 'genkit/registry';
9
9
  import { ImageGenerateParams } from 'openai/resources/images.mjs';
10
- import { ChatCompletionCreateParams, ChatCompletionRole, ChatCompletionTool, ChatCompletionContentPart, ChatCompletionMessageParam, ChatCompletionMessageToolCall, ChatCompletionChunk, ChatCompletion } from 'openai/resources/index.mjs';
10
+ import { ChatCompletionCreateParams, ChatCompletion, ChatCompletionChunk, ChatCompletionMessageToolCall, ChatCompletionMessageParam, ChatCompletionRole, ChatCompletionContentPart, ChatCompletionTool } from 'openai/resources/index.mjs';
11
11
 
12
12
  /**
13
13
  * Copyright 2024 The Fire Company
@@ -622,4 +622,4 @@ declare function compatOaiTranscriptionModelRef<CustomOptions extends z.ZodTypeA
622
622
  namespace?: string;
623
623
  }): ModelReference<any>;
624
624
 
625
- export { defineCompatOpenAISpeechModel as A, defineCompatOpenAITranscriptionModel as B, ChatCompletionCommonConfigSchema as C, type SpeechRequestBuilder as D, type TranscriptionRequestBuilder as E, TRANSCRIPTION_MODEL_INFO as F, SPEECH_MODEL_INFO as G, toTTSRequest as H, ImageGenerationCommonConfigSchema as I, speechToGenerateResponse as J, toSttRequest as K, transcriptionToGenerateResponse as L, type ModelRequestBuilder as M, type PluginOptions as P, RESPONSE_FORMAT_MEDIA_TYPES as R, SpeechConfigSchema as S, TranscriptionConfigSchema as T, type ImageRequestBuilder as a, IMAGE_GENERATION_MODEL_INFO as b, defineCompatOpenAIImageModel as c, defineCompatOpenAIEmbedder as d, compatOaiImageModelRef as e, toOpenAITool as f, toOpenAITextAndMedia as g, toOpenAIMessages as h, fromOpenAIToolCall as i, fromOpenAIChoice as j, fromOpenAIChunkChoice as k, toOpenAIRequestBody as l, defineCompatOpenAIModel as m, compatOaiModelRef as n, openAIModelRunner as o, type TranslationRequestBuilder as p, TRANSLATION_MODEL_INFO as q, TranslationConfigSchema as r, toTranslationRequest as s, toOpenAIRole as t, translationToGenerateResponse as u, defineCompatOpenAITranslationModel as v, compatOaiTranslationModelRef as w, openAICompatible as x, compatOaiSpeechModelRef as y, compatOaiTranscriptionModelRef as z };
625
+ export { compatOaiTranscriptionModelRef as A, openAICompatible as B, ChatCompletionCommonConfigSchema as C, defineCompatOpenAISpeechModel as D, defineCompatOpenAITranscriptionModel as E, SPEECH_MODEL_INFO as F, TRANSCRIPTION_MODEL_INFO as G, speechToGenerateResponse as H, ImageGenerationCommonConfigSchema as I, toSttRequest as J, toTTSRequest as K, transcriptionToGenerateResponse as L, type ModelRequestBuilder as M, type PluginOptions as P, RESPONSE_FORMAT_MEDIA_TYPES as R, SpeechConfigSchema as S, TranscriptionConfigSchema as T, type ImageRequestBuilder as a, IMAGE_GENERATION_MODEL_INFO as b, compatOaiImageModelRef as c, defineCompatOpenAIEmbedder as d, defineCompatOpenAIImageModel as e, compatOaiModelRef as f, defineCompatOpenAIModel as g, fromOpenAIChoice as h, fromOpenAIChunkChoice as i, fromOpenAIToolCall as j, toOpenAIRequestBody as k, toOpenAIRole as l, toOpenAITextAndMedia as m, toOpenAITool as n, openAIModelRunner as o, TRANSLATION_MODEL_INFO as p, TranslationConfigSchema as q, type TranslationRequestBuilder as r, compatOaiTranslationModelRef as s, toOpenAIMessages as t, defineCompatOpenAITranslationModel as u, toTranslationRequest as v, translationToGenerateResponse as w, type SpeechRequestBuilder as x, type TranscriptionRequestBuilder as y, compatOaiSpeechModelRef as z };
@@ -1,4 +1,4 @@
1
- import { EmbedderReference, EmbedderAction, GenerateRequest, z, ModelReference, StreamingCallback, GenerateResponseChunkData, GenerateResponseData, Role, Part, MessageData, ToolRequestPart, ActionMetadata } from 'genkit';
1
+ import { EmbedderReference, EmbedderAction, z, GenerateRequest, ModelReference, StreamingCallback, GenerateResponseChunkData, GenerateResponseData, ToolRequestPart, MessageData, Role, Part, ActionMetadata } from 'genkit';
2
2
  import { ModelInfo, ModelAction, ToolDefinition } from 'genkit/model';
3
3
  import OpenAI, { ClientOptions } from 'openai';
4
4
  import { Response } from 'openai/core.mjs';
@@ -7,7 +7,7 @@ import * as genkit_plugin from 'genkit/plugin';
7
7
  import { ResolvableAction } from 'genkit/plugin';
8
8
  import { ActionType } from 'genkit/registry';
9
9
  import { ImageGenerateParams } from 'openai/resources/images.mjs';
10
- import { ChatCompletionCreateParams, ChatCompletionRole, ChatCompletionTool, ChatCompletionContentPart, ChatCompletionMessageParam, ChatCompletionMessageToolCall, ChatCompletionChunk, ChatCompletion } from 'openai/resources/index.mjs';
10
+ import { ChatCompletionCreateParams, ChatCompletion, ChatCompletionChunk, ChatCompletionMessageToolCall, ChatCompletionMessageParam, ChatCompletionRole, ChatCompletionContentPart, ChatCompletionTool } from 'openai/resources/index.mjs';
11
11
 
12
12
  /**
13
13
  * Copyright 2024 The Fire Company
@@ -622,4 +622,4 @@ declare function compatOaiTranscriptionModelRef<CustomOptions extends z.ZodTypeA
622
622
  namespace?: string;
623
623
  }): ModelReference<any>;
624
624
 
625
- export { defineCompatOpenAISpeechModel as A, defineCompatOpenAITranscriptionModel as B, ChatCompletionCommonConfigSchema as C, type SpeechRequestBuilder as D, type TranscriptionRequestBuilder as E, TRANSCRIPTION_MODEL_INFO as F, SPEECH_MODEL_INFO as G, toTTSRequest as H, ImageGenerationCommonConfigSchema as I, speechToGenerateResponse as J, toSttRequest as K, transcriptionToGenerateResponse as L, type ModelRequestBuilder as M, type PluginOptions as P, RESPONSE_FORMAT_MEDIA_TYPES as R, SpeechConfigSchema as S, TranscriptionConfigSchema as T, type ImageRequestBuilder as a, IMAGE_GENERATION_MODEL_INFO as b, defineCompatOpenAIImageModel as c, defineCompatOpenAIEmbedder as d, compatOaiImageModelRef as e, toOpenAITool as f, toOpenAITextAndMedia as g, toOpenAIMessages as h, fromOpenAIToolCall as i, fromOpenAIChoice as j, fromOpenAIChunkChoice as k, toOpenAIRequestBody as l, defineCompatOpenAIModel as m, compatOaiModelRef as n, openAIModelRunner as o, type TranslationRequestBuilder as p, TRANSLATION_MODEL_INFO as q, TranslationConfigSchema as r, toTranslationRequest as s, toOpenAIRole as t, translationToGenerateResponse as u, defineCompatOpenAITranslationModel as v, compatOaiTranslationModelRef as w, openAICompatible as x, compatOaiSpeechModelRef as y, compatOaiTranscriptionModelRef as z };
625
+ export { compatOaiTranscriptionModelRef as A, openAICompatible as B, ChatCompletionCommonConfigSchema as C, defineCompatOpenAISpeechModel as D, defineCompatOpenAITranscriptionModel as E, SPEECH_MODEL_INFO as F, TRANSCRIPTION_MODEL_INFO as G, speechToGenerateResponse as H, ImageGenerationCommonConfigSchema as I, toSttRequest as J, toTTSRequest as K, transcriptionToGenerateResponse as L, type ModelRequestBuilder as M, type PluginOptions as P, RESPONSE_FORMAT_MEDIA_TYPES as R, SpeechConfigSchema as S, TranscriptionConfigSchema as T, type ImageRequestBuilder as a, IMAGE_GENERATION_MODEL_INFO as b, compatOaiImageModelRef as c, defineCompatOpenAIEmbedder as d, defineCompatOpenAIImageModel as e, compatOaiModelRef as f, defineCompatOpenAIModel as g, fromOpenAIChoice as h, fromOpenAIChunkChoice as i, fromOpenAIToolCall as j, toOpenAIRequestBody as k, toOpenAIRole as l, toOpenAITextAndMedia as m, toOpenAITool as n, openAIModelRunner as o, TRANSLATION_MODEL_INFO as p, TranslationConfigSchema as q, type TranslationRequestBuilder as r, compatOaiTranslationModelRef as s, toOpenAIMessages as t, defineCompatOpenAITranslationModel as u, toTranslationRequest as v, translationToGenerateResponse as w, type SpeechRequestBuilder as x, type TranscriptionRequestBuilder as y, compatOaiSpeechModelRef as z };
package/lib/audio.d.mts CHANGED
@@ -3,7 +3,7 @@ import 'genkit/model';
3
3
  import 'openai';
4
4
  import 'openai/core.mjs';
5
5
  import 'openai/resources/audio/index.mjs';
6
- export { R as RESPONSE_FORMAT_MEDIA_TYPES, G as SPEECH_MODEL_INFO, S as SpeechConfigSchema, D as SpeechRequestBuilder, F as TRANSCRIPTION_MODEL_INFO, T as TranscriptionConfigSchema, E as TranscriptionRequestBuilder, y as compatOaiSpeechModelRef, z as compatOaiTranscriptionModelRef, A as defineCompatOpenAISpeechModel, B as defineCompatOpenAITranscriptionModel, J as speechToGenerateResponse, K as toSttRequest, H as toTTSRequest, L as transcriptionToGenerateResponse } from './audio-Cr0WtG4I.mjs';
6
+ export { R as RESPONSE_FORMAT_MEDIA_TYPES, F as SPEECH_MODEL_INFO, S as SpeechConfigSchema, x as SpeechRequestBuilder, G as TRANSCRIPTION_MODEL_INFO, T as TranscriptionConfigSchema, y as TranscriptionRequestBuilder, z as compatOaiSpeechModelRef, A as compatOaiTranscriptionModelRef, D as defineCompatOpenAISpeechModel, E as defineCompatOpenAITranscriptionModel, H as speechToGenerateResponse, J as toSttRequest, K as toTTSRequest, L as transcriptionToGenerateResponse } from './audio-CW-qdV9D.mjs';
7
7
  import 'genkit/plugin';
8
8
  import 'genkit/registry';
9
9
  import 'openai/resources/images.mjs';
package/lib/audio.d.ts CHANGED
@@ -3,7 +3,7 @@ import 'genkit/model';
3
3
  import 'openai';
4
4
  import 'openai/core.mjs';
5
5
  import 'openai/resources/audio/index.mjs';
6
- export { R as RESPONSE_FORMAT_MEDIA_TYPES, G as SPEECH_MODEL_INFO, S as SpeechConfigSchema, D as SpeechRequestBuilder, F as TRANSCRIPTION_MODEL_INFO, T as TranscriptionConfigSchema, E as TranscriptionRequestBuilder, y as compatOaiSpeechModelRef, z as compatOaiTranscriptionModelRef, A as defineCompatOpenAISpeechModel, B as defineCompatOpenAITranscriptionModel, J as speechToGenerateResponse, K as toSttRequest, H as toTTSRequest, L as transcriptionToGenerateResponse } from './audio-Cr0WtG4I.js';
6
+ export { R as RESPONSE_FORMAT_MEDIA_TYPES, F as SPEECH_MODEL_INFO, S as SpeechConfigSchema, x as SpeechRequestBuilder, G as TRANSCRIPTION_MODEL_INFO, T as TranscriptionConfigSchema, y as TranscriptionRequestBuilder, z as compatOaiSpeechModelRef, A as compatOaiTranscriptionModelRef, D as defineCompatOpenAISpeechModel, E as defineCompatOpenAITranscriptionModel, H as speechToGenerateResponse, J as toSttRequest, K as toTTSRequest, L as transcriptionToGenerateResponse } from './audio-CW-qdV9D.js';
7
7
  import 'genkit/plugin';
8
8
  import 'genkit/registry';
9
9
  import 'openai/resources/images.mjs';
@@ -1,6 +1,6 @@
1
1
  import { z } from 'genkit';
2
- import { ModelInfo, ModelReference } from 'genkit/model';
3
- import { M as ModelRequestBuilder } from '../audio-Cr0WtG4I.mjs';
2
+ import { ModelReference, ModelInfo } from 'genkit/model';
3
+ import { M as ModelRequestBuilder } from '../audio-CW-qdV9D.mjs';
4
4
  import 'openai';
5
5
  import 'openai/core.mjs';
6
6
  import 'openai/resources/audio/index.mjs';
@@ -1,6 +1,6 @@
1
1
  import { z } from 'genkit';
2
- import { ModelInfo, ModelReference } from 'genkit/model';
3
- import { M as ModelRequestBuilder } from '../audio-Cr0WtG4I.js';
2
+ import { ModelReference, ModelInfo } from 'genkit/model';
3
+ import { M as ModelRequestBuilder } from '../audio-CW-qdV9D.js';
4
4
  import 'openai';
5
5
  import 'openai/core.mjs';
6
6
  import 'openai/resources/audio/index.mjs';
@@ -1,6 +1,6 @@
1
1
  import { z, ModelReference } from 'genkit';
2
2
  import { GenkitPluginV2 } from 'genkit/plugin';
3
- import { P as PluginOptions } from '../audio-Cr0WtG4I.mjs';
3
+ import { P as PluginOptions } from '../audio-CW-qdV9D.mjs';
4
4
  import { SUPPORTED_DEEPSEEK_MODELS, DeepSeekChatCompletionConfigSchema } from './deepseek.mjs';
5
5
  import 'genkit/model';
6
6
  import 'openai';
@@ -1,6 +1,6 @@
1
1
  import { z, ModelReference } from 'genkit';
2
2
  import { GenkitPluginV2 } from 'genkit/plugin';
3
- import { P as PluginOptions } from '../audio-Cr0WtG4I.js';
3
+ import { P as PluginOptions } from '../audio-CW-qdV9D.js';
4
4
  import { SUPPORTED_DEEPSEEK_MODELS, DeepSeekChatCompletionConfigSchema } from './deepseek.js';
5
5
  import 'genkit/model';
6
6
  import 'openai';
@@ -90,12 +90,12 @@ function deepSeekPlugin(options) {
90
90
  listActions
91
91
  });
92
92
  }
93
- const model = (name, config) => {
93
+ const model = ((name, config) => {
94
94
  return (0, import_deepseek.deepSeekModelRef)({
95
95
  name,
96
96
  config
97
97
  });
98
- };
98
+ });
99
99
  const deepSeek = Object.assign(deepSeekPlugin, {
100
100
  model
101
101
  });
@@ -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 GenkitError,\n modelActionMetadata,\n ModelReference,\n z,\n} from 'genkit';\nimport { logger } from 'genkit/logging';\nimport { type GenkitPluginV2 } 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\nfunction createResolver(pluginOptions: PluginOptions) {\n return async (client: OpenAI, actionType: ActionType, actionName: string) => {\n if (actionType === 'model') {\n const modelRef = deepSeekModelRef({\n name: actionName,\n });\n return defineCompatOpenAIModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n requestBuilder: deepSeekRequestBuilder,\n });\n } else {\n logger.warn('Only model actions are supported by the DeepSeek plugin');\n return undefined;\n }\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: 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(\n options?: DeepSeekPluginOptions\n): GenkitPluginV2 {\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 const pluginOptions = { name: 'deepseek', ...options };\n return openAICompatible({\n name: 'deepseek',\n baseURL: 'https://api.deepseek.com',\n apiKey,\n ...options,\n initializer: async (client) => {\n return Object.values(SUPPORTED_DEEPSEEK_MODELS).map((modelRef) =>\n defineCompatOpenAIModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n requestBuilder: deepSeekRequestBuilder,\n })\n );\n },\n resolver: createResolver(pluginOptions),\n listActions,\n });\n}\n\nexport type DeepSeekPlugin = {\n (params?: DeepSeekPluginOptions): GenkitPluginV2;\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,\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,oBAMO;AACP,qBAAuB;AAIvB,eAAgD;AAChD,mBAAwC;AACxC,sBAKO;AAIP,SAAS,eAAe,eAA8B;AACpD,SAAO,OAAO,QAAgB,YAAwB,eAAuB;AAC3E,QAAI,eAAe,SAAS;AAC1B,YAAM,eAAW,kCAAiB;AAAA,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WA,MAAM,QAAS,CAAC,MAAc,WAA+C;AAC3E,aAAO,kCAAiB;AAAA,IACtB;AAAA,IACA;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 GenkitError,\n modelActionMetadata,\n ModelReference,\n z,\n} from 'genkit';\nimport { logger } from 'genkit/logging';\nimport { type GenkitPluginV2 } 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\nfunction createResolver(pluginOptions: PluginOptions) {\n return async (client: OpenAI, actionType: ActionType, actionName: string) => {\n if (actionType === 'model') {\n const modelRef = deepSeekModelRef({\n name: actionName,\n });\n return defineCompatOpenAIModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n requestBuilder: deepSeekRequestBuilder,\n });\n } else {\n logger.warn('Only model actions are supported by the DeepSeek plugin');\n return undefined;\n }\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: 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(\n options?: DeepSeekPluginOptions\n): GenkitPluginV2 {\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 const pluginOptions = { name: 'deepseek', ...options };\n return openAICompatible({\n name: 'deepseek',\n baseURL: 'https://api.deepseek.com',\n apiKey,\n ...options,\n initializer: async (client) => {\n return Object.values(SUPPORTED_DEEPSEEK_MODELS).map((modelRef) =>\n defineCompatOpenAIModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n requestBuilder: deepSeekRequestBuilder,\n })\n );\n },\n resolver: createResolver(pluginOptions),\n listActions,\n });\n}\n\nexport type DeepSeekPlugin = {\n (params?: DeepSeekPluginOptions): GenkitPluginV2;\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,\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,oBAMO;AACP,qBAAuB;AAIvB,eAAgD;AAChD,mBAAwC;AACxC,sBAKO;AAIP,SAAS,eAAe,eAA8B;AACpD,SAAO,OAAO,QAAgB,YAAwB,eAAuB;AAC3E,QAAI,eAAe,SAAS;AAC1B,YAAM,eAAW,kCAAiB;AAAA,QAChC,MAAM;AAAA,MACR,CAAC;AACD,iBAAO,sCAAwB;AAAA,QAC7B,MAAM,SAAS;AAAA,QACf;AAAA,QACA;AAAA,QACA;AAAA,QACA,gBAAgB;AAAA,MAClB,CAAC;AAAA,IACH,OAAO;AACL,4BAAO,KAAK,yDAAyD;AACrE,aAAO;AAAA,IACT;AAAA,EACF;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,MAAMA,OAAM;AAAA,MACd,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,eACd,SACgB;AAChB,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,QAAM,gBAAgB,EAAE,MAAM,YAAY,GAAG,QAAQ;AACrD,aAAO,2BAAiB;AAAA,IACtB,MAAM;AAAA,IACN,SAAS;AAAA,IACT;AAAA,IACA,GAAG;AAAA,IACH,aAAa,OAAO,WAAW;AAC7B,aAAO,OAAO,OAAO,yCAAyB,EAAE;AAAA,QAAI,CAAC,iBACnD,sCAAwB;AAAA,UACtB,MAAM,SAAS;AAAA,UACf;AAAA,UACA;AAAA,UACA;AAAA,UACA,gBAAgB;AAAA,QAClB,CAAC;AAAA,MACH;AAAA,IACF;AAAA,IACA,UAAU,eAAe,aAAa;AAAA,IACtC;AAAA,EACF,CAAC;AACH;AAWA,MAAM,SAAS,CAAC,MAAc,WAA+C;AAC3E,aAAO,kCAAiB;AAAA,IACtB;AAAA,IACA;AAAA,EACF,CAAC;AACH;AAgCO,MAAM,WAA2B,OAAO,OAAO,gBAAgB;AAAA,EACpE;AACF,CAAC;AAED,IAAO,mBAAQ;","names":["model"]}
@@ -72,12 +72,12 @@ function deepSeekPlugin(options) {
72
72
  listActions
73
73
  });
74
74
  }
75
- const model = (name, config) => {
75
+ const model = ((name, config) => {
76
76
  return deepSeekModelRef({
77
77
  name,
78
78
  config
79
79
  });
80
- };
80
+ });
81
81
  const deepSeek = Object.assign(deepSeekPlugin, {
82
82
  model
83
83
  });
@@ -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 GenkitError,\n modelActionMetadata,\n ModelReference,\n z,\n} from 'genkit';\nimport { logger } from 'genkit/logging';\nimport { type GenkitPluginV2 } 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\nfunction createResolver(pluginOptions: PluginOptions) {\n return async (client: OpenAI, actionType: ActionType, actionName: string) => {\n if (actionType === 'model') {\n const modelRef = deepSeekModelRef({\n name: actionName,\n });\n return defineCompatOpenAIModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n requestBuilder: deepSeekRequestBuilder,\n });\n } else {\n logger.warn('Only model actions are supported by the DeepSeek plugin');\n return undefined;\n }\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: 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(\n options?: DeepSeekPluginOptions\n): GenkitPluginV2 {\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 const pluginOptions = { name: 'deepseek', ...options };\n return openAICompatible({\n name: 'deepseek',\n baseURL: 'https://api.deepseek.com',\n apiKey,\n ...options,\n initializer: async (client) => {\n return Object.values(SUPPORTED_DEEPSEEK_MODELS).map((modelRef) =>\n defineCompatOpenAIModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n requestBuilder: deepSeekRequestBuilder,\n })\n );\n },\n resolver: createResolver(pluginOptions),\n listActions,\n });\n}\n\nexport type DeepSeekPlugin = {\n (params?: DeepSeekPluginOptions): GenkitPluginV2;\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,\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,EAEE;AAAA,EACA;AAAA,OAGK;AACP,SAAS,cAAc;AAIvB,SAAS,wBAAuC;AAChD,SAAS,+BAA+B;AACxC;AAAA,EAEE;AAA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;AAAA,UACA;AAAA,UACA;AAAA,UACA,gBAAgB;AAAA,QAClB,CAAC;AAAA,MACH;AAAA,IACF;AAAA,IACA,UAAU,eAAe,aAAa;AAAA,IACtC;AAAA,EACF,CAAC;AACH;AAWA,MAAM,QAAS,CAAC,MAAc,WAA+C;AAC3E,SAAO,iBAAiB;AAAA,IACtB;AAAA,IACA;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 GenkitError,\n modelActionMetadata,\n ModelReference,\n z,\n} from 'genkit';\nimport { logger } from 'genkit/logging';\nimport { type GenkitPluginV2 } 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\nfunction createResolver(pluginOptions: PluginOptions) {\n return async (client: OpenAI, actionType: ActionType, actionName: string) => {\n if (actionType === 'model') {\n const modelRef = deepSeekModelRef({\n name: actionName,\n });\n return defineCompatOpenAIModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n requestBuilder: deepSeekRequestBuilder,\n });\n } else {\n logger.warn('Only model actions are supported by the DeepSeek plugin');\n return undefined;\n }\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: 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(\n options?: DeepSeekPluginOptions\n): GenkitPluginV2 {\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 const pluginOptions = { name: 'deepseek', ...options };\n return openAICompatible({\n name: 'deepseek',\n baseURL: 'https://api.deepseek.com',\n apiKey,\n ...options,\n initializer: async (client) => {\n return Object.values(SUPPORTED_DEEPSEEK_MODELS).map((modelRef) =>\n defineCompatOpenAIModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n requestBuilder: deepSeekRequestBuilder,\n })\n );\n },\n resolver: createResolver(pluginOptions),\n listActions,\n });\n}\n\nexport type DeepSeekPlugin = {\n (params?: DeepSeekPluginOptions): GenkitPluginV2;\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,\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,EAEE;AAAA,EACA;AAAA,OAGK;AACP,SAAS,cAAc;AAIvB,SAAS,wBAAuC;AAChD,SAAS,+BAA+B;AACxC;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAIP,SAAS,eAAe,eAA8B;AACpD,SAAO,OAAO,QAAgB,YAAwB,eAAuB;AAC3E,QAAI,eAAe,SAAS;AAC1B,YAAM,WAAW,iBAAiB;AAAA,QAChC,MAAM;AAAA,MACR,CAAC;AACD,aAAO,wBAAwB;AAAA,QAC7B,MAAM,SAAS;AAAA,QACf;AAAA,QACA;AAAA,QACA;AAAA,QACA,gBAAgB;AAAA,MAClB,CAAC;AAAA,IACH,OAAO;AACL,aAAO,KAAK,yDAAyD;AACrE,aAAO;AAAA,IACT;AAAA,EACF;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,MAAMA,OAAM;AAAA,MACd,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,eACd,SACgB;AAChB,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,QAAM,gBAAgB,EAAE,MAAM,YAAY,GAAG,QAAQ;AACrD,SAAO,iBAAiB;AAAA,IACtB,MAAM;AAAA,IACN,SAAS;AAAA,IACT;AAAA,IACA,GAAG;AAAA,IACH,aAAa,OAAO,WAAW;AAC7B,aAAO,OAAO,OAAO,yBAAyB,EAAE;AAAA,QAAI,CAAC,aACnD,wBAAwB;AAAA,UACtB,MAAM,SAAS;AAAA,UACf;AAAA,UACA;AAAA,UACA;AAAA,UACA,gBAAgB;AAAA,QAClB,CAAC;AAAA,MACH;AAAA,IACF;AAAA,IACA,UAAU,eAAe,aAAa;AAAA,IACtC;AAAA,EACF,CAAC;AACH;AAWA,MAAM,SAAS,CAAC,MAAc,WAA+C;AAC3E,SAAO,iBAAiB;AAAA,IACtB;AAAA,IACA;AAAA,EACF,CAAC;AACH;AAgCO,MAAM,WAA2B,OAAO,OAAO,gBAAgB;AAAA,EACpE;AACF,CAAC;AAED,IAAO,mBAAQ;","names":["model"]}
@@ -1,6 +1,6 @@
1
1
  import 'genkit';
2
2
  import 'openai';
3
- export { d as defineCompatOpenAIEmbedder } from './audio-Cr0WtG4I.mjs';
3
+ export { d as defineCompatOpenAIEmbedder } from './audio-CW-qdV9D.mjs';
4
4
  import 'genkit/model';
5
5
  import 'openai/core.mjs';
6
6
  import 'openai/resources/audio/index.mjs';
package/lib/embedder.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import 'genkit';
2
2
  import 'openai';
3
- export { d as defineCompatOpenAIEmbedder } from './audio-Cr0WtG4I.js';
3
+ export { d as defineCompatOpenAIEmbedder } from './audio-CW-qdV9D.js';
4
4
  import 'genkit/model';
5
5
  import 'openai/core.mjs';
6
6
  import 'openai/resources/audio/index.mjs';
package/lib/image.d.mts CHANGED
@@ -2,7 +2,7 @@ import 'genkit';
2
2
  import 'genkit/model';
3
3
  import 'openai';
4
4
  import 'openai/resources/images.mjs';
5
- export { b as IMAGE_GENERATION_MODEL_INFO, I as ImageGenerationCommonConfigSchema, a as ImageRequestBuilder, e as compatOaiImageModelRef, c as defineCompatOpenAIImageModel } from './audio-Cr0WtG4I.mjs';
5
+ export { b as IMAGE_GENERATION_MODEL_INFO, I as ImageGenerationCommonConfigSchema, a as ImageRequestBuilder, c as compatOaiImageModelRef, e as defineCompatOpenAIImageModel } from './audio-CW-qdV9D.mjs';
6
6
  import 'openai/core.mjs';
7
7
  import 'openai/resources/audio/index.mjs';
8
8
  import 'genkit/plugin';
package/lib/image.d.ts CHANGED
@@ -2,7 +2,7 @@ import 'genkit';
2
2
  import 'genkit/model';
3
3
  import 'openai';
4
4
  import 'openai/resources/images.mjs';
5
- export { b as IMAGE_GENERATION_MODEL_INFO, I as ImageGenerationCommonConfigSchema, a as ImageRequestBuilder, e as compatOaiImageModelRef, c as defineCompatOpenAIImageModel } from './audio-Cr0WtG4I.js';
5
+ export { b as IMAGE_GENERATION_MODEL_INFO, I as ImageGenerationCommonConfigSchema, a as ImageRequestBuilder, c as compatOaiImageModelRef, e as defineCompatOpenAIImageModel } from './audio-CW-qdV9D.js';
6
6
  import 'openai/core.mjs';
7
7
  import 'openai/resources/audio/index.mjs';
8
8
  import 'genkit/plugin';
package/lib/index.d.mts CHANGED
@@ -2,7 +2,7 @@ import 'genkit/plugin';
2
2
  import 'genkit';
3
3
  import 'genkit/registry';
4
4
  import 'openai';
5
- export { C as ChatCompletionCommonConfigSchema, I as ImageGenerationCommonConfigSchema, a as ImageRequestBuilder, M as ModelRequestBuilder, P as PluginOptions, S as SpeechConfigSchema, D as SpeechRequestBuilder, T as TranscriptionConfigSchema, E as TranscriptionRequestBuilder, r as TranslationConfigSchema, p as TranslationRequestBuilder, e as compatOaiImageModelRef, n as compatOaiModelRef, y as compatOaiSpeechModelRef, z as compatOaiTranscriptionModelRef, w as compatOaiTranslationModelRef, x as default, d as defineCompatOpenAIEmbedder, c as defineCompatOpenAIImageModel, m as defineCompatOpenAIModel, A as defineCompatOpenAISpeechModel, B as defineCompatOpenAITranscriptionModel, v as defineCompatOpenAITranslationModel, x as openAICompatible, o as openAIModelRunner } from './audio-Cr0WtG4I.mjs';
5
+ export { C as ChatCompletionCommonConfigSchema, I as ImageGenerationCommonConfigSchema, a as ImageRequestBuilder, M as ModelRequestBuilder, P as PluginOptions, S as SpeechConfigSchema, x as SpeechRequestBuilder, T as TranscriptionConfigSchema, y as TranscriptionRequestBuilder, q as TranslationConfigSchema, r as TranslationRequestBuilder, c as compatOaiImageModelRef, f as compatOaiModelRef, z as compatOaiSpeechModelRef, A as compatOaiTranscriptionModelRef, s as compatOaiTranslationModelRef, B as default, d as defineCompatOpenAIEmbedder, e as defineCompatOpenAIImageModel, g as defineCompatOpenAIModel, D as defineCompatOpenAISpeechModel, E as defineCompatOpenAITranscriptionModel, u as defineCompatOpenAITranslationModel, B as openAICompatible, o as openAIModelRunner } from './audio-CW-qdV9D.mjs';
6
6
  import 'genkit/model';
7
7
  import 'openai/core.mjs';
8
8
  import 'openai/resources/audio/index.mjs';
package/lib/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import 'genkit/plugin';
2
2
  import 'genkit';
3
3
  import 'genkit/registry';
4
4
  import 'openai';
5
- export { C as ChatCompletionCommonConfigSchema, I as ImageGenerationCommonConfigSchema, a as ImageRequestBuilder, M as ModelRequestBuilder, P as PluginOptions, S as SpeechConfigSchema, D as SpeechRequestBuilder, T as TranscriptionConfigSchema, E as TranscriptionRequestBuilder, r as TranslationConfigSchema, p as TranslationRequestBuilder, e as compatOaiImageModelRef, n as compatOaiModelRef, y as compatOaiSpeechModelRef, z as compatOaiTranscriptionModelRef, w as compatOaiTranslationModelRef, x as default, d as defineCompatOpenAIEmbedder, c as defineCompatOpenAIImageModel, m as defineCompatOpenAIModel, A as defineCompatOpenAISpeechModel, B as defineCompatOpenAITranscriptionModel, v as defineCompatOpenAITranslationModel, x as openAICompatible, o as openAIModelRunner } from './audio-Cr0WtG4I.js';
5
+ export { C as ChatCompletionCommonConfigSchema, I as ImageGenerationCommonConfigSchema, a as ImageRequestBuilder, M as ModelRequestBuilder, P as PluginOptions, S as SpeechConfigSchema, x as SpeechRequestBuilder, T as TranscriptionConfigSchema, y as TranscriptionRequestBuilder, q as TranslationConfigSchema, r as TranslationRequestBuilder, c as compatOaiImageModelRef, f as compatOaiModelRef, z as compatOaiSpeechModelRef, A as compatOaiTranscriptionModelRef, s as compatOaiTranslationModelRef, B as default, d as defineCompatOpenAIEmbedder, e as defineCompatOpenAIImageModel, g as defineCompatOpenAIModel, D as defineCompatOpenAISpeechModel, E as defineCompatOpenAITranscriptionModel, u as defineCompatOpenAITranslationModel, B as openAICompatible, o as openAIModelRunner } from './audio-CW-qdV9D.js';
6
6
  import 'genkit/model';
7
7
  import 'openai/core.mjs';
8
8
  import 'openai/resources/audio/index.mjs';
package/lib/model.d.mts CHANGED
@@ -2,7 +2,7 @@ import 'genkit';
2
2
  import 'genkit/model';
3
3
  import 'openai';
4
4
  import 'openai/resources/index.mjs';
5
- export { C as ChatCompletionCommonConfigSchema, M as ModelRequestBuilder, n as compatOaiModelRef, m as defineCompatOpenAIModel, j as fromOpenAIChoice, k as fromOpenAIChunkChoice, i as fromOpenAIToolCall, o as openAIModelRunner, h as toOpenAIMessages, l as toOpenAIRequestBody, t as toOpenAIRole, g as toOpenAITextAndMedia, f as toOpenAITool } from './audio-Cr0WtG4I.mjs';
5
+ export { C as ChatCompletionCommonConfigSchema, M as ModelRequestBuilder, f as compatOaiModelRef, g as defineCompatOpenAIModel, h as fromOpenAIChoice, i as fromOpenAIChunkChoice, j as fromOpenAIToolCall, o as openAIModelRunner, t as toOpenAIMessages, k as toOpenAIRequestBody, l as toOpenAIRole, m as toOpenAITextAndMedia, n as toOpenAITool } from './audio-CW-qdV9D.mjs';
6
6
  import 'openai/core.mjs';
7
7
  import 'openai/resources/audio/index.mjs';
8
8
  import 'genkit/plugin';
package/lib/model.d.ts CHANGED
@@ -2,7 +2,7 @@ import 'genkit';
2
2
  import 'genkit/model';
3
3
  import 'openai';
4
4
  import 'openai/resources/index.mjs';
5
- export { C as ChatCompletionCommonConfigSchema, M as ModelRequestBuilder, n as compatOaiModelRef, m as defineCompatOpenAIModel, j as fromOpenAIChoice, k as fromOpenAIChunkChoice, i as fromOpenAIToolCall, o as openAIModelRunner, h as toOpenAIMessages, l as toOpenAIRequestBody, t as toOpenAIRole, g as toOpenAITextAndMedia, f as toOpenAITool } from './audio-Cr0WtG4I.js';
5
+ export { C as ChatCompletionCommonConfigSchema, M as ModelRequestBuilder, f as compatOaiModelRef, g as defineCompatOpenAIModel, h as fromOpenAIChoice, i as fromOpenAIChunkChoice, j as fromOpenAIToolCall, o as openAIModelRunner, t as toOpenAIMessages, k as toOpenAIRequestBody, l as toOpenAIRole, m as toOpenAITextAndMedia, n as toOpenAITool } from './audio-CW-qdV9D.js';
6
6
  import 'openai/core.mjs';
7
7
  import 'openai/resources/audio/index.mjs';
8
8
  import 'genkit/plugin';
@@ -1,7 +1,7 @@
1
1
  import * as genkit from 'genkit';
2
2
  import { z } from 'genkit';
3
3
  import { ModelInfo } from 'genkit/model';
4
- import { a as ImageRequestBuilder } from '../audio-Cr0WtG4I.mjs';
4
+ import { a as ImageRequestBuilder } from '../audio-CW-qdV9D.mjs';
5
5
  import 'openai';
6
6
  import 'openai/core.mjs';
7
7
  import 'openai/resources/audio/index.mjs';
@@ -1,7 +1,7 @@
1
1
  import * as genkit from 'genkit';
2
2
  import { z } from 'genkit';
3
3
  import { ModelInfo } from 'genkit/model';
4
- import { a as ImageRequestBuilder } from '../audio-Cr0WtG4I.js';
4
+ import { a as ImageRequestBuilder } from '../audio-CW-qdV9D.js';
5
5
  import 'openai';
6
6
  import 'openai/core.mjs';
7
7
  import 'openai/resources/audio/index.mjs';
@@ -1,4 +1,4 @@
1
- import { z, EmbedderReference } from 'genkit';
1
+ import { EmbedderReference, z } from 'genkit';
2
2
 
3
3
  /**
4
4
  * Copyright 2024 The Fire Company
@@ -1,4 +1,4 @@
1
- import { z, EmbedderReference } from 'genkit';
1
+ import { EmbedderReference, z } from 'genkit';
2
2
 
3
3
  /**
4
4
  * Copyright 2024 The Fire Company
@@ -1,5 +1,5 @@
1
1
  import { z } from 'genkit';
2
- import { ModelInfo, ModelReference } from 'genkit/model';
2
+ import { ModelReference, ModelInfo } from 'genkit/model';
3
3
 
4
4
  /**
5
5
  * Copyright 2024 The Fire Company
@@ -1,5 +1,5 @@
1
1
  import { z } from 'genkit';
2
- import { ModelInfo, ModelReference } from 'genkit/model';
2
+ import { ModelReference, ModelInfo } from 'genkit/model';
3
3
 
4
4
  /**
5
5
  * Copyright 2024 The Fire Company
@@ -1,6 +1,6 @@
1
1
  import { z, ModelReference, EmbedderReference } from 'genkit';
2
2
  import { GenkitPluginV2 } from 'genkit/plugin';
3
- import { P as PluginOptions, I as ImageGenerationCommonConfigSchema, S as SpeechConfigSchema, T as TranscriptionConfigSchema } from '../audio-Cr0WtG4I.mjs';
3
+ import { P as PluginOptions, I as ImageGenerationCommonConfigSchema, S as SpeechConfigSchema, T as TranscriptionConfigSchema } from '../audio-CW-qdV9D.mjs';
4
4
  import { SUPPORTED_IMAGE_MODELS } from './dalle.mjs';
5
5
  import { SUPPORTED_EMBEDDING_MODELS, TextEmbeddingConfigSchema } from './embedder.mjs';
6
6
  import { SUPPORTED_GPT_MODELS, OpenAIChatCompletionConfigSchema } from './gpt.mjs';
@@ -1,6 +1,6 @@
1
1
  import { z, ModelReference, EmbedderReference } from 'genkit';
2
2
  import { GenkitPluginV2 } from 'genkit/plugin';
3
- import { P as PluginOptions, I as ImageGenerationCommonConfigSchema, S as SpeechConfigSchema, T as TranscriptionConfigSchema } from '../audio-Cr0WtG4I.js';
3
+ import { P as PluginOptions, I as ImageGenerationCommonConfigSchema, S as SpeechConfigSchema, T as TranscriptionConfigSchema } from '../audio-CW-qdV9D.js';
4
4
  import { SUPPORTED_IMAGE_MODELS } from './dalle.js';
5
5
  import { SUPPORTED_EMBEDDING_MODELS, TextEmbeddingConfigSchema } from './embedder.js';
6
6
  import { SUPPORTED_GPT_MODELS, OpenAIChatCompletionConfigSchema } from './gpt.js';
@@ -214,7 +214,7 @@ function openAIPlugin(options) {
214
214
  listActions
215
215
  });
216
216
  }
217
- const model = (name, config) => {
217
+ const model = ((name, config) => {
218
218
  if (name.includes("gpt-image-1") || name.includes("dall-e")) {
219
219
  return (0, import_dalle.openAIImageModelRef)({
220
220
  name,
@@ -243,15 +243,15 @@ const model = (name, config) => {
243
243
  name,
244
244
  config
245
245
  });
246
- };
247
- const embedder = (name, config) => {
246
+ });
247
+ const embedder = ((name, config) => {
248
248
  return (0, import_genkit.embedderRef)({
249
249
  name,
250
250
  config,
251
251
  configSchema: import_embedder2.TextEmbeddingConfigSchema,
252
252
  namespace: "openai"
253
253
  });
254
- };
254
+ });
255
255
  const openAI = Object.assign(openAIPlugin, {
256
256
  model,
257
257
  embedder
@@ -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 modelActionMetadata,\n ModelReference,\n z,\n} from 'genkit';\nimport { ResolvableAction, type GenkitPluginV2 } 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 {\n gptImage1RequestBuilder,\n openAIImageModelRef,\n SUPPORTED_IMAGE_MODELS,\n} 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 { openAITranscriptionModelRef, SUPPORTED_STT_MODELS } from './stt.js';\nimport { openAISpeechModelRef, SUPPORTED_TTS_MODELS } from './tts.js';\nimport {\n defineOpenAIWhisperModel,\n openAIWhisperModelRef,\n SUPPORTED_WHISPER_MODELS,\n WhisperConfigSchema,\n} from './whisper.js';\n\nexport type OpenAIPluginOptions = Omit<PluginOptions, 'name' | 'baseURL'>;\n\nconst UNSUPPORTED_MODEL_MATCHERS = ['babbage', 'davinci', 'codex'];\n\nfunction createResolver(pluginOptions: PluginOptions) {\n return async (client: OpenAI, actionType: ActionType, actionName: string) => {\n if (actionType === 'embedder') {\n return defineCompatOpenAIEmbedder({\n name: actionName,\n client,\n pluginOptions,\n });\n } else if (\n actionName.includes('gpt-image-1') ||\n actionName.includes('dall-e')\n ) {\n const modelRef = openAIImageModelRef({ name: actionName });\n return defineCompatOpenAIImageModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n });\n } else if (actionName.includes('tts')) {\n const modelRef = openAISpeechModelRef({ name: actionName });\n return defineCompatOpenAISpeechModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n });\n } else if (actionName.includes('whisper')) {\n const modelRef = openAIWhisperModelRef({ name: actionName });\n return defineOpenAIWhisperModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n });\n } else if (actionName.includes('transcribe')) {\n const modelRef = openAITranscriptionModelRef({\n name: actionName,\n });\n return defineCompatOpenAITranscriptionModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n });\n } else {\n const modelRef = openAIModelRef({ name: actionName });\n return defineCompatOpenAIModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n });\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: 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: 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: model.id });\n return modelActionMetadata({\n name: modelRef.name,\n info: modelRef.info,\n configSchema: modelRef.configSchema,\n });\n } else if (model.id.includes('whisper')) {\n const modelRef =\n SUPPORTED_WHISPER_MODELS[model.id] ??\n openAIWhisperModelRef({ name: model.id });\n return modelActionMetadata({\n name: modelRef.name,\n info: modelRef.info,\n configSchema: modelRef.configSchema,\n });\n } else if (model.id.includes('transcribe')) {\n const modelRef =\n SUPPORTED_STT_MODELS[model.id] ??\n openAITranscriptionModelRef({ name: 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] ?? openAIModelRef({ name: 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): GenkitPluginV2 {\n const pluginOptions = { name: 'openai', ...options };\n return openAICompatible({\n name: 'openai',\n ...options,\n initializer: async (client) => {\n const models = [] as ResolvableAction[];\n models.push(\n ...Object.values(SUPPORTED_GPT_MODELS).map((modelRef) =>\n defineCompatOpenAIModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n })\n )\n );\n models.push(\n ...Object.values(SUPPORTED_EMBEDDING_MODELS).map((embedderRef) =>\n defineCompatOpenAIEmbedder({\n name: embedderRef.name,\n client,\n pluginOptions,\n embedderRef,\n })\n )\n );\n models.push(\n ...Object.values(SUPPORTED_TTS_MODELS).map((modelRef) =>\n defineCompatOpenAISpeechModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n })\n )\n );\n models.push(\n ...Object.values(SUPPORTED_WHISPER_MODELS).map((modelRef) =>\n defineOpenAIWhisperModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n })\n )\n );\n models.push(\n ...Object.values(SUPPORTED_STT_MODELS).map((modelRef) =>\n defineCompatOpenAITranscriptionModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n })\n )\n );\n models.push(\n ...Object.values(SUPPORTED_IMAGE_MODELS).map((modelRef) =>\n defineCompatOpenAIImageModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n requestBuilder: modelRef.name.includes('gpt-image-1')\n ? gptImage1RequestBuilder\n : undefined,\n })\n )\n );\n return models;\n },\n resolver: createResolver(pluginOptions),\n listActions,\n });\n}\n\nexport type OpenAIPlugin = {\n (params?: OpenAIPluginOptions): GenkitPluginV2;\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: keyof typeof SUPPORTED_WHISPER_MODELS | (`whisper-${string}` & {}),\n config?: z.infer<typeof WhisperConfigSchema>\n ): ModelReference<typeof WhisperConfigSchema>;\n model(\n name: keyof typeof SUPPORTED_STT_MODELS | (`${string}-transcribe` & {}),\n config?: z.infer<typeof TranscriptionConfigSchema>\n ): ModelReference<typeof TranscriptionConfigSchema>;\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(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,\n config,\n });\n }\n if (name.includes('tts')) {\n return openAISpeechModelRef({\n name,\n config,\n });\n }\n if (name.includes('whisper')) {\n return openAIWhisperModelRef({\n name,\n config,\n });\n }\n if (name.includes('transcribe')) {\n return openAITranscriptionModelRef({\n name,\n config,\n });\n }\n return openAIModelRef({\n 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,\n config,\n configSchema: TextEmbeddingConfigSchema,\n namespace: 'openai',\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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBA,oBAQO;AAIP,mBAKO;AACP,sBAA2C;AAC3C,mBAGO;AACP,eAAgD;AAChD,mBAAwC;AACxC,mBAIO;AACP,IAAAA,mBAGO;AACP,iBAIO;AACP,iBAAkE;AAClE,iBAA2D;AAC3D,qBAKO;AAIP,MAAM,6BAA6B,CAAC,WAAW,WAAW,OAAO;AAEjE,SAAS,eAAe,eAA8B;AACpD,SAAO,OAAO,QAAgB,YAAwB,eAAuB;AAC3E,QAAI,eAAe,YAAY;AAC7B,iBAAO,4CAA2B;AAAA,QAChC,MAAM;AAAA,QACN;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH,WACE,WAAW,SAAS,aAAa,KACjC,WAAW,SAAS,QAAQ,GAC5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F,CAAC;AAAA,QACH;AAAA,MACF;AACA,aAAO;AAAA,QACL,GAAG,OAAO,OAAO,mCAAsB,EAAE;AAAA,UAAI,CAAC,iBAC5C,2CAA6B;AAAA,YAC3B,MAAM,SAAS;AAAA,YACf;AAAA,YACA;AAAA,YACA;AAAA,YACA,gBAAgB,SAAS,KAAK,SAAS,aAAa,IAChD,uCACA;AAAA,UACN,CAAC;AAAA,QACH;AAAA,MACF;AACA,aAAO;AAAA,IACT;AAAA,IACA,UAAU,eAAe,aAAa;AAAA,IACtC;AAAA,EACF,CAAC;AACH;AA2CA,MAAM,QAAS,CAAC,MAAc,WAA+C;AAC3E,MAAI,KAAK,SAAS,aAAa,KAAK,KAAK,SAAS,QAAQ,GAAG;AAC3D,eAAO,kCAAoB;AAAA,MACzB;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AACA,MAAI,KAAK,SAAS,KAAK,GAAG;AACxB,eAAO,iCAAqB;AAAA,MAC1B;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AACA,MAAI,KAAK,SAAS,SAAS,GAAG;AAC5B,eAAO,sCAAsB;AAAA,MAC3B;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AACA,MAAI,KAAK,SAAS,YAAY,GAAG;AAC/B,eAAO,wCAA4B;AAAA,MACjC;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AACA,aAAO,2BAAe;AAAA,IACpB;AAAA,IACA;AAAA,EACF,CAAC;AACH;AAEA,MAAM,WAAY,CAChB,MACA,WACoC;AACpC,aAAO,2BAAY;AAAA,IACjB;AAAA,IACA;AAAA,IACA,cAAc;AAAA,IACd,WAAW;AAAA,EACb,CAAC;AACH;AA+BO,MAAM,SAAuB,OAAO,OAAO,cAAc;AAAA,EAC9D;AAAA,EACA;AACF,CAAC;AAED,IAAO,iBAAQ;","names":["import_embedder","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 modelActionMetadata,\n ModelReference,\n z,\n} from 'genkit';\nimport { ResolvableAction, type GenkitPluginV2 } 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 {\n gptImage1RequestBuilder,\n openAIImageModelRef,\n SUPPORTED_IMAGE_MODELS,\n} 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 { openAITranscriptionModelRef, SUPPORTED_STT_MODELS } from './stt.js';\nimport { openAISpeechModelRef, SUPPORTED_TTS_MODELS } from './tts.js';\nimport {\n defineOpenAIWhisperModel,\n openAIWhisperModelRef,\n SUPPORTED_WHISPER_MODELS,\n WhisperConfigSchema,\n} from './whisper.js';\n\nexport type OpenAIPluginOptions = Omit<PluginOptions, 'name' | 'baseURL'>;\n\nconst UNSUPPORTED_MODEL_MATCHERS = ['babbage', 'davinci', 'codex'];\n\nfunction createResolver(pluginOptions: PluginOptions) {\n return async (client: OpenAI, actionType: ActionType, actionName: string) => {\n if (actionType === 'embedder') {\n return defineCompatOpenAIEmbedder({\n name: actionName,\n client,\n pluginOptions,\n });\n } else if (\n actionName.includes('gpt-image-1') ||\n actionName.includes('dall-e')\n ) {\n const modelRef = openAIImageModelRef({ name: actionName });\n return defineCompatOpenAIImageModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n });\n } else if (actionName.includes('tts')) {\n const modelRef = openAISpeechModelRef({ name: actionName });\n return defineCompatOpenAISpeechModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n });\n } else if (actionName.includes('whisper')) {\n const modelRef = openAIWhisperModelRef({ name: actionName });\n return defineOpenAIWhisperModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n });\n } else if (actionName.includes('transcribe')) {\n const modelRef = openAITranscriptionModelRef({\n name: actionName,\n });\n return defineCompatOpenAITranscriptionModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n });\n } else {\n const modelRef = openAIModelRef({ name: actionName });\n return defineCompatOpenAIModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n });\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: 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: 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: model.id });\n return modelActionMetadata({\n name: modelRef.name,\n info: modelRef.info,\n configSchema: modelRef.configSchema,\n });\n } else if (model.id.includes('whisper')) {\n const modelRef =\n SUPPORTED_WHISPER_MODELS[model.id] ??\n openAIWhisperModelRef({ name: model.id });\n return modelActionMetadata({\n name: modelRef.name,\n info: modelRef.info,\n configSchema: modelRef.configSchema,\n });\n } else if (model.id.includes('transcribe')) {\n const modelRef =\n SUPPORTED_STT_MODELS[model.id] ??\n openAITranscriptionModelRef({ name: 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] ?? openAIModelRef({ name: 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): GenkitPluginV2 {\n const pluginOptions = { name: 'openai', ...options };\n return openAICompatible({\n name: 'openai',\n ...options,\n initializer: async (client) => {\n const models = [] as ResolvableAction[];\n models.push(\n ...Object.values(SUPPORTED_GPT_MODELS).map((modelRef) =>\n defineCompatOpenAIModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n })\n )\n );\n models.push(\n ...Object.values(SUPPORTED_EMBEDDING_MODELS).map((embedderRef) =>\n defineCompatOpenAIEmbedder({\n name: embedderRef.name,\n client,\n pluginOptions,\n embedderRef,\n })\n )\n );\n models.push(\n ...Object.values(SUPPORTED_TTS_MODELS).map((modelRef) =>\n defineCompatOpenAISpeechModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n })\n )\n );\n models.push(\n ...Object.values(SUPPORTED_WHISPER_MODELS).map((modelRef) =>\n defineOpenAIWhisperModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n })\n )\n );\n models.push(\n ...Object.values(SUPPORTED_STT_MODELS).map((modelRef) =>\n defineCompatOpenAITranscriptionModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n })\n )\n );\n models.push(\n ...Object.values(SUPPORTED_IMAGE_MODELS).map((modelRef) =>\n defineCompatOpenAIImageModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n requestBuilder: modelRef.name.includes('gpt-image-1')\n ? gptImage1RequestBuilder\n : undefined,\n })\n )\n );\n return models;\n },\n resolver: createResolver(pluginOptions),\n listActions,\n });\n}\n\nexport type OpenAIPlugin = {\n (params?: OpenAIPluginOptions): GenkitPluginV2;\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: keyof typeof SUPPORTED_WHISPER_MODELS | (`whisper-${string}` & {}),\n config?: z.infer<typeof WhisperConfigSchema>\n ): ModelReference<typeof WhisperConfigSchema>;\n model(\n name: keyof typeof SUPPORTED_STT_MODELS | (`${string}-transcribe` & {}),\n config?: z.infer<typeof TranscriptionConfigSchema>\n ): ModelReference<typeof TranscriptionConfigSchema>;\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(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,\n config,\n });\n }\n if (name.includes('tts')) {\n return openAISpeechModelRef({\n name,\n config,\n });\n }\n if (name.includes('whisper')) {\n return openAIWhisperModelRef({\n name,\n config,\n });\n }\n if (name.includes('transcribe')) {\n return openAITranscriptionModelRef({\n name,\n config,\n });\n }\n return openAIModelRef({\n 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,\n config,\n configSchema: TextEmbeddingConfigSchema,\n namespace: 'openai',\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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBA,oBAQO;AAIP,mBAKO;AACP,sBAA2C;AAC3C,mBAGO;AACP,eAAgD;AAChD,mBAAwC;AACxC,mBAIO;AACP,IAAAA,mBAGO;AACP,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AAC;AACH;AAEA,MAAM,YAAY,CAChB,MACA,WACoC;AACpC,aAAO,2BAAY;AAAA,IACjB;AAAA,IACA;AAAA,IACA,cAAc;AAAA,IACd,WAAW;AAAA,EACb,CAAC;AACH;AA+BO,MAAM,SAAuB,OAAO,OAAO,cAAc;AAAA,EAC9D;AAAA,EACA;AACF,CAAC;AAED,IAAO,iBAAQ;","names":["import_embedder","model","embedderRef"]}
@@ -212,7 +212,7 @@ function openAIPlugin(options) {
212
212
  listActions
213
213
  });
214
214
  }
215
- const model = (name, config) => {
215
+ const model = ((name, config) => {
216
216
  if (name.includes("gpt-image-1") || name.includes("dall-e")) {
217
217
  return openAIImageModelRef({
218
218
  name,
@@ -241,15 +241,15 @@ const model = (name, config) => {
241
241
  name,
242
242
  config
243
243
  });
244
- };
245
- const embedder = (name, config) => {
244
+ });
245
+ const embedder = ((name, config) => {
246
246
  return embedderRef({
247
247
  name,
248
248
  config,
249
249
  configSchema: TextEmbeddingConfigSchema,
250
250
  namespace: "openai"
251
251
  });
252
- };
252
+ });
253
253
  const openAI = Object.assign(openAIPlugin, {
254
254
  model,
255
255
  embedder
@@ -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 modelActionMetadata,\n ModelReference,\n z,\n} from 'genkit';\nimport { ResolvableAction, type GenkitPluginV2 } 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 {\n gptImage1RequestBuilder,\n openAIImageModelRef,\n SUPPORTED_IMAGE_MODELS,\n} 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 { openAITranscriptionModelRef, SUPPORTED_STT_MODELS } from './stt.js';\nimport { openAISpeechModelRef, SUPPORTED_TTS_MODELS } from './tts.js';\nimport {\n defineOpenAIWhisperModel,\n openAIWhisperModelRef,\n SUPPORTED_WHISPER_MODELS,\n WhisperConfigSchema,\n} from './whisper.js';\n\nexport type OpenAIPluginOptions = Omit<PluginOptions, 'name' | 'baseURL'>;\n\nconst UNSUPPORTED_MODEL_MATCHERS = ['babbage', 'davinci', 'codex'];\n\nfunction createResolver(pluginOptions: PluginOptions) {\n return async (client: OpenAI, actionType: ActionType, actionName: string) => {\n if (actionType === 'embedder') {\n return defineCompatOpenAIEmbedder({\n name: actionName,\n client,\n pluginOptions,\n });\n } else if (\n actionName.includes('gpt-image-1') ||\n actionName.includes('dall-e')\n ) {\n const modelRef = openAIImageModelRef({ name: actionName });\n return defineCompatOpenAIImageModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n });\n } else if (actionName.includes('tts')) {\n const modelRef = openAISpeechModelRef({ name: actionName });\n return defineCompatOpenAISpeechModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n });\n } else if (actionName.includes('whisper')) {\n const modelRef = openAIWhisperModelRef({ name: actionName });\n return defineOpenAIWhisperModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n });\n } else if (actionName.includes('transcribe')) {\n const modelRef = openAITranscriptionModelRef({\n name: actionName,\n });\n return defineCompatOpenAITranscriptionModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n });\n } else {\n const modelRef = openAIModelRef({ name: actionName });\n return defineCompatOpenAIModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n });\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: 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: 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: model.id });\n return modelActionMetadata({\n name: modelRef.name,\n info: modelRef.info,\n configSchema: modelRef.configSchema,\n });\n } else if (model.id.includes('whisper')) {\n const modelRef =\n SUPPORTED_WHISPER_MODELS[model.id] ??\n openAIWhisperModelRef({ name: model.id });\n return modelActionMetadata({\n name: modelRef.name,\n info: modelRef.info,\n configSchema: modelRef.configSchema,\n });\n } else if (model.id.includes('transcribe')) {\n const modelRef =\n SUPPORTED_STT_MODELS[model.id] ??\n openAITranscriptionModelRef({ name: 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] ?? openAIModelRef({ name: 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): GenkitPluginV2 {\n const pluginOptions = { name: 'openai', ...options };\n return openAICompatible({\n name: 'openai',\n ...options,\n initializer: async (client) => {\n const models = [] as ResolvableAction[];\n models.push(\n ...Object.values(SUPPORTED_GPT_MODELS).map((modelRef) =>\n defineCompatOpenAIModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n })\n )\n );\n models.push(\n ...Object.values(SUPPORTED_EMBEDDING_MODELS).map((embedderRef) =>\n defineCompatOpenAIEmbedder({\n name: embedderRef.name,\n client,\n pluginOptions,\n embedderRef,\n })\n )\n );\n models.push(\n ...Object.values(SUPPORTED_TTS_MODELS).map((modelRef) =>\n defineCompatOpenAISpeechModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n })\n )\n );\n models.push(\n ...Object.values(SUPPORTED_WHISPER_MODELS).map((modelRef) =>\n defineOpenAIWhisperModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n })\n )\n );\n models.push(\n ...Object.values(SUPPORTED_STT_MODELS).map((modelRef) =>\n defineCompatOpenAITranscriptionModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n })\n )\n );\n models.push(\n ...Object.values(SUPPORTED_IMAGE_MODELS).map((modelRef) =>\n defineCompatOpenAIImageModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n requestBuilder: modelRef.name.includes('gpt-image-1')\n ? gptImage1RequestBuilder\n : undefined,\n })\n )\n );\n return models;\n },\n resolver: createResolver(pluginOptions),\n listActions,\n });\n}\n\nexport type OpenAIPlugin = {\n (params?: OpenAIPluginOptions): GenkitPluginV2;\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: keyof typeof SUPPORTED_WHISPER_MODELS | (`whisper-${string}` & {}),\n config?: z.infer<typeof WhisperConfigSchema>\n ): ModelReference<typeof WhisperConfigSchema>;\n model(\n name: keyof typeof SUPPORTED_STT_MODELS | (`${string}-transcribe` & {}),\n config?: z.infer<typeof TranscriptionConfigSchema>\n ): ModelReference<typeof TranscriptionConfigSchema>;\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(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,\n config,\n });\n }\n if (name.includes('tts')) {\n return openAISpeechModelRef({\n name,\n config,\n });\n }\n if (name.includes('whisper')) {\n return openAIWhisperModelRef({\n name,\n config,\n });\n }\n if (name.includes('transcribe')) {\n return openAITranscriptionModelRef({\n name,\n config,\n });\n }\n return openAIModelRef({\n 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,\n config,\n configSchema: TextEmbeddingConfigSchema,\n namespace: 'openai',\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,EAEA;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;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP;AAAA,EAEE;AAAA,EACA;AAAA,OACK;AACP,SAAS,6BAA6B,4BAA4B;AAClE,SAAS,sBAAsB,4BAA4B;AAC3D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAIP,MAAM,6BAA6B,CAAC,WAAW,WAAW,OAAO;AAEjE,SAAS,eAAe,eAA8B;AACpD,SAAO,OAAO,QAAgB,YAAwB,eAAuB;AAC3E,QAAI,eAAe,YAAY;AAC7B,aAAO,2BAA2B;AAAA,QAChC,MAAM;AAAA,QACN;AAAA,QACA;AAAA,MACF,CAAC;AA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AAAA,YACf;AAAA,YACA;AAAA,YACA;AAAA,UACF,CAAC;AAAA,QACH;AAAA,MACF;AACA,aAAO;AAAA,QACL,GAAG,OAAO,OAAO,sBAAsB,EAAE;AAAA,UAAI,CAAC,aAC5C,6BAA6B;AAAA,YAC3B,MAAM,SAAS;AAAA,YACf;AAAA,YACA;AAAA,YACA;AAAA,YACA,gBAAgB,SAAS,KAAK,SAAS,aAAa,IAChD,0BACA;AAAA,UACN,CAAC;AAAA,QACH;AAAA,MACF;AACA,aAAO;AAAA,IACT;AAAA,IACA,UAAU,eAAe,aAAa;AAAA,IACtC;AAAA,EACF,CAAC;AACH;AA2CA,MAAM,QAAS,CAAC,MAAc,WAA+C;AAC3E,MAAI,KAAK,SAAS,aAAa,KAAK,KAAK,SAAS,QAAQ,GAAG;AAC3D,WAAO,oBAAoB;AAAA,MACzB;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AACA,MAAI,KAAK,SAAS,KAAK,GAAG;AACxB,WAAO,qBAAqB;AAAA,MAC1B;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AACA,MAAI,KAAK,SAAS,SAAS,GAAG;AAC5B,WAAO,sBAAsB;AAAA,MAC3B;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AACA,MAAI,KAAK,SAAS,YAAY,GAAG;AAC/B,WAAO,4BAA4B;AAAA,MACjC;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AACA,SAAO,eAAe;AAAA,IACpB;AAAA,IACA;AAAA,EACF,CAAC;AACH;AAEA,MAAM,WAAY,CAChB,MACA,WACoC;AACpC,SAAO,YAAY;AAAA,IACjB;AAAA,IACA;AAAA,IACA,cAAc;AAAA,IACd,WAAW;AAAA,EACb,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 modelActionMetadata,\n ModelReference,\n z,\n} from 'genkit';\nimport { ResolvableAction, type GenkitPluginV2 } 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 {\n gptImage1RequestBuilder,\n openAIImageModelRef,\n SUPPORTED_IMAGE_MODELS,\n} 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 { openAITranscriptionModelRef, SUPPORTED_STT_MODELS } from './stt.js';\nimport { openAISpeechModelRef, SUPPORTED_TTS_MODELS } from './tts.js';\nimport {\n defineOpenAIWhisperModel,\n openAIWhisperModelRef,\n SUPPORTED_WHISPER_MODELS,\n WhisperConfigSchema,\n} from './whisper.js';\n\nexport type OpenAIPluginOptions = Omit<PluginOptions, 'name' | 'baseURL'>;\n\nconst UNSUPPORTED_MODEL_MATCHERS = ['babbage', 'davinci', 'codex'];\n\nfunction createResolver(pluginOptions: PluginOptions) {\n return async (client: OpenAI, actionType: ActionType, actionName: string) => {\n if (actionType === 'embedder') {\n return defineCompatOpenAIEmbedder({\n name: actionName,\n client,\n pluginOptions,\n });\n } else if (\n actionName.includes('gpt-image-1') ||\n actionName.includes('dall-e')\n ) {\n const modelRef = openAIImageModelRef({ name: actionName });\n return defineCompatOpenAIImageModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n });\n } else if (actionName.includes('tts')) {\n const modelRef = openAISpeechModelRef({ name: actionName });\n return defineCompatOpenAISpeechModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n });\n } else if (actionName.includes('whisper')) {\n const modelRef = openAIWhisperModelRef({ name: actionName });\n return defineOpenAIWhisperModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n });\n } else if (actionName.includes('transcribe')) {\n const modelRef = openAITranscriptionModelRef({\n name: actionName,\n });\n return defineCompatOpenAITranscriptionModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n });\n } else {\n const modelRef = openAIModelRef({ name: actionName });\n return defineCompatOpenAIModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n });\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: 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: 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: model.id });\n return modelActionMetadata({\n name: modelRef.name,\n info: modelRef.info,\n configSchema: modelRef.configSchema,\n });\n } else if (model.id.includes('whisper')) {\n const modelRef =\n SUPPORTED_WHISPER_MODELS[model.id] ??\n openAIWhisperModelRef({ name: model.id });\n return modelActionMetadata({\n name: modelRef.name,\n info: modelRef.info,\n configSchema: modelRef.configSchema,\n });\n } else if (model.id.includes('transcribe')) {\n const modelRef =\n SUPPORTED_STT_MODELS[model.id] ??\n openAITranscriptionModelRef({ name: 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] ?? openAIModelRef({ name: 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): GenkitPluginV2 {\n const pluginOptions = { name: 'openai', ...options };\n return openAICompatible({\n name: 'openai',\n ...options,\n initializer: async (client) => {\n const models = [] as ResolvableAction[];\n models.push(\n ...Object.values(SUPPORTED_GPT_MODELS).map((modelRef) =>\n defineCompatOpenAIModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n })\n )\n );\n models.push(\n ...Object.values(SUPPORTED_EMBEDDING_MODELS).map((embedderRef) =>\n defineCompatOpenAIEmbedder({\n name: embedderRef.name,\n client,\n pluginOptions,\n embedderRef,\n })\n )\n );\n models.push(\n ...Object.values(SUPPORTED_TTS_MODELS).map((modelRef) =>\n defineCompatOpenAISpeechModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n })\n )\n );\n models.push(\n ...Object.values(SUPPORTED_WHISPER_MODELS).map((modelRef) =>\n defineOpenAIWhisperModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n })\n )\n );\n models.push(\n ...Object.values(SUPPORTED_STT_MODELS).map((modelRef) =>\n defineCompatOpenAITranscriptionModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n })\n )\n );\n models.push(\n ...Object.values(SUPPORTED_IMAGE_MODELS).map((modelRef) =>\n defineCompatOpenAIImageModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n requestBuilder: modelRef.name.includes('gpt-image-1')\n ? gptImage1RequestBuilder\n : undefined,\n })\n )\n );\n return models;\n },\n resolver: createResolver(pluginOptions),\n listActions,\n });\n}\n\nexport type OpenAIPlugin = {\n (params?: OpenAIPluginOptions): GenkitPluginV2;\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: keyof typeof SUPPORTED_WHISPER_MODELS | (`whisper-${string}` & {}),\n config?: z.infer<typeof WhisperConfigSchema>\n ): ModelReference<typeof WhisperConfigSchema>;\n model(\n name: keyof typeof SUPPORTED_STT_MODELS | (`${string}-transcribe` & {}),\n config?: z.infer<typeof TranscriptionConfigSchema>\n ): ModelReference<typeof TranscriptionConfigSchema>;\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(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,\n config,\n });\n }\n if (name.includes('tts')) {\n return openAISpeechModelRef({\n name,\n config,\n });\n }\n if (name.includes('whisper')) {\n return openAIWhisperModelRef({\n name,\n config,\n });\n }\n if (name.includes('transcribe')) {\n return openAITranscriptionModelRef({\n name,\n config,\n });\n }\n return openAIModelRef({\n 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,\n config,\n configSchema: TextEmbeddingConfigSchema,\n namespace: 'openai',\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,EAEA;AAAA,OAGK;AAIP;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AACP,SAAS,kCAAkC;AAC3C;AAAA,EACE;AAAA,OAEK;AACP,SAA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MACA;AAAA,IACF,CAAC;AAAA,EACH;AACA,MAAI,KAAK,SAAS,YAAY,GAAG;AAC/B,WAAO,4BAA4B;AAAA,MACjC;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AACA,SAAO,eAAe;AAAA,IACpB;AAAA,IACA;AAAA,EACF,CAAC;AACH;AAEA,MAAM,YAAY,CAChB,MACA,WACoC;AACpC,SAAO,YAAY;AAAA,IACjB;AAAA,IACA;AAAA,IACA,cAAc;AAAA,IACd,WAAW;AAAA,EACb,CAAC;AACH;AA+BO,MAAM,SAAuB,OAAO,OAAO,cAAc;AAAA,EAC9D;AAAA,EACA;AACF,CAAC;AAED,IAAO,iBAAQ;","names":["model","embedderRef"]}
@@ -1,7 +1,7 @@
1
1
  import { ModelReference, z } from 'genkit';
2
2
  import { ModelInfo, ModelAction } from 'genkit/model';
3
3
  import OpenAI from 'openai';
4
- import { P as PluginOptions } from '../audio-Cr0WtG4I.mjs';
4
+ import { P as PluginOptions } from '../audio-CW-qdV9D.mjs';
5
5
  import 'openai/core.mjs';
6
6
  import 'openai/resources/audio/index.mjs';
7
7
  import 'genkit/plugin';
@@ -1,7 +1,7 @@
1
1
  import { ModelReference, z } from 'genkit';
2
2
  import { ModelInfo, ModelAction } from 'genkit/model';
3
3
  import OpenAI from 'openai';
4
- import { P as PluginOptions } from '../audio-Cr0WtG4I.js';
4
+ import { P as PluginOptions } from '../audio-CW-qdV9D.js';
5
5
  import 'openai/core.mjs';
6
6
  import 'openai/resources/audio/index.mjs';
7
7
  import 'genkit/plugin';
@@ -2,7 +2,7 @@ import 'genkit';
2
2
  import 'genkit/model';
3
3
  import 'openai';
4
4
  import 'openai/resources/audio/index.mjs';
5
- export { q as TRANSLATION_MODEL_INFO, r as TranslationConfigSchema, p as TranslationRequestBuilder, w as compatOaiTranslationModelRef, v as defineCompatOpenAITranslationModel, s as toTranslationRequest, u as translationToGenerateResponse } from './audio-Cr0WtG4I.mjs';
5
+ export { p as TRANSLATION_MODEL_INFO, q as TranslationConfigSchema, r as TranslationRequestBuilder, s as compatOaiTranslationModelRef, u as defineCompatOpenAITranslationModel, v as toTranslationRequest, w as translationToGenerateResponse } from './audio-CW-qdV9D.mjs';
6
6
  import 'openai/core.mjs';
7
7
  import 'genkit/plugin';
8
8
  import 'genkit/registry';
@@ -2,7 +2,7 @@ import 'genkit';
2
2
  import 'genkit/model';
3
3
  import 'openai';
4
4
  import 'openai/resources/audio/index.mjs';
5
- export { q as TRANSLATION_MODEL_INFO, r as TranslationConfigSchema, p as TranslationRequestBuilder, w as compatOaiTranslationModelRef, v as defineCompatOpenAITranslationModel, s as toTranslationRequest, u as translationToGenerateResponse } from './audio-Cr0WtG4I.js';
5
+ export { p as TRANSLATION_MODEL_INFO, q as TranslationConfigSchema, r as TranslationRequestBuilder, s as compatOaiTranslationModelRef, u as defineCompatOpenAITranslationModel, v as toTranslationRequest, w as translationToGenerateResponse } from './audio-CW-qdV9D.js';
6
6
  import 'openai/core.mjs';
7
7
  import 'genkit/plugin';
8
8
  import 'genkit/registry';
package/lib/utils.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { GenerateRequest } from 'genkit';
2
2
  import { EmbedRequest } from 'genkit/embedder';
3
3
  import OpenAI from 'openai';
4
- import { P as PluginOptions } from './audio-Cr0WtG4I.mjs';
4
+ import { P as PluginOptions } from './audio-CW-qdV9D.mjs';
5
5
  import 'genkit/model';
6
6
  import 'openai/core.mjs';
7
7
  import 'openai/resources/audio/index.mjs';
package/lib/utils.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { GenerateRequest } from 'genkit';
2
2
  import { EmbedRequest } from 'genkit/embedder';
3
3
  import OpenAI from 'openai';
4
- import { P as PluginOptions } from './audio-Cr0WtG4I.js';
4
+ import { P as PluginOptions } from './audio-CW-qdV9D.js';
5
5
  import 'genkit/model';
6
6
  import 'openai/core.mjs';
7
7
  import 'openai/resources/audio/index.mjs';
@@ -1,6 +1,6 @@
1
1
  import { z } from 'genkit';
2
- import { ModelInfo, ModelReference } from 'genkit/model';
3
- import { M as ModelRequestBuilder } from '../audio-Cr0WtG4I.mjs';
2
+ import { ModelReference, ModelInfo } from 'genkit/model';
3
+ import { M as ModelRequestBuilder } from '../audio-CW-qdV9D.mjs';
4
4
  import 'openai';
5
5
  import 'openai/core.mjs';
6
6
  import 'openai/resources/audio/index.mjs';
package/lib/xai/grok.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { z } from 'genkit';
2
- import { ModelInfo, ModelReference } from 'genkit/model';
3
- import { M as ModelRequestBuilder } from '../audio-Cr0WtG4I.js';
2
+ import { ModelReference, ModelInfo } from 'genkit/model';
3
+ import { M as ModelRequestBuilder } from '../audio-CW-qdV9D.js';
4
4
  import 'openai';
5
5
  import 'openai/core.mjs';
6
6
  import 'openai/resources/audio/index.mjs';
@@ -1,6 +1,6 @@
1
1
  import { z, ModelReference } from 'genkit';
2
2
  import { GenkitPluginV2 } from 'genkit/plugin';
3
- import { P as PluginOptions, I as ImageGenerationCommonConfigSchema } from '../audio-Cr0WtG4I.mjs';
3
+ import { P as PluginOptions, I as ImageGenerationCommonConfigSchema } from '../audio-CW-qdV9D.mjs';
4
4
  import { SUPPORTED_IMAGE_MODELS } from './grok-image.mjs';
5
5
  import { SUPPORTED_LANGUAGE_MODELS, XaiChatCompletionConfigSchema } from './grok.mjs';
6
6
  import 'genkit/model';
@@ -1,6 +1,6 @@
1
1
  import { z, ModelReference } from 'genkit';
2
2
  import { GenkitPluginV2 } from 'genkit/plugin';
3
- import { P as PluginOptions, I as ImageGenerationCommonConfigSchema } from '../audio-Cr0WtG4I.js';
3
+ import { P as PluginOptions, I as ImageGenerationCommonConfigSchema } from '../audio-CW-qdV9D.js';
4
4
  import { SUPPORTED_IMAGE_MODELS } from './grok-image.js';
5
5
  import { SUPPORTED_LANGUAGE_MODELS, XaiChatCompletionConfigSchema } from './grok.js';
6
6
  import 'genkit/model';
package/lib/xai/index.js CHANGED
@@ -111,7 +111,7 @@ function xAIPlugin(options) {
111
111
  listActions
112
112
  });
113
113
  }
114
- const model = (name, config) => {
114
+ const model = ((name, config) => {
115
115
  if (name.includes("image")) {
116
116
  return (0, import_grok_image.xaiImageModelRef)({
117
117
  name,
@@ -122,7 +122,7 @@ const model = (name, config) => {
122
122
  name,
123
123
  config
124
124
  });
125
- };
125
+ });
126
126
  const xAI = Object.assign(xAIPlugin, {
127
127
  model
128
128
  });
@@ -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 GenkitError,\n modelActionMetadata,\n ModelReference,\n z,\n} from 'genkit';\nimport { logger } from 'genkit/logging';\nimport { ResolvableAction, type GenkitPluginV2 } 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\nfunction createResolver(pluginOptions: PluginOptions) {\n return async (client: OpenAI, actionType: ActionType, actionName: string) => {\n if (actionType === 'model') {\n const modelRef = xaiModelRef({ name: actionName });\n return defineCompatOpenAIModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n requestBuilder: grokRequestBuilder,\n });\n } else {\n logger.warn('Only model actions are supported by the XAI plugin');\n }\n return undefined;\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: 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: 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): GenkitPluginV2 {\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 const pluginOptions = { name: 'xai', ...options };\n return openAICompatible({\n name: 'xai',\n baseURL: 'https://api.x.ai/v1',\n apiKey,\n ...options,\n initializer: async (client) => {\n const models = [] as ResolvableAction[];\n models.push(\n ...Object.values(SUPPORTED_LANGUAGE_MODELS).map((modelRef) =>\n defineCompatOpenAIModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n requestBuilder: grokRequestBuilder,\n })\n )\n );\n models.push(\n ...Object.values(SUPPORTED_IMAGE_MODELS).map((modelRef) =>\n defineCompatOpenAIImageModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n })\n )\n );\n return models;\n },\n resolver: createResolver(pluginOptions),\n listActions,\n });\n}\n\nexport type XAIPlugin = {\n (params?: XAIPluginOptions): GenkitPluginV2;\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,\n config,\n });\n }\n return xaiModelRef({\n 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,oBAMO;AACP,qBAAuB;AAIvB,mBAGO;AACP,eAAgD;AAChD,mBAAwC;AACxC,wBAAyD;AACzD,kBAKO;AAIP,SAAS,eAAe,eAA8B;AACpD,SAAO,OAAO,QAAgB,YAAwB,eAAuB;AAC3E,QAAI,eAAe,SAAS;AAC1B,YAAM,eAAW,yBAAY,EAAE,MAAM,WAAW,CAAC;AACjD,iBAAO,sCAAwB;AAAA,QAC7B,MAAM,SAAS;AAAA,QACf;AAAA,QACA;AAAA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AC,iBAC/C,sCAAwB;AAAA,YACtB,MAAM,SAAS;AAAA,YACf;AAAA,YACA;AAAA,YACA;AAAA,YACA,gBAAgB;AAAA,UAClB,CAAC;AAAA,QACH;AAAA,MACF;AACA,aAAO;AAAA,QACL,GAAG,OAAO,OAAO,wCAAsB,EAAE;AAAA,UAAI,CAAC,iBAC5C,2CAA6B;AAAA,YAC3B,MAAM,SAAS;AAAA,YACf;AAAA,YACA;AAAA,YACA;AAAA,UACF,CAAC;AAAA,QACH;AAAA,MACF;AACA,aAAO;AAAA,IACT;AAAA,IACA,UAAU,eAAe,aAAa;AAAA,IACtC;AAAA,EACF,CAAC;AACH;AAeA,MAAM,QAAS,CAAC,MAAc,WAA+C;AAC3E,MAAI,KAAK,SAAS,OAAO,GAAG;AAC1B,eAAO,oCAAiB;AAAA,MACtB;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AACA,aAAO,yBAAY;AAAA,IACjB;AAAA,IACA;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 GenkitError,\n modelActionMetadata,\n ModelReference,\n z,\n} from 'genkit';\nimport { logger } from 'genkit/logging';\nimport { ResolvableAction, type GenkitPluginV2 } 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\nfunction createResolver(pluginOptions: PluginOptions) {\n return async (client: OpenAI, actionType: ActionType, actionName: string) => {\n if (actionType === 'model') {\n const modelRef = xaiModelRef({ name: actionName });\n return defineCompatOpenAIModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n requestBuilder: grokRequestBuilder,\n });\n } else {\n logger.warn('Only model actions are supported by the XAI plugin');\n }\n return undefined;\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: 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: 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): GenkitPluginV2 {\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 const pluginOptions = { name: 'xai', ...options };\n return openAICompatible({\n name: 'xai',\n baseURL: 'https://api.x.ai/v1',\n apiKey,\n ...options,\n initializer: async (client) => {\n const models = [] as ResolvableAction[];\n models.push(\n ...Object.values(SUPPORTED_LANGUAGE_MODELS).map((modelRef) =>\n defineCompatOpenAIModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n requestBuilder: grokRequestBuilder,\n })\n )\n );\n models.push(\n ...Object.values(SUPPORTED_IMAGE_MODELS).map((modelRef) =>\n defineCompatOpenAIImageModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n })\n )\n );\n return models;\n },\n resolver: createResolver(pluginOptions),\n listActions,\n });\n}\n\nexport type XAIPlugin = {\n (params?: XAIPluginOptions): GenkitPluginV2;\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,\n config,\n });\n }\n return xaiModelRef({\n 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 x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EO,SAAS,UAAU,SAA4C;AACpE,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,QAAM,gBAAgB,EAAE,MAAM,OAAO,GAAG,QAAQ;AAChD,aAAO,2BAAiB;AAAA,IACtB,MAAM;AAAA,IACN,SAAS;AAAA,IACT;AAAA,IACA,GAAG;AAAA,IACH,aAAa,OAAO,WAAW;AAC7B,YAAM,SAAS,CAAC;AAChB,aAAO;AAAA,QACL,GAAG,OAAO,OAAO,qCAAyB,EAAE;AAAA,UAAI,CAAC,iBAC/C,sCAAwB;AAAA,YACtB,MAAM,SAAS;AAAA,YACf;AAAA,YACA;AAAA,YACA;AAAA,YACA,gBAAgB;AAAA,UAClB,CAAC;AAAA,QACH;AAAA,MACF;AACA,aAAO;AAAA,QACL,GAAG,OAAO,OAAO,wCAAsB,EAAE;AAAA,UAAI,CAAC,iBAC5C,2CAA6B;AAAA,YAC3B,MAAM,SAAS;AAAA,YACf;AAAA,YACA;AAAA,YACA;AAAA,UACF,CAAC;AAAA,QACH;AAAA,MACF;AACA,aAAO;AAAA,IACT;AAAA,IACA,UAAU,eAAe,aAAa;AAAA,IACtC;AAAA,EACF,CAAC;AACH;AAeA,MAAM,SAAS,CAAC,MAAc,WAA+C;AAC3E,MAAI,KAAK,SAAS,OAAO,GAAG;AAC1B,eAAO,oCAAiB;AAAA,MACtB;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AACA,aAAO,yBAAY;AAAA,IACjB;AAAA,IACA;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
@@ -95,7 +95,7 @@ function xAIPlugin(options) {
95
95
  listActions
96
96
  });
97
97
  }
98
- const model = (name, config) => {
98
+ const model = ((name, config) => {
99
99
  if (name.includes("image")) {
100
100
  return xaiImageModelRef({
101
101
  name,
@@ -106,7 +106,7 @@ const model = (name, config) => {
106
106
  name,
107
107
  config
108
108
  });
109
- };
109
+ });
110
110
  const xAI = Object.assign(xAIPlugin, {
111
111
  model
112
112
  });
@@ -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 GenkitError,\n modelActionMetadata,\n ModelReference,\n z,\n} from 'genkit';\nimport { logger } from 'genkit/logging';\nimport { ResolvableAction, type GenkitPluginV2 } 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\nfunction createResolver(pluginOptions: PluginOptions) {\n return async (client: OpenAI, actionType: ActionType, actionName: string) => {\n if (actionType === 'model') {\n const modelRef = xaiModelRef({ name: actionName });\n return defineCompatOpenAIModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n requestBuilder: grokRequestBuilder,\n });\n } else {\n logger.warn('Only model actions are supported by the XAI plugin');\n }\n return undefined;\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: 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: 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): GenkitPluginV2 {\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 const pluginOptions = { name: 'xai', ...options };\n return openAICompatible({\n name: 'xai',\n baseURL: 'https://api.x.ai/v1',\n apiKey,\n ...options,\n initializer: async (client) => {\n const models = [] as ResolvableAction[];\n models.push(\n ...Object.values(SUPPORTED_LANGUAGE_MODELS).map((modelRef) =>\n defineCompatOpenAIModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n requestBuilder: grokRequestBuilder,\n })\n )\n );\n models.push(\n ...Object.values(SUPPORTED_IMAGE_MODELS).map((modelRef) =>\n defineCompatOpenAIImageModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n })\n )\n );\n return models;\n },\n resolver: createResolver(pluginOptions),\n listActions,\n });\n}\n\nexport type XAIPlugin = {\n (params?: XAIPluginOptions): GenkitPluginV2;\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,\n config,\n });\n }\n return xaiModelRef({\n 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,EAEE;AAAA,EACA;AAAA,OAGK;AACP,SAAS,cAAc;AAIvB;AAAA,EACE;AAAA,OAEK;AACP,SAAS,wBAAuC;AAChD,SAAS,+BAA+B;AACxC,SAAS,wBAAwB,wBAAwB;AACzD;AAAA,EACE;AAAA,EACA;AAAA,EAEA;AAAA,OACK;AAIP,SAAS,eAAe,eAA8B;AACpD,SAAO,OAAO,QAAgB,YAAwB,eAAuB;AAC3E,QAAI,eAAe,SAAS;AAC1B,YAAM,WAAW,YAAY,EAAE,MAAM,WAAW,CAAC;AACjD,aAAO,wBAAwB;AAAA,QAC7B,MAAM,SAAS;AAAA,QACf;AAAA,QACA;AAAA,QAC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,wBAAwB;AAAA,YACtB,MAAM,SAAS;AAAA,YACf;AAAA,YACA;AAAA,YACA;AAAA,YACA,gBAAgB;AAAA,UAClB,CAAC;AAAA,QACH;AAAA,MACF;AACA,aAAO;AAAA,QACL,GAAG,OAAO,OAAO,sBAAsB,EAAE;AAAA,UAAI,CAAC,aAC5C,6BAA6B;AAAA,YAC3B,MAAM,SAAS;AAAA,YACf;AAAA,YACA;AAAA,YACA;AAAA,UACF,CAAC;AAAA,QACH;AAAA,MACF;AACA,aAAO;AAAA,IACT;AAAA,IACA,UAAU,eAAe,aAAa;AAAA,IACtC;AAAA,EACF,CAAC;AACH;AAeA,MAAM,QAAS,CAAC,MAAc,WAA+C;AAC3E,MAAI,KAAK,SAAS,OAAO,GAAG;AAC1B,WAAO,iBAAiB;AAAA,MACtB;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AACA,SAAO,YAAY;AAAA,IACjB;AAAA,IACA;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 GenkitError,\n modelActionMetadata,\n ModelReference,\n z,\n} from 'genkit';\nimport { logger } from 'genkit/logging';\nimport { ResolvableAction, type GenkitPluginV2 } 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\nfunction createResolver(pluginOptions: PluginOptions) {\n return async (client: OpenAI, actionType: ActionType, actionName: string) => {\n if (actionType === 'model') {\n const modelRef = xaiModelRef({ name: actionName });\n return defineCompatOpenAIModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n requestBuilder: grokRequestBuilder,\n });\n } else {\n logger.warn('Only model actions are supported by the XAI plugin');\n }\n return undefined;\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: 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: 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): GenkitPluginV2 {\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 const pluginOptions = { name: 'xai', ...options };\n return openAICompatible({\n name: 'xai',\n baseURL: 'https://api.x.ai/v1',\n apiKey,\n ...options,\n initializer: async (client) => {\n const models = [] as ResolvableAction[];\n models.push(\n ...Object.values(SUPPORTED_LANGUAGE_MODELS).map((modelRef) =>\n defineCompatOpenAIModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n requestBuilder: grokRequestBuilder,\n })\n )\n );\n models.push(\n ...Object.values(SUPPORTED_IMAGE_MODELS).map((modelRef) =>\n defineCompatOpenAIImageModel({\n name: modelRef.name,\n client,\n pluginOptions,\n modelRef,\n })\n )\n );\n return models;\n },\n resolver: createResolver(pluginOptions),\n listActions,\n });\n}\n\nexport type XAIPlugin = {\n (params?: XAIPluginOptions): GenkitPluginV2;\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,\n config,\n });\n }\n return xaiModelRef({\n 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 =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  ],
14
- "version": "1.30.0-rc.0",
14
+ "version": "1.31.0",
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.30.0-rc.0"
27
+ "genkit": "^1.31.0"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@jest/globals": "^29.7.0",
@@ -33,7 +33,7 @@
33
33
  "npm-run-all": "^4.1.5",
34
34
  "ts-jest": "^29.1.2",
35
35
  "tsup": "^8.0.2",
36
- "typescript": "^5.4.5"
36
+ "typescript": "^5.9.3"
37
37
  },
38
38
  "types": "./lib/index.d.ts",
39
39
  "exports": {