@genkit-ai/compat-oai
Version:
Genkit AI framework plugin for OpenAI APIs.
1 lines • 3.89 kB
Source Map (JSON)
{"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 });\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: 'xai/grok-3',\n }),\n 'grok-3-fast': xaiModelRef({\n name: 'xai/grok-3-fast',\n }),\n 'grok-3-mini': xaiModelRef({\n name: 'xai/grok-3-mini',\n }),\n 'grok-3-mini-fast': xaiModelRef({\n name: 'xai/grok-3-mini-fast',\n }),\n 'grok-2-vision-1212': xaiModelRef({\n name: 'xai/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,EAChB,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;AA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