@genkit-ai/compat-oai 1.34.0 → 1.36.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.
- package/lib/audio.mjs +1 -1
- package/lib/audio.mjs.map +1 -1
- package/lib/deepseek/deepseek.js +1 -1
- package/lib/deepseek/deepseek.js.map +1 -1
- package/lib/deepseek/deepseek.mjs +1 -1
- package/lib/deepseek/deepseek.mjs.map +1 -1
- package/lib/deepseek/index.d.mts +1 -1
- package/lib/deepseek/index.d.ts +1 -1
- package/lib/deepseek/index.js.map +1 -1
- package/lib/deepseek/index.mjs +3 -3
- package/lib/deepseek/index.mjs.map +1 -1
- package/lib/embedder.mjs +1 -1
- package/lib/embedder.mjs.map +1 -1
- package/lib/image.mjs +1 -1
- package/lib/image.mjs.map +1 -1
- package/lib/index.mjs +7 -7
- package/lib/index.mjs.map +1 -1
- package/lib/model.js +13 -1
- package/lib/model.js.map +1 -1
- package/lib/model.mjs +14 -2
- package/lib/model.mjs.map +1 -1
- package/lib/openai/dalle.js +1 -1
- package/lib/openai/dalle.js.map +1 -1
- package/lib/openai/dalle.mjs +1 -1
- package/lib/openai/dalle.mjs.map +1 -1
- package/lib/openai/gpt.js +1 -1
- package/lib/openai/gpt.js.map +1 -1
- package/lib/openai/gpt.mjs +4 -1
- package/lib/openai/gpt.mjs.map +1 -1
- package/lib/openai/index.mjs +11 -11
- package/lib/openai/index.mjs.map +1 -1
- package/lib/openai/stt.js +1 -1
- package/lib/openai/stt.js.map +1 -1
- package/lib/openai/stt.mjs +1 -1
- package/lib/openai/stt.mjs.map +1 -1
- package/lib/openai/tts.js +1 -1
- package/lib/openai/tts.js.map +1 -1
- package/lib/openai/tts.mjs +1 -1
- package/lib/openai/tts.mjs.map +1 -1
- package/lib/openai/whisper.mjs +3 -3
- package/lib/openai/whisper.mjs.map +1 -1
- package/lib/translate.mjs +1 -1
- package/lib/translate.mjs.map +1 -1
- package/lib/xai/grok-image.js +1 -1
- package/lib/xai/grok-image.js.map +1 -1
- package/lib/xai/grok-image.mjs +1 -1
- package/lib/xai/grok-image.mjs.map +1 -1
- package/lib/xai/grok.js +1 -1
- package/lib/xai/grok.js.map +1 -1
- package/lib/xai/grok.mjs +1 -1
- package/lib/xai/grok.mjs.map +1 -1
- package/lib/xai/index.d.mts +1 -1
- package/lib/xai/index.d.ts +1 -1
- package/lib/xai/index.js.map +1 -1
- package/lib/xai/index.mjs +5 -5
- package/lib/xai/index.mjs.map +1 -1
- package/package.json +2 -2
package/lib/openai/tts.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/openai/tts.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 */\nimport { z } from 'genkit';\nimport { ModelInfo } from 'genkit/model';\nimport { compatOaiSpeechModelRef, SpeechConfigSchema } from '../audio';\n\n/** OpenAI speech ModelRef helper, same as the OpenAI-compatible spec. */\nexport function openAISpeechModelRef<\n CustomOptions extends z.ZodTypeAny = z.ZodTypeAny,\n>(params: {\n name: string;\n info?: ModelInfo;\n configSchema?: CustomOptions;\n config?: any;\n}) {\n return compatOaiSpeechModelRef({ ...params, namespace: 'openai' });\n}\n\nexport const SUPPORTED_TTS_MODELS = {\n 'tts-1': openAISpeechModelRef({ name: 'tts-1' }),\n 'tts-1-hd': openAISpeechModelRef({\n name: 'tts-1-hd',\n }),\n 'gpt-4o-mini-tts': openAISpeechModelRef({\n name: 'gpt-4o-mini-tts',\n configSchema: SpeechConfigSchema.omit({ speed: true }),\n }),\n};\n"],"mappings":"AAkBA,SAAS,yBAAyB,0BAA0B;AAGrD,SAAS,qBAEd,QAKC;AACD,SAAO,wBAAwB,EAAE,GAAG,QAAQ,WAAW,SAAS,CAAC;AACnE;AAEO,MAAM,uBAAuB;AAAA,EAClC,SAAS,qBAAqB,EAAE,MAAM,QAAQ,CAAC;AAAA,EAC/C,YAAY,qBAAqB;AAAA,IAC/B,MAAM;AAAA,EACR,CAAC;AAAA,EACD,mBAAmB,qBAAqB;AAAA,IACtC,MAAM;AAAA,IACN,cAAc,mBAAmB,KAAK,EAAE,OAAO,KAAK,CAAC;AAAA,EACvD,CAAC;AACH;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/openai/tts.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 */\nimport { z } from 'genkit';\nimport { ModelInfo } from 'genkit/model';\nimport { compatOaiSpeechModelRef, SpeechConfigSchema } from '../audio.mjs';\n\n/** OpenAI speech ModelRef helper, same as the OpenAI-compatible spec. */\nexport function openAISpeechModelRef<\n CustomOptions extends z.ZodTypeAny = z.ZodTypeAny,\n>(params: {\n name: string;\n info?: ModelInfo;\n configSchema?: CustomOptions;\n config?: any;\n}) {\n return compatOaiSpeechModelRef({ ...params, namespace: 'openai' });\n}\n\nexport const SUPPORTED_TTS_MODELS = {\n 'tts-1': openAISpeechModelRef({ name: 'tts-1' }),\n 'tts-1-hd': openAISpeechModelRef({\n name: 'tts-1-hd',\n }),\n 'gpt-4o-mini-tts': openAISpeechModelRef({\n name: 'gpt-4o-mini-tts',\n configSchema: SpeechConfigSchema.omit({ speed: true }),\n }),\n};\n"],"mappings":"AAkBA,SAAS,yBAAyB,0BAA0B;AAGrD,SAAS,qBAEd,QAKC;AACD,SAAO,wBAAwB,EAAE,GAAG,QAAQ,WAAW,SAAS,CAAC;AACnE;AAEO,MAAM,uBAAuB;AAAA,EAClC,SAAS,qBAAqB,EAAE,MAAM,QAAQ,CAAC;AAAA,EAC/C,YAAY,qBAAqB;AAAA,IAC/B,MAAM;AAAA,EACR,CAAC;AAAA,EACD,mBAAmB,qBAAqB;AAAA,IACtC,MAAM;AAAA,IACN,cAAc,mBAAmB,KAAK,EAAE,OAAO,KAAK,CAAC;AAAA,EACvD,CAAC;AACH;","names":[]}
|
package/lib/openai/whisper.mjs
CHANGED
|
@@ -4,12 +4,12 @@ import {
|
|
|
4
4
|
TranscriptionConfigSchema,
|
|
5
5
|
toSttRequest,
|
|
6
6
|
transcriptionToGenerateResponse
|
|
7
|
-
} from "../audio.
|
|
7
|
+
} from "../audio.mjs";
|
|
8
8
|
import {
|
|
9
9
|
toTranslationRequest,
|
|
10
10
|
translationToGenerateResponse
|
|
11
|
-
} from "../translate.
|
|
12
|
-
import { maybeCreateRequestScopedOpenAIClient, toModelName } from "../utils.
|
|
11
|
+
} from "../translate.mjs";
|
|
12
|
+
import { maybeCreateRequestScopedOpenAIClient, toModelName } from "../utils.mjs";
|
|
13
13
|
const WHISPER_MODEL_INFO = {
|
|
14
14
|
supports: {
|
|
15
15
|
media: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/openai/whisper.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 type { ModelReference } from 'genkit';\nimport { modelRef, z } from 'genkit';\nimport type { ModelAction, ModelInfo } from 'genkit/model';\nimport { model } from 'genkit/plugin';\nimport OpenAI from 'openai';\nimport {\n TranscriptionConfigSchema,\n toSttRequest,\n transcriptionToGenerateResponse,\n} from '../audio.
|
|
1
|
+
{"version":3,"sources":["../../src/openai/whisper.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 type { ModelReference } from 'genkit';\nimport { modelRef, z } from 'genkit';\nimport type { ModelAction, ModelInfo } from 'genkit/model';\nimport { model } from 'genkit/plugin';\nimport OpenAI from 'openai';\nimport {\n TranscriptionConfigSchema,\n toSttRequest,\n transcriptionToGenerateResponse,\n} from '../audio.mjs';\nimport type { PluginOptions } from '../index.mjs';\nimport {\n toTranslationRequest,\n translationToGenerateResponse,\n} from '../translate.mjs';\nimport { maybeCreateRequestScopedOpenAIClient, toModelName } from '../utils.mjs';\n\nexport const WHISPER_MODEL_INFO: ModelInfo = {\n supports: {\n media: true,\n output: ['text', 'json'],\n multiturn: false,\n systemRole: false,\n tools: false,\n },\n};\n\n/**\n * Config schema for Whisper models. Extends the transcription config with\n * a `translate` flag that switches between transcription and translation APIs.\n */\nexport const WhisperConfigSchema = TranscriptionConfigSchema.extend({\n /** When true, uses Translation API instead of Transcription. Default: false */\n translate: z.boolean().optional().default(false),\n});\n\n/**\n * Method to define an OpenAI Whisper model that can perform both transcription and\n * translation based on the `translate` config flag.\n *\n * @param params.ai The Genkit AI instance.\n * @param params.name The name of the model.\n * @param params.client The OpenAI client instance.\n * @param params.modelRef Optional reference to the model's configuration and\n * custom options.\n *\n * @returns the created {@link ModelAction}\n */\nexport function defineOpenAIWhisperModel<\n CustomOptions extends z.ZodTypeAny = z.ZodTypeAny,\n>(params: {\n name: string;\n client: OpenAI;\n modelRef?: ModelReference<CustomOptions>;\n pluginOptions?: PluginOptions;\n}): ModelAction {\n const { name, client: defaultClient, pluginOptions, modelRef } = params;\n const modelName = toModelName(name, pluginOptions?.name);\n const actionName =\n modelRef?.name ?? `${pluginOptions?.name ?? 'openai'}/${modelName}`;\n\n return model(\n {\n name: actionName,\n ...modelRef?.info,\n configSchema: modelRef?.configSchema,\n },\n async (request, { abortSignal }) => {\n const { translate, ...cleanConfig } = (request.config ?? {}) as Record<\n string,\n unknown\n >;\n const cleanRequest = { ...request, config: cleanConfig };\n const client = maybeCreateRequestScopedOpenAIClient(\n pluginOptions,\n request,\n defaultClient\n );\n\n if (translate === true) {\n const params = toTranslationRequest(modelName, cleanRequest);\n const result = await client.audio.translations.create(params, {\n signal: abortSignal,\n });\n return translationToGenerateResponse(result);\n } else {\n const params = toSttRequest(modelName, cleanRequest);\n // Explicitly setting stream to false ensures we use the non-streaming overload\n const result = await client.audio.transcriptions.create(\n {\n ...params,\n stream: false,\n },\n { signal: abortSignal }\n );\n return transcriptionToGenerateResponse(result);\n }\n }\n );\n}\n\n/** OpenAI whisper ModelRef helper. */\nexport function openAIWhisperModelRef<\n CustomOptions extends z.ZodTypeAny = z.ZodTypeAny,\n>(params: {\n name: string;\n info?: ModelInfo;\n configSchema?: CustomOptions;\n config?: any;\n}) {\n const {\n name,\n info = WHISPER_MODEL_INFO,\n configSchema,\n config = undefined,\n } = params;\n return modelRef({\n name,\n configSchema: configSchema || (WhisperConfigSchema as any),\n info,\n config,\n namespace: 'openai',\n });\n}\n\nexport const SUPPORTED_WHISPER_MODELS = {\n 'whisper-1': openAIWhisper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AY;AAEnD,cAAM,SAAS,MAAM,OAAO,MAAM,eAAe;AAAA,UAC/C;AAAA,YACE,GAAGA;AAAA,YACH,QAAQ;AAAA,UACV;AAAA,UACA,EAAE,QAAQ,YAAY;AAAA,QACxB;AACA,eAAO,gCAAgC,MAAM;AAAA,MAC/C;AAAA,IACF;AAAA,EACF;AACF;AAGO,SAAS,sBAEd,QAKC;AACD,QAAM;AAAA,IACJ;AAAA,IACA,OAAO;AAAA,IACP;AAAA,IACA,SAAS;AAAA,EACX,IAAI;AACJ,SAAO,SAAS;AAAA,IACd;AAAA,IACA,cAAc,gBAAiB;AAAA,IAC/B;AAAA,IACA;AAAA,IACA,WAAW;AAAA,EACb,CAAC;AACH;AAEO,MAAM,2BAA2B;AAAA,EACtC,aAAa,sBAAsB;AAAA,IACjC,MAAM;AAAA,EACR,CAAC;AACH;","names":["modelRef","params"]}
|
package/lib/translate.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GenerationCommonConfigSchema, Message, modelRef, z } from "genkit";
|
|
2
2
|
import { model } from "genkit/plugin";
|
|
3
|
-
import { maybeCreateRequestScopedOpenAIClient, toModelName } from "./utils.
|
|
3
|
+
import { maybeCreateRequestScopedOpenAIClient, toModelName } from "./utils.mjs";
|
|
4
4
|
const TRANSLATION_MODEL_INFO = {
|
|
5
5
|
supports: {
|
|
6
6
|
media: true,
|
package/lib/translate.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/translate.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 type {\n GenerateRequest,\n GenerateResponseData,\n ModelReference,\n} from 'genkit';\nimport { GenerationCommonConfigSchema, Message, modelRef, z } from 'genkit';\nimport type { ModelAction, ModelInfo } from 'genkit/model';\nimport { model } from 'genkit/plugin';\nimport OpenAI from 'openai';\nimport type {\n TranslationCreateParams,\n TranslationCreateResponse,\n} from 'openai/resources/audio/index.mjs';\nimport { PluginOptions } from './index.
|
|
1
|
+
{"version":3,"sources":["../src/translate.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 type {\n GenerateRequest,\n GenerateResponseData,\n ModelReference,\n} from 'genkit';\nimport { GenerationCommonConfigSchema, Message, modelRef, z } from 'genkit';\nimport type { ModelAction, ModelInfo } from 'genkit/model';\nimport { model } from 'genkit/plugin';\nimport OpenAI from 'openai';\nimport type {\n TranslationCreateParams,\n TranslationCreateResponse,\n} from 'openai/resources/audio/index.mjs';\nimport { PluginOptions } from './index.mjs';\nimport { maybeCreateRequestScopedOpenAIClient, toModelName } from './utils.mjs';\n\nexport type TranslationRequestBuilder = (\n req: GenerateRequest,\n params: TranslationCreateParams\n) => void;\n\nexport const TRANSLATION_MODEL_INFO: ModelInfo = {\n supports: {\n media: true,\n output: ['text', 'json'],\n multiturn: false,\n systemRole: false,\n tools: false,\n },\n};\n\nexport const TranslationConfigSchema = GenerationCommonConfigSchema.pick({\n temperature: true,\n}).extend({\n response_format: z\n .enum(['json', 'text', 'srt', 'verbose_json', 'vtt'])\n .optional(),\n});\n\nexport function toTranslationRequest(\n modelName: string,\n request: GenerateRequest,\n requestBuilder?: TranslationRequestBuilder\n): TranslationCreateParams {\n const message = new Message(request.messages[0]);\n const media = message.media;\n if (!media?.url) {\n throw new Error('No media found in the request');\n }\n const mediaBuffer = Buffer.from(\n media.url.slice(media.url.indexOf(',') + 1),\n 'base64'\n );\n const mediaFile = new File([mediaBuffer], 'input', {\n type:\n media.contentType ??\n media.url.slice('data:'.length, media.url.indexOf(';')),\n });\n const {\n temperature,\n version: modelVersion,\n maxOutputTokens,\n stopSequences,\n topK,\n topP,\n ...restOfConfig\n } = request.config ?? {};\n\n let options: TranslationCreateParams = {\n model: modelVersion ?? modelName,\n file: mediaFile,\n prompt: message.text,\n temperature,\n };\n if (requestBuilder) {\n requestBuilder(request, options);\n } else {\n options = {\n ...options,\n ...restOfConfig, // passthrough rest of the config\n };\n }\n const outputFormat = request.output?.format as 'json' | 'text' | 'media';\n const customFormat = request.config?.response_format;\n if (outputFormat && customFormat) {\n if (\n outputFormat === 'json' &&\n customFormat !== 'json' &&\n customFormat !== 'verbose_json'\n ) {\n throw new Error(\n `Custom response format ${customFormat} is not compatible with output format ${outputFormat}`\n );\n }\n }\n if (outputFormat === 'media') {\n throw new Error(`Output format ${outputFormat} is not supported.`);\n }\n options.response_format = customFormat || outputFormat || 'text';\n for (const k in options) {\n if (options[k] === undefined) {\n delete options[k];\n }\n }\n return options;\n}\n\nexport function translationToGenerateResponse(\n result: TranslationCreateResponse | string\n): GenerateResponseData {\n return {\n message: {\n role: 'model',\n content: [\n {\n text: typeof result === 'string' ? result : result.text,\n },\n ],\n },\n finishReason: 'stop',\n raw: result,\n };\n}\n\n/**\n * Method to define a new Genkit Model that is compatible with Open AI\n * Translation API.\n *\n * These models are to be used to translate audio to text.\n *\n * @param params An object containing parameters for defining the OpenAI\n * translation model.\n * @param params.ai The Genkit AI instance.\n * @param params.name The name of the model.\n * @param params.client The OpenAI client instance.\n * @param params.modelRef Optional reference to the model's configuration and\n * custom options.\n *\n * @returns the created {@link ModelAction}\n */\nexport function defineCompatOpenAITranslationModel<\n CustomOptions extends z.ZodTypeAny = z.ZodTypeAny,\n>(params: {\n name: string;\n client: OpenAI;\n pluginOptions?: PluginOptions;\n modelRef?: ModelReference<CustomOptions>;\n requestBuilder?: TranslationRequestBuilder;\n}) {\n const {\n name,\n client: defaultClient,\n pluginOptions,\n modelRef,\n requestBuilder,\n } = params;\n const modelName = toModelName(name, pluginOptions?.name);\n const actionName = `${pluginOptions?.name ?? 'compat-oai'}/${modelName}`;\n\n return model(\n {\n name: actionName,\n ...modelRef?.info,\n configSchema: modelRef?.configSchema,\n },\n async (request, { abortSignal }) => {\n const params = toTranslationRequest(modelName, request, requestBuilder);\n const client = maybeCreateRequestScopedOpenAIClient(\n pluginOptions,\n request,\n defaultClient\n );\n const result = await client.audio.translations.create(params, {\n signal: abortSignal,\n });\n return translationToGenerateResponse(result);\n }\n );\n}\n\n/** Translation ModelRef helper, with reasonable defaults for\n * OpenAI-compatible providers */\nexport function compatOaiTranslationModelRef<\n CustomOptions extends z.ZodTypeAny = z.ZodTypeAny,\n>(params: {\n name: string;\n info?: ModelInfo;\n configSchema?: CustomOptions;\n config?: any;\n namespace?: string;\n}) {\n const {\n name,\n info = TRANSLATION_MODEL_INFO,\n configSchema,\n config = undefined,\n namespace,\n } = params;\n return modelRef({\n name,\n configSchema: configSchema || (TranslationConfigSchema as any),\n info,\n config,\n namespace,\n });\n}\n"],"mappings":"AAsBA,SAAS,8BAA8B,SAAS,UAAU,SAAS;AAEnE,SAAS,aAAa;AAOtB,SAAS,sCAAsC,mBAAmB;AAO3D,MAAM,yBAAoC;AAAA,EAC/C,UAAU;AAAA,IACR,OAAO;AAAA,IACP,QAAQ,CAAC,QAAQ,MAAM;AAAA,IACvB,WAAW;AAAA,IACX,YAAY;AAAA,IACZ,OAAO;AAAA,EACT;AACF;AAEO,MAAM,0BAA0B,6BAA6B,KAAK;AAAA,EACvE,aAAa;AACf,CAAC,EAAE,OAAO;AAAA,EAC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B;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACH;","names":["modelRef","params"]}
|
package/lib/xai/grok-image.js
CHANGED
|
@@ -22,7 +22,7 @@ __export(grok_image_exports, {
|
|
|
22
22
|
xaiImageModelRef: () => xaiImageModelRef
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(grok_image_exports);
|
|
25
|
-
var import_image = require("../image");
|
|
25
|
+
var import_image = require("../image.js");
|
|
26
26
|
function xaiImageModelRef(params) {
|
|
27
27
|
return (0, import_image.compatOaiImageModelRef)({ ...params, namespace: "xai" });
|
|
28
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/xai/grok-image.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 { z } from 'genkit';\nimport { ModelInfo } from 'genkit/model';\nimport { compatOaiImageModelRef } from '../image';\n\n/** XAI image generation ModelRef helper, same as the OpenAI-compatible model specification. */\nexport function xaiImageModelRef<\n CustomOptions extends z.ZodTypeAny = z.ZodTypeAny,\n>(params: {\n name: string;\n info?: ModelInfo;\n configSchema?: CustomOptions;\n config?: any;\n}) {\n return compatOaiImageModelRef({ ...params, namespace: 'xai' });\n}\n\nexport const SUPPORTED_IMAGE_MODELS = {\n 'grok-2-image-1212': xaiImageModelRef({\n name: 'grok-2-image-1212',\n }),\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBA,mBAAuC;AAGhC,SAAS,iBAEd,QAKC;AACD,aAAO,qCAAuB,EAAE,GAAG,QAAQ,WAAW,MAAM,CAAC;AAC/D;AAEO,MAAM,yBAAyB;AAAA,EACpC,qBAAqB,iBAAiB;AAAA,IACpC,MAAM;AAAA,EACR,CAAC;AACH;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/xai/grok-image.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 { z } from 'genkit';\nimport { ModelInfo } from 'genkit/model';\nimport { compatOaiImageModelRef } from '../image.js';\n\n/** XAI image generation ModelRef helper, same as the OpenAI-compatible model specification. */\nexport function xaiImageModelRef<\n CustomOptions extends z.ZodTypeAny = z.ZodTypeAny,\n>(params: {\n name: string;\n info?: ModelInfo;\n configSchema?: CustomOptions;\n config?: any;\n}) {\n return compatOaiImageModelRef({ ...params, namespace: 'xai' });\n}\n\nexport const SUPPORTED_IMAGE_MODELS = {\n 'grok-2-image-1212': xaiImageModelRef({\n name: 'grok-2-image-1212',\n }),\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBA,mBAAuC;AAGhC,SAAS,iBAEd,QAKC;AACD,aAAO,qCAAuB,EAAE,GAAG,QAAQ,WAAW,MAAM,CAAC;AAC/D;AAEO,MAAM,yBAAyB;AAAA,EACpC,qBAAqB,iBAAiB;AAAA,IACpC,MAAM;AAAA,EACR,CAAC;AACH;","names":[]}
|
package/lib/xai/grok-image.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/xai/grok-image.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 { z } from 'genkit';\nimport { ModelInfo } from 'genkit/model';\nimport { compatOaiImageModelRef } from '../image';\n\n/** XAI image generation ModelRef helper, same as the OpenAI-compatible model specification. */\nexport function xaiImageModelRef<\n CustomOptions extends z.ZodTypeAny = z.ZodTypeAny,\n>(params: {\n name: string;\n info?: ModelInfo;\n configSchema?: CustomOptions;\n config?: any;\n}) {\n return compatOaiImageModelRef({ ...params, namespace: 'xai' });\n}\n\nexport const SUPPORTED_IMAGE_MODELS = {\n 'grok-2-image-1212': xaiImageModelRef({\n name: 'grok-2-image-1212',\n }),\n};\n"],"mappings":"AAkBA,SAAS,8BAA8B;AAGhC,SAAS,iBAEd,QAKC;AACD,SAAO,uBAAuB,EAAE,GAAG,QAAQ,WAAW,MAAM,CAAC;AAC/D;AAEO,MAAM,yBAAyB;AAAA,EACpC,qBAAqB,iBAAiB;AAAA,IACpC,MAAM;AAAA,EACR,CAAC;AACH;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/xai/grok-image.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 { z } from 'genkit';\nimport { ModelInfo } from 'genkit/model';\nimport { compatOaiImageModelRef } from '../image.mjs';\n\n/** XAI image generation ModelRef helper, same as the OpenAI-compatible model specification. */\nexport function xaiImageModelRef<\n CustomOptions extends z.ZodTypeAny = z.ZodTypeAny,\n>(params: {\n name: string;\n info?: ModelInfo;\n configSchema?: CustomOptions;\n config?: any;\n}) {\n return compatOaiImageModelRef({ ...params, namespace: 'xai' });\n}\n\nexport const SUPPORTED_IMAGE_MODELS = {\n 'grok-2-image-1212': xaiImageModelRef({\n name: 'grok-2-image-1212',\n }),\n};\n"],"mappings":"AAkBA,SAAS,8BAA8B;AAGhC,SAAS,iBAEd,QAKC;AACD,SAAO,uBAAuB,EAAE,GAAG,QAAQ,WAAW,MAAM,CAAC;AAC/D;AAEO,MAAM,yBAAyB;AAAA,EACpC,qBAAqB,iBAAiB;AAAA,IACpC,MAAM;AAAA,EACR,CAAC;AACH;","names":[]}
|
package/lib/xai/grok.js
CHANGED
|
@@ -25,7 +25,7 @@ __export(grok_exports, {
|
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(grok_exports);
|
|
27
27
|
var import_genkit = require("genkit");
|
|
28
|
-
var import_model2 = require("../model");
|
|
28
|
+
var import_model2 = require("../model.js");
|
|
29
29
|
const XAI_LANGUGAGE_MODEL_INFO = {
|
|
30
30
|
supports: {
|
|
31
31
|
multiturn: true,
|
package/lib/xai/grok.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/xai/grok.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 { z } from 'genkit';\nimport { ModelInfo, ModelReference } from 'genkit/model';\nimport {\n ChatCompletionCommonConfigSchema,\n ModelRequestBuilder,\n compatOaiModelRef,\n} from '../model';\n\n/**\n * Language models that support text -> text, tool calling, structured output\n */\nconst XAI_LANGUGAGE_MODEL_INFO: ModelInfo = {\n supports: {\n multiturn: true,\n tools: true,\n media: false,\n systemRole: true,\n output: ['text', 'json'],\n },\n};\n\n/** XAI Custom configuration schema. */\nexport const XaiChatCompletionConfigSchema =\n ChatCompletionCommonConfigSchema.extend({\n deferred: z.boolean().optional(),\n reasoningEffort: z.enum(['low', 'medium', 'high']).optional(),\n webSearchOptions: z.object({}).passthrough().optional(),\n });\n\n/** XAI ModelRef helper, with XAI specific config. */\nexport function xaiModelRef(params: {\n name: string;\n info?: ModelInfo;\n config?: any;\n}): ModelReference<typeof XaiChatCompletionConfigSchema> {\n return compatOaiModelRef({\n ...params,\n info: params.info ?? XAI_LANGUGAGE_MODEL_INFO,\n configSchema: XaiChatCompletionConfigSchema,\n namespace: 'xai',\n });\n}\n\nexport const grokRequestBuilder: ModelRequestBuilder = (req, params) => {\n const { deferred, webSearchOptions, reasoningEffort } = req.config ?? {};\n\n params.web_search_options = webSearchOptions;\n params.reasoning_effort = reasoningEffort;\n // Deferred is not a standard field on the request type\n (params as any).deferred = deferred;\n};\n\nexport const SUPPORTED_LANGUAGE_MODELS = {\n 'grok-3': xaiModelRef({\n name: 'grok-3',\n }),\n 'grok-3-fast': xaiModelRef({\n name: 'grok-3-fast',\n }),\n 'grok-3-mini': xaiModelRef({\n name: 'grok-3-mini',\n }),\n 'grok-3-mini-fast': xaiModelRef({\n name: 'grok-3-mini-fast',\n }),\n 'grok-2-vision-1212': xaiModelRef({\n name: 'grok-2-vision-1212',\n info: {\n supports: {\n multiturn: false,\n tools: true,\n media: true,\n systemRole: false,\n output: ['text', 'json'],\n },\n },\n }),\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBA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,CAAC;AACH;","names":["import_model"]}
|
|
1
|
+
{"version":3,"sources":["../../src/xai/grok.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 { z } from 'genkit';\nimport { ModelInfo, ModelReference } from 'genkit/model';\nimport {\n ChatCompletionCommonConfigSchema,\n ModelRequestBuilder,\n compatOaiModelRef,\n} from '../model.js';\n\n/**\n * Language models that support text -> text, tool calling, structured output\n */\nconst XAI_LANGUGAGE_MODEL_INFO: ModelInfo = {\n supports: {\n multiturn: true,\n tools: true,\n media: false,\n systemRole: true,\n output: ['text', 'json'],\n },\n};\n\n/** XAI Custom configuration schema. */\nexport const XaiChatCompletionConfigSchema =\n ChatCompletionCommonConfigSchema.extend({\n deferred: z.boolean().optional(),\n reasoningEffort: z.enum(['low', 'medium', 'high']).optional(),\n webSearchOptions: z.object({}).passthrough().optional(),\n });\n\n/** XAI ModelRef helper, with XAI specific config. */\nexport function xaiModelRef(params: {\n name: string;\n info?: ModelInfo;\n config?: any;\n}): ModelReference<typeof XaiChatCompletionConfigSchema> {\n return compatOaiModelRef({\n ...params,\n info: params.info ?? XAI_LANGUGAGE_MODEL_INFO,\n configSchema: XaiChatCompletionConfigSchema,\n namespace: 'xai',\n });\n}\n\nexport const grokRequestBuilder: ModelRequestBuilder = (req, params) => {\n const { deferred, webSearchOptions, reasoningEffort } = req.config ?? {};\n\n params.web_search_options = webSearchOptions;\n params.reasoning_effort = reasoningEffort;\n // Deferred is not a standard field on the request type\n (params as any).deferred = deferred;\n};\n\nexport const SUPPORTED_LANGUAGE_MODELS = {\n 'grok-3': xaiModelRef({\n name: 'grok-3',\n }),\n 'grok-3-fast': xaiModelRef({\n name: 'grok-3-fast',\n }),\n 'grok-3-mini': xaiModelRef({\n name: 'grok-3-mini',\n }),\n 'grok-3-mini-fast': xaiModelRef({\n name: 'grok-3-mini-fast',\n }),\n 'grok-2-vision-1212': xaiModelRef({\n name: 'grok-2-vision-1212',\n info: {\n supports: {\n multiturn: false,\n tools: true,\n media: true,\n systemRole: false,\n output: ['text', 'json'],\n },\n },\n }),\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBA,oBAAkB;AAElB,IAAAA,gBAIO;AAKP,MAAM,2BAAsC;AAAA,EAC1C,UAAU;AAAA,IACR,WAAW;AAAA,IACX,OAAO;AAAA,IACP,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,QAAQ,CAAC,QAAQ,MAAM;AAAA,EACzB;AACF;AAGO,MAAM,gCACX,+CAAiC,OAAO;AAAA,EACtC,UAAU,gBAAE,QAAQ,EAAE,SAAS;AAAA,EAC/B,iBAAiB,gBAAE,KAAK,CAAC,OAAO,UAAU,MAAM,CAAC,EAAE,SAAS;AAAA,EAC5D,kBAAkB,gBAAE,OAAO,CAAC,CAAC,EAAE,YAAY,EAAE,SAAS;AACxD,CAAC;AAGI,SAAS,YAAY,QAI6B;AACvD,aAAO,iCAAkB;AAAA,IACvB,GAAG;AAAA,IACH,MAAM,OAAO,QAAQ;AAAA,IACrB,cAAc;AAAA,IACd,WAAW;AAAA,EACb,CAAC;AACH;AAEO,MAAM,qBAA0C,CAAC,KAAK,WAAW;AACtE,QAAM,EAAE,UAAU,kBAAkB,gBAAgB,IAAI,IAAI,UAAU,CAAC;AAEvE,SAAO,qBAAqB;AAC5B,SAAO,mBAAmB;AAE1B,EAAC,OAAe,WAAW;AAC7B;AAEO,MAAM,4BAA4B;AAAA,EACvC,UAAU,YAAY;AAAA,IACpB,MAAM;AAAA,EACR,CAAC;AAAA,EACD,eAAe,YAAY;AAAA,IACzB,MAAM;AAAA,EACR,CAAC;AAAA,EACD,eAAe,YAAY;AAAA,IACzB,MAAM;AAAA,EACR,CAAC;AAAA,EACD,oBAAoB,YAAY;AAAA,IAC9B,MAAM;AAAA,EACR,CAAC;AAAA,EACD,sBAAsB,YAAY;AAAA,IAChC,MAAM;AAAA,IACN,MAAM;AAAA,MACJ,UAAU;AAAA,QACR,WAAW;AAAA,QACX,OAAO;AAAA,QACP,OAAO;AAAA,QACP,YAAY;AAAA,QACZ,QAAQ,CAAC,QAAQ,MAAM;AAAA,MACzB;AAAA,IACF;AAAA,EACF,CAAC;AACH;","names":["import_model"]}
|
package/lib/xai/grok.mjs
CHANGED
package/lib/xai/grok.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/xai/grok.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 { z } from 'genkit';\nimport { ModelInfo, ModelReference } from 'genkit/model';\nimport {\n ChatCompletionCommonConfigSchema,\n ModelRequestBuilder,\n compatOaiModelRef,\n} from '../model';\n\n/**\n * Language models that support text -> text, tool calling, structured output\n */\nconst XAI_LANGUGAGE_MODEL_INFO: ModelInfo = {\n supports: {\n multiturn: true,\n tools: true,\n media: false,\n systemRole: true,\n output: ['text', 'json'],\n },\n};\n\n/** XAI Custom configuration schema. */\nexport const XaiChatCompletionConfigSchema =\n ChatCompletionCommonConfigSchema.extend({\n deferred: z.boolean().optional(),\n reasoningEffort: z.enum(['low', 'medium', 'high']).optional(),\n webSearchOptions: z.object({}).passthrough().optional(),\n });\n\n/** XAI ModelRef helper, with XAI specific config. */\nexport function xaiModelRef(params: {\n name: string;\n info?: ModelInfo;\n config?: any;\n}): ModelReference<typeof XaiChatCompletionConfigSchema> {\n return compatOaiModelRef({\n ...params,\n info: params.info ?? XAI_LANGUGAGE_MODEL_INFO,\n configSchema: XaiChatCompletionConfigSchema,\n namespace: 'xai',\n });\n}\n\nexport const grokRequestBuilder: ModelRequestBuilder = (req, params) => {\n const { deferred, webSearchOptions, reasoningEffort } = req.config ?? {};\n\n params.web_search_options = webSearchOptions;\n params.reasoning_effort = reasoningEffort;\n // Deferred is not a standard field on the request type\n (params as any).deferred = deferred;\n};\n\nexport const SUPPORTED_LANGUAGE_MODELS = {\n 'grok-3': xaiModelRef({\n name: 'grok-3',\n }),\n 'grok-3-fast': xaiModelRef({\n name: 'grok-3-fast',\n }),\n 'grok-3-mini': xaiModelRef({\n name: 'grok-3-mini',\n }),\n 'grok-3-mini-fast': xaiModelRef({\n name: 'grok-3-mini-fast',\n }),\n 'grok-2-vision-1212': xaiModelRef({\n name: 'grok-2-vision-1212',\n info: {\n supports: {\n multiturn: false,\n tools: true,\n media: true,\n systemRole: false,\n output: ['text', 'json'],\n },\n },\n }),\n};\n"],"mappings":"AAgBA,SAAS,SAAS;AAElB;AAAA,EACE;AAAA,EAEA;AAAA,OACK;AAKP,MAAM,2BAAsC;AAAA,EAC1C,UAAU;AAAA,IACR,WAAW;AAAA,IACX,OAAO;AAAA,IACP,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,QAAQ,CAAC,QAAQ,MAAM;AAAA,EACzB;AACF;AAGO,MAAM,gCACX,iCAAiC,OAAO;AAAA,EACtC,UAAU,EAAE,QAAQ,EAAE,SAAS;AAAA,EAC/B,iBAAiB,EAAE,KAAK,CAAC,OAAO,UAAU,MAAM,CAAC,EAAE,SAAS;AAAA,EAC5D,kBAAkB,EAAE,OAAO,CAAC,CAAC,EAAE,YAAY,EAAE,SAAS;AACxD,CAAC;AAGI,SAAS,YAAY,QAI6B;AACvD,SAAO,kBAAkB;AAAA,IACvB,GAAG;AAAA,IACH,MAAM,OAAO,QAAQ;AAAA,IACrB,cAAc;AAAA,IACd,WAAW;AAAA,EACb,CAAC;AACH;AAEO,MAAM,qBAA0C,CAAC,KAAK,WAAW;AACtE,QAAM,EAAE,UAAU,kBAAkB,gBAAgB,IAAI,IAAI,UAAU,CAAC;AAEvE,SAAO,qBAAqB;AAC5B,SAAO,mBAAmB;AAE1B,EAAC,OAAe,WAAW;AAC7B;AAEO,MAAM,4BAA4B;AAAA,EACvC,UAAU,YAAY;AAAA,IACpB,MAAM;AAAA,EACR,CAAC;AAAA,EACD,eAAe,YAAY;AAAA,IACzB,MAAM;AAAA,EACR,CAAC;AAAA,EACD,eAAe,YAAY;AAAA,IACzB,MAAM;AAAA,EACR,CAAC;AAAA,EACD,oBAAoB,YAAY;AAAA,IAC9B,MAAM;AAAA,EACR,CAAC;AAAA,EACD,sBAAsB,YAAY;AAAA,IAChC,MAAM;AAAA,IACN,MAAM;AAAA,MACJ,UAAU;AAAA,QACR,WAAW;AAAA,QACX,OAAO;AAAA,QACP,OAAO;AAAA,QACP,YAAY;AAAA,QACZ,QAAQ,CAAC,QAAQ,MAAM;AAAA,MACzB;AAAA,IACF;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/xai/grok.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 { z } from 'genkit';\nimport { ModelInfo, ModelReference } from 'genkit/model';\nimport {\n ChatCompletionCommonConfigSchema,\n ModelRequestBuilder,\n compatOaiModelRef,\n} from '../model.mjs';\n\n/**\n * Language models that support text -> text, tool calling, structured output\n */\nconst XAI_LANGUGAGE_MODEL_INFO: ModelInfo = {\n supports: {\n multiturn: true,\n tools: true,\n media: false,\n systemRole: true,\n output: ['text', 'json'],\n },\n};\n\n/** XAI Custom configuration schema. */\nexport const XaiChatCompletionConfigSchema =\n ChatCompletionCommonConfigSchema.extend({\n deferred: z.boolean().optional(),\n reasoningEffort: z.enum(['low', 'medium', 'high']).optional(),\n webSearchOptions: z.object({}).passthrough().optional(),\n });\n\n/** XAI ModelRef helper, with XAI specific config. */\nexport function xaiModelRef(params: {\n name: string;\n info?: ModelInfo;\n config?: any;\n}): ModelReference<typeof XaiChatCompletionConfigSchema> {\n return compatOaiModelRef({\n ...params,\n info: params.info ?? XAI_LANGUGAGE_MODEL_INFO,\n configSchema: XaiChatCompletionConfigSchema,\n namespace: 'xai',\n });\n}\n\nexport const grokRequestBuilder: ModelRequestBuilder = (req, params) => {\n const { deferred, webSearchOptions, reasoningEffort } = req.config ?? {};\n\n params.web_search_options = webSearchOptions;\n params.reasoning_effort = reasoningEffort;\n // Deferred is not a standard field on the request type\n (params as any).deferred = deferred;\n};\n\nexport const SUPPORTED_LANGUAGE_MODELS = {\n 'grok-3': xaiModelRef({\n name: 'grok-3',\n }),\n 'grok-3-fast': xaiModelRef({\n name: 'grok-3-fast',\n }),\n 'grok-3-mini': xaiModelRef({\n name: 'grok-3-mini',\n }),\n 'grok-3-mini-fast': xaiModelRef({\n name: 'grok-3-mini-fast',\n }),\n 'grok-2-vision-1212': xaiModelRef({\n name: 'grok-2-vision-1212',\n info: {\n supports: {\n multiturn: false,\n tools: true,\n media: true,\n systemRole: false,\n output: ['text', 'json'],\n },\n },\n }),\n};\n"],"mappings":"AAgBA,SAAS,SAAS;AAElB;AAAA,EACE;AAAA,EAEA;AAAA,OACK;AAKP,MAAM,2BAAsC;AAAA,EAC1C,UAAU;AAAA,IACR,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
|
|
50
50
|
*
|
|
51
51
|
* Usage: To use the models, initialize the xAI plugin inside
|
|
52
52
|
* `configureGenkit` and pass the configuration options. If no API key is
|
|
53
|
-
* provided in the options, the environment variable `
|
|
53
|
+
* provided in the options, the environment variable `XAI_API_KEY` must be
|
|
54
54
|
* set.
|
|
55
55
|
*
|
|
56
56
|
* Example:
|
package/lib/xai/index.d.ts
CHANGED
|
@@ -50,7 +50,7 @@ type XAIPlugin = {
|
|
|
50
50
|
*
|
|
51
51
|
* Usage: To use the models, initialize the xAI plugin inside
|
|
52
52
|
* `configureGenkit` and pass the configuration options. If no API key is
|
|
53
|
-
* provided in the options, the environment variable `
|
|
53
|
+
* provided in the options, the environment variable `XAI_API_KEY` must be
|
|
54
54
|
* set.
|
|
55
55
|
*
|
|
56
56
|
* Example:
|
package/lib/xai/index.js.map
CHANGED
|
@@ -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 `
|
|
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 `XAI_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,QACA;AAAA,QACA,gBAAgB;AAAA,MAClB,CAAC;AAAA,IACH,OAAO;AACL,4BAAO,KAAK,oDAAoD;AAAA,IAClE;AACA,WAAO;AAAA,EACT;AACF;AAEA,MAAM,cAAc,OAAO,WAA8C;AACvE,SAAO,MAAM,OAAO,OAAO,KAAK,EAAE;AAAA,IAAK,CAAC,aACtC,SAAS,KACN,OAAO,CAACA,WAAUA,OAAM,WAAW,OAAO,EAC1C,IAAI,CAACA,WAAwB;AAC5B,UAAIA,OAAM,GAAG,SAAS,OAAO,GAAG;AAC9B,cAAM,WACJ,yCAAuBA,OAAM,EAAE,SAC/B,oCAAiB,EAAE,MAAMA,OAAM,GAAG,CAAC;AACrC,mBAAO,mCAAoB;AAAA,UACzB,MAAM,SAAS;AAAA,UACf,MAAM,SAAS;AAAA,UACf,cAAc,SAAS;AAAA,QACzB,CAAC;AAAA,MACH,OAAO;AACL,cA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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
|
@@ -5,15 +5,15 @@ import {
|
|
|
5
5
|
import { logger } from "genkit/logging";
|
|
6
6
|
import {
|
|
7
7
|
defineCompatOpenAIImageModel
|
|
8
|
-
} from "../image.
|
|
9
|
-
import { openAICompatible } from "../index.
|
|
10
|
-
import { defineCompatOpenAIModel } from "../model.
|
|
11
|
-
import { SUPPORTED_IMAGE_MODELS, xaiImageModelRef } from "./grok-image.
|
|
8
|
+
} from "../image.mjs";
|
|
9
|
+
import { openAICompatible } from "../index.mjs";
|
|
10
|
+
import { defineCompatOpenAIModel } from "../model.mjs";
|
|
11
|
+
import { SUPPORTED_IMAGE_MODELS, xaiImageModelRef } from "./grok-image.mjs";
|
|
12
12
|
import {
|
|
13
13
|
grokRequestBuilder,
|
|
14
14
|
SUPPORTED_LANGUAGE_MODELS,
|
|
15
15
|
xaiModelRef
|
|
16
|
-
} from "./grok.
|
|
16
|
+
} from "./grok.mjs";
|
|
17
17
|
function createResolver(pluginOptions) {
|
|
18
18
|
return async (client, actionType, actionName) => {
|
|
19
19
|
if (actionType === "model") {
|
package/lib/xai/index.mjs.map
CHANGED
|
@@ -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.
|
|
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.mjs';\nimport { openAICompatible, PluginOptions } from '../index.mjs';\nimport { defineCompatOpenAIModel } from '../model.mjs';\nimport { SUPPORTED_IMAGE_MODELS, xaiImageModelRef } from './grok-image.mjs';\nimport {\n grokRequestBuilder,\n SUPPORTED_LANGUAGE_MODELS,\n XaiChatCompletionConfigSchema,\n xaiModelRef,\n} from './grok.mjs';\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 `XAI_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;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C,aAC/C,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,SAAS,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"]}
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"genai",
|
|
12
12
|
"generative-ai"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.
|
|
14
|
+
"version": "1.36.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.
|
|
27
|
+
"genkit": "^1.36.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@jest/globals": "^29.7.0",
|