@langchain/xai 0.1.0 → 1.0.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat_models.cjs","names":["ChatOpenAICompletions","fields?: Partial<ChatXAIInput>","options: this[\"ParsedCallOptions\"]","request:\n | OpenAIClient.Chat.ChatCompletionCreateParamsStreaming\n | OpenAIClient.Chat.ChatCompletionCreateParamsNonStreaming","options?: OpenAICoreRequestOptions","delta: Record<string, any>","rawResponse: OpenAIClient.ChatCompletionChunk","defaultRole?:\n | \"function\"\n | \"user\"\n | \"system\"\n | \"developer\"\n | \"assistant\"\n | \"tool\"","messageChunk: AIMessageChunk","message: OpenAIClient.ChatCompletionMessage","rawResponse: OpenAIClient.ChatCompletion","outputSchema:\n | InteropZodType<RunOutput>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | Record<string, any>","config?: StructuredOutputMethodOptions<boolean>"],"sources":["../src/chat_models.ts"],"sourcesContent":["import {\n BaseLanguageModelInput,\n StructuredOutputMethodOptions,\n} from \"@langchain/core/language_models/base\";\nimport {\n BaseChatModelCallOptions,\n BindToolsInput,\n LangSmithParams,\n type BaseChatModelParams,\n} from \"@langchain/core/language_models/chat_models\";\nimport { Serialized } from \"@langchain/core/load/serializable\";\nimport { AIMessageChunk, BaseMessage } from \"@langchain/core/messages\";\nimport { Runnable } from \"@langchain/core/runnables\";\nimport { getEnvironmentVariable } from \"@langchain/core/utils/env\";\nimport { InteropZodType } from \"@langchain/core/utils/types\";\nimport {\n type OpenAICoreRequestOptions,\n type OpenAIClient,\n OpenAIToolChoice,\n ChatOpenAICompletions,\n} from \"@langchain/openai\";\n\ntype ChatXAIToolType = BindToolsInput | OpenAIClient.ChatCompletionTool;\n\nexport interface ChatXAICallOptions extends BaseChatModelCallOptions {\n headers?: Record<string, string>;\n tools?: ChatXAIToolType[];\n tool_choice?: OpenAIToolChoice | string | \"auto\" | \"any\";\n}\n\nexport interface ChatXAIInput extends BaseChatModelParams {\n /**\n * The xAI API key to use for requests.\n * @default process.env.XAI_API_KEY\n */\n apiKey?: string;\n /**\n * The name of the model to use.\n * @default \"grok-beta\"\n */\n model?: string;\n /**\n * Up to 4 sequences where the API will stop generating further tokens. The\n * returned text will not contain the stop sequence.\n * Alias for `stopSequences`\n */\n stop?: Array<string>;\n /**\n * Up to 4 sequences where the API will stop generating further tokens. The\n * returned text will not contain the stop sequence.\n */\n stopSequences?: Array<string>;\n /**\n * Whether or not to stream responses.\n */\n streaming?: boolean;\n /**\n * The temperature to use for sampling.\n * @default 0.7\n */\n temperature?: number;\n /**\n * The maximum number of tokens that the model can process in a single response.\n * This limits ensures computational efficiency and resource management.\n */\n maxTokens?: number;\n}\n\n/**\n * xAI chat model integration.\n *\n * The xAI API is compatible to the OpenAI API with some limitations.\n *\n * Setup:\n * Install `@langchain/xai` and set an environment variable named `XAI_API_KEY`.\n *\n * ```bash\n * npm install @langchain/xai\n * export XAI_API_KEY=\"your-api-key\"\n * ```\n *\n * ## [Constructor args](https://api.js.langchain.com/classes/_langchain_xai.ChatXAI.html#constructor)\n *\n * ## [Runtime args](https://api.js.langchain.com/interfaces/_langchain_xai.ChatXAICallOptions.html)\n *\n * Runtime args can be passed as the second argument to any of the base runnable methods `.invoke`. `.stream`, `.batch`, etc.\n * They can also be passed via `.withConfig`, or the second arg in `.bindTools`, like shown in the examples below:\n *\n * ```typescript\n * // When calling `.withConfig`, call options should be passed via the first argument\n * const llmWithArgsBound = llm.withConfig({\n * stop: [\"\\n\"],\n * tools: [...],\n * });\n *\n * // When calling `.bindTools`, call options should be passed via the second argument\n * const llmWithTools = llm.bindTools(\n * [...],\n * {\n * tool_choice: \"auto\",\n * }\n * );\n * ```\n *\n * ## Examples\n *\n * <details open>\n * <summary><strong>Instantiate</strong></summary>\n *\n * ```typescript\n * import { ChatXAI } from '@langchain/xai';\n *\n * const llm = new ChatXAI({\n * model: \"grok-beta\",\n * temperature: 0,\n * // other params...\n * });\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Invoking</strong></summary>\n *\n * ```typescript\n * const input = `Translate \"I love programming\" into French.`;\n *\n * // Models also accept a list of chat messages or a formatted prompt\n * const result = await llm.invoke(input);\n * console.log(result);\n * ```\n *\n * ```txt\n * AIMessage {\n * \"content\": \"The French translation of \\\"I love programming\\\" is \\\"J'aime programmer\\\". In this sentence, \\\"J'aime\\\" is the first person singular conjugation of the French verb \\\"aimer\\\" which means \\\"to love\\\", and \\\"programmer\\\" is the French infinitive for \\\"to program\\\". I hope this helps! Let me know if you have any other questions.\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {\n * \"tokenUsage\": {\n * \"completionTokens\": 82,\n * \"promptTokens\": 20,\n * \"totalTokens\": 102\n * },\n * \"finish_reason\": \"stop\"\n * },\n * \"tool_calls\": [],\n * \"invalid_tool_calls\": []\n * }\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Streaming Chunks</strong></summary>\n *\n * ```typescript\n * for await (const chunk of await llm.stream(input)) {\n * console.log(chunk);\n * }\n * ```\n *\n * ```txt\n * AIMessageChunk {\n * \"content\": \"\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {\n * \"finishReason\": null\n * },\n * \"tool_calls\": [],\n * \"tool_call_chunks\": [],\n * \"invalid_tool_calls\": []\n * }\n * AIMessageChunk {\n * \"content\": \"The\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {\n * \"finishReason\": null\n * },\n * \"tool_calls\": [],\n * \"tool_call_chunks\": [],\n * \"invalid_tool_calls\": []\n * }\n * AIMessageChunk {\n * \"content\": \" French\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {\n * \"finishReason\": null\n * },\n * \"tool_calls\": [],\n * \"tool_call_chunks\": [],\n * \"invalid_tool_calls\": []\n * }\n * AIMessageChunk {\n * \"content\": \" translation\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {\n * \"finishReason\": null\n * },\n * \"tool_calls\": [],\n * \"tool_call_chunks\": [],\n * \"invalid_tool_calls\": []\n * }\n * AIMessageChunk {\n * \"content\": \" of\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {\n * \"finishReason\": null\n * },\n * \"tool_calls\": [],\n * \"tool_call_chunks\": [],\n * \"invalid_tool_calls\": []\n * }\n * AIMessageChunk {\n * \"content\": \" \\\"\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {\n * \"finishReason\": null\n * },\n * \"tool_calls\": [],\n * \"tool_call_chunks\": [],\n * \"invalid_tool_calls\": []\n * }\n * AIMessageChunk {\n * \"content\": \"I\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {\n * \"finishReason\": null\n * },\n * \"tool_calls\": [],\n * \"tool_call_chunks\": [],\n * \"invalid_tool_calls\": []\n * }\n * AIMessageChunk {\n * \"content\": \" love\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {\n * \"finishReason\": null\n * },\n * \"tool_calls\": [],\n * \"tool_call_chunks\": [],\n * \"invalid_tool_calls\": []\n * }\n * ...\n * AIMessageChunk {\n * \"content\": \".\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {\n * \"finishReason\": null\n * },\n * \"tool_calls\": [],\n * \"tool_call_chunks\": [],\n * \"invalid_tool_calls\": []\n * }\n * AIMessageChunk {\n * \"content\": \"\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {\n * \"finishReason\": \"stop\"\n * },\n * \"tool_calls\": [],\n * \"tool_call_chunks\": [],\n * \"invalid_tool_calls\": []\n * }\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Aggregate Streamed Chunks</strong></summary>\n *\n * ```typescript\n * import { AIMessageChunk } from '@langchain/core/messages';\n * import { concat } from '@langchain/core/utils/stream';\n *\n * const stream = await llm.stream(input);\n * let full: AIMessageChunk | undefined;\n * for await (const chunk of stream) {\n * full = !full ? chunk : concat(full, chunk);\n * }\n * console.log(full);\n * ```\n *\n * ```txt\n * AIMessageChunk {\n * \"content\": \"The French translation of \\\"I love programming\\\" is \\\"J'aime programmer\\\". In this sentence, \\\"J'aime\\\" is the first person singular conjugation of the French verb \\\"aimer\\\" which means \\\"to love\\\", and \\\"programmer\\\" is the French infinitive for \\\"to program\\\". I hope this helps! Let me know if you have any other questions.\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {\n * \"finishReason\": \"stop\"\n * },\n * \"tool_calls\": [],\n * \"tool_call_chunks\": [],\n * \"invalid_tool_calls\": []\n * }\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Bind tools</strong></summary>\n *\n * ```typescript\n * import { z } from 'zod';\n *\n * const llmForToolCalling = new ChatXAI({\n * model: \"grok-beta\",\n * temperature: 0,\n * // other params...\n * });\n *\n * const GetWeather = {\n * name: \"GetWeather\",\n * description: \"Get the current weather in a given location\",\n * schema: z.object({\n * location: z.string().describe(\"The city and state, e.g. San Francisco, CA\")\n * }),\n * }\n *\n * const GetPopulation = {\n * name: \"GetPopulation\",\n * description: \"Get the current population in a given location\",\n * schema: z.object({\n * location: z.string().describe(\"The city and state, e.g. San Francisco, CA\")\n * }),\n * }\n *\n * const llmWithTools = llmForToolCalling.bindTools([GetWeather, GetPopulation]);\n * const aiMsg = await llmWithTools.invoke(\n * \"Which city is hotter today and which is bigger: LA or NY?\"\n * );\n * console.log(aiMsg.tool_calls);\n * ```\n *\n * ```txt\n * [\n * {\n * name: 'GetWeather',\n * args: { location: 'Los Angeles, CA' },\n * type: 'tool_call',\n * id: 'call_cd34'\n * },\n * {\n * name: 'GetWeather',\n * args: { location: 'New York, NY' },\n * type: 'tool_call',\n * id: 'call_68rf'\n * },\n * {\n * name: 'GetPopulation',\n * args: { location: 'Los Angeles, CA' },\n * type: 'tool_call',\n * id: 'call_f81z'\n * },\n * {\n * name: 'GetPopulation',\n * args: { location: 'New York, NY' },\n * type: 'tool_call',\n * id: 'call_8byt'\n * }\n * ]\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Structured Output</strong></summary>\n *\n * ```typescript\n * import { z } from 'zod';\n *\n * const Joke = z.object({\n * setup: z.string().describe(\"The setup of the joke\"),\n * punchline: z.string().describe(\"The punchline to the joke\"),\n * rating: z.number().optional().describe(\"How funny the joke is, from 1 to 10\")\n * }).describe('Joke to tell user.');\n *\n * const structuredLlm = llmForToolCalling.withStructuredOutput(Joke, { name: \"Joke\" });\n * const jokeResult = await structuredLlm.invoke(\"Tell me a joke about cats\");\n * console.log(jokeResult);\n * ```\n *\n * ```txt\n * {\n * setup: \"Why don't cats play poker in the wild?\",\n * punchline: 'Because there are too many cheetahs.'\n * }\n * ```\n * </details>\n *\n * <br />\n */\nexport class ChatXAI extends ChatOpenAICompletions<ChatXAICallOptions> {\n static lc_name() {\n return \"ChatXAI\";\n }\n\n _llmType() {\n return \"xai\";\n }\n\n get lc_secrets(): { [key: string]: string } | undefined {\n return {\n apiKey: \"XAI_API_KEY\",\n };\n }\n\n lc_serializable = true;\n\n lc_namespace = [\"langchain\", \"chat_models\", \"xai\"];\n\n constructor(fields?: Partial<ChatXAIInput>) {\n const apiKey = fields?.apiKey || getEnvironmentVariable(\"XAI_API_KEY\");\n if (!apiKey) {\n throw new Error(\n `xAI API key not found. Please set the XAI_API_KEY environment variable or provide the key into \"apiKey\" field.`\n );\n }\n\n super({\n ...fields,\n model: fields?.model || \"grok-beta\",\n apiKey,\n configuration: {\n baseURL: \"https://api.x.ai/v1\",\n },\n });\n }\n\n toJSON(): Serialized {\n const result = super.toJSON();\n\n if (\n \"kwargs\" in result &&\n typeof result.kwargs === \"object\" &&\n result.kwargs != null\n ) {\n delete result.kwargs.openai_api_key;\n delete result.kwargs.configuration;\n }\n\n return result;\n }\n\n getLsParams(options: this[\"ParsedCallOptions\"]): LangSmithParams {\n const params = super.getLsParams(options);\n params.ls_provider = \"xai\";\n return params;\n }\n\n async completionWithRetry(\n request: OpenAIClient.Chat.ChatCompletionCreateParamsStreaming,\n options?: OpenAICoreRequestOptions\n ): Promise<AsyncIterable<OpenAIClient.Chat.Completions.ChatCompletionChunk>>;\n\n async completionWithRetry(\n request: OpenAIClient.Chat.ChatCompletionCreateParamsNonStreaming,\n options?: OpenAICoreRequestOptions\n ): Promise<OpenAIClient.Chat.Completions.ChatCompletion>;\n\n /**\n * Calls the xAI API with retry logic in case of failures.\n * @param request The request to send to the xAI API.\n * @param options Optional configuration for the API call.\n * @returns The response from the xAI API.\n */\n async completionWithRetry(\n request:\n | OpenAIClient.Chat.ChatCompletionCreateParamsStreaming\n | OpenAIClient.Chat.ChatCompletionCreateParamsNonStreaming,\n options?: OpenAICoreRequestOptions\n ): Promise<\n | AsyncIterable<OpenAIClient.Chat.Completions.ChatCompletionChunk>\n | OpenAIClient.Chat.Completions.ChatCompletion\n > {\n delete request.frequency_penalty;\n delete request.presence_penalty;\n delete request.logit_bias;\n delete request.functions;\n\n const newRequestMessages = request.messages.map((msg) => {\n if (!msg.content) {\n return {\n ...msg,\n content: \"\",\n };\n }\n return msg;\n });\n\n const newRequest = {\n ...request,\n messages: newRequestMessages,\n };\n\n if (newRequest.stream === true) {\n return super.completionWithRetry(newRequest, options);\n }\n\n return super.completionWithRetry(newRequest, options);\n }\n\n protected override _convertCompletionsDeltaToBaseMessageChunk(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n delta: Record<string, any>,\n rawResponse: OpenAIClient.ChatCompletionChunk,\n defaultRole?:\n | \"function\"\n | \"user\"\n | \"system\"\n | \"developer\"\n | \"assistant\"\n | \"tool\"\n ) {\n const messageChunk: AIMessageChunk =\n super._convertCompletionsDeltaToBaseMessageChunk(\n delta,\n rawResponse,\n defaultRole\n );\n // Make concatenating chunks work without merge warning\n if (!rawResponse.choices[0]?.finish_reason) {\n delete messageChunk.response_metadata.usage;\n delete messageChunk.usage_metadata;\n } else {\n messageChunk.usage_metadata = messageChunk.response_metadata.usage;\n }\n return messageChunk;\n }\n\n protected override _convertCompletionsMessageToBaseMessage(\n message: OpenAIClient.ChatCompletionMessage,\n rawResponse: OpenAIClient.ChatCompletion\n ) {\n const langChainMessage = super._convertCompletionsMessageToBaseMessage(\n message,\n rawResponse\n );\n langChainMessage.additional_kwargs.reasoning_content =\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (message as any).reasoning_content;\n return langChainMessage;\n }\n\n override withStructuredOutput<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput extends Record<string, any> = Record<string, any>\n >(\n outputSchema:\n | InteropZodType<RunOutput>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | Record<string, any>,\n config?: StructuredOutputMethodOptions<false>\n ): Runnable<BaseLanguageModelInput, RunOutput>;\n\n override withStructuredOutput<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput extends Record<string, any> = Record<string, any>\n >(\n outputSchema:\n | InteropZodType<RunOutput>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | Record<string, any>,\n config?: StructuredOutputMethodOptions<true>\n ): Runnable<BaseLanguageModelInput, { raw: BaseMessage; parsed: RunOutput }>;\n\n override withStructuredOutput<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput extends Record<string, any> = Record<string, any>\n >(\n outputSchema:\n | InteropZodType<RunOutput>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | Record<string, any>,\n config?: StructuredOutputMethodOptions<boolean>\n ):\n | Runnable<BaseLanguageModelInput, RunOutput>\n | Runnable<BaseLanguageModelInput, { raw: BaseMessage; parsed: RunOutput }>;\n\n override withStructuredOutput<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput extends Record<string, any> = Record<string, any>\n >(\n outputSchema:\n | InteropZodType<RunOutput>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | Record<string, any>,\n config?: StructuredOutputMethodOptions<boolean>\n ):\n | Runnable<BaseLanguageModelInput, RunOutput>\n | Runnable<\n BaseLanguageModelInput,\n { raw: BaseMessage; parsed: RunOutput }\n > {\n const ensuredConfig = { ...config };\n if (ensuredConfig?.method === undefined) {\n ensuredConfig.method = \"functionCalling\";\n }\n return super.withStructuredOutput<RunOutput>(outputSchema, ensuredConfig);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0YA,IAAa,UAAb,cAA6BA,yCAA0C;CACrE,OAAO,UAAU;AACf,SAAO;CACR;CAED,WAAW;AACT,SAAO;CACR;CAED,IAAI,aAAoD;AACtD,SAAO,EACL,QAAQ,cACT;CACF;CAED,kBAAkB;CAElB,eAAe;EAAC;EAAa;EAAe;CAAM;CAElD,YAAYC,QAAgC;EAC1C,MAAM,SAAS,QAAQ,iEAAiC,cAAc;AACtE,MAAI,CAAC,OACH,OAAM,IAAI,MACR,CAAC,8GAA8G,CAAC;EAIpH,MAAM;GACJ,GAAG;GACH,OAAO,QAAQ,SAAS;GACxB;GACA,eAAe,EACb,SAAS,sBACV;EACF,EAAC;CACH;CAED,SAAqB;EACnB,MAAM,SAAS,MAAM,QAAQ;AAE7B,MACE,YAAY,UACZ,OAAO,OAAO,WAAW,YACzB,OAAO,UAAU,MACjB;GACA,OAAO,OAAO,OAAO;GACrB,OAAO,OAAO,OAAO;EACtB;AAED,SAAO;CACR;CAED,YAAYC,SAAqD;EAC/D,MAAM,SAAS,MAAM,YAAY,QAAQ;EACzC,OAAO,cAAc;AACrB,SAAO;CACR;;;;;;;CAkBD,MAAM,oBACJC,SAGAC,SAIA;EACA,OAAO,QAAQ;EACf,OAAO,QAAQ;EACf,OAAO,QAAQ;EACf,OAAO,QAAQ;EAEf,MAAM,qBAAqB,QAAQ,SAAS,IAAI,CAAC,QAAQ;AACvD,OAAI,CAAC,IAAI,QACP,QAAO;IACL,GAAG;IACH,SAAS;GACV;AAEH,UAAO;EACR,EAAC;EAEF,MAAM,aAAa;GACjB,GAAG;GACH,UAAU;EACX;AAED,MAAI,WAAW,WAAW,KACxB,QAAO,MAAM,oBAAoB,YAAY,QAAQ;AAGvD,SAAO,MAAM,oBAAoB,YAAY,QAAQ;CACtD;CAED,AAAmB,2CAEjBC,OACAC,aACAC,aAOA;EACA,MAAMC,eACJ,MAAM,2CACJ,OACA,aACA,YACD;AAEH,MAAI,CAAC,YAAY,QAAQ,IAAI,eAAe;GAC1C,OAAO,aAAa,kBAAkB;GACtC,OAAO,aAAa;EACrB,OACC,aAAa,iBAAiB,aAAa,kBAAkB;AAE/D,SAAO;CACR;CAED,AAAmB,wCACjBC,SACAC,aACA;EACA,MAAM,mBAAmB,MAAM,wCAC7B,SACA,YACD;EACD,iBAAiB,kBAAkB,oBAEhC,QAAgB;AACnB,SAAO;CACR;CAqCD,AAAS,qBAIPC,cAIAC,QAMI;EACJ,MAAM,gBAAgB,EAAE,GAAG,OAAQ;AACnC,MAAI,eAAe,WAAW,QAC5B,cAAc,SAAS;AAEzB,SAAO,MAAM,qBAAgC,cAAc,cAAc;CAC1E;AACF"}
@@ -0,0 +1,421 @@
1
+ import * as _langchain_core_messages0 from "@langchain/core/messages";
2
+ import { AIMessageChunk, BaseMessage } from "@langchain/core/messages";
3
+ import { BaseLanguageModelInput, StructuredOutputMethodOptions } from "@langchain/core/language_models/base";
4
+ import { BaseChatModelCallOptions, BaseChatModelParams, BindToolsInput, LangSmithParams } from "@langchain/core/language_models/chat_models";
5
+ import { Serialized } from "@langchain/core/load/serializable";
6
+ import { Runnable } from "@langchain/core/runnables";
7
+ import { InteropZodType } from "@langchain/core/utils/types";
8
+ import { ChatOpenAICompletions, OpenAIClient, OpenAICoreRequestOptions, OpenAIToolChoice } from "@langchain/openai";
9
+
10
+ //#region src/chat_models.d.ts
11
+ type ChatXAIToolType = BindToolsInput | OpenAIClient.ChatCompletionTool;
12
+ interface ChatXAICallOptions extends BaseChatModelCallOptions {
13
+ headers?: Record<string, string>;
14
+ tools?: ChatXAIToolType[];
15
+ tool_choice?: OpenAIToolChoice | string | "auto" | "any";
16
+ }
17
+ interface ChatXAIInput extends BaseChatModelParams {
18
+ /**
19
+ * The xAI API key to use for requests.
20
+ * @default process.env.XAI_API_KEY
21
+ */
22
+ apiKey?: string;
23
+ /**
24
+ * The name of the model to use.
25
+ * @default "grok-beta"
26
+ */
27
+ model?: string;
28
+ /**
29
+ * Up to 4 sequences where the API will stop generating further tokens. The
30
+ * returned text will not contain the stop sequence.
31
+ * Alias for `stopSequences`
32
+ */
33
+ stop?: Array<string>;
34
+ /**
35
+ * Up to 4 sequences where the API will stop generating further tokens. The
36
+ * returned text will not contain the stop sequence.
37
+ */
38
+ stopSequences?: Array<string>;
39
+ /**
40
+ * Whether or not to stream responses.
41
+ */
42
+ streaming?: boolean;
43
+ /**
44
+ * The temperature to use for sampling.
45
+ * @default 0.7
46
+ */
47
+ temperature?: number;
48
+ /**
49
+ * The maximum number of tokens that the model can process in a single response.
50
+ * This limits ensures computational efficiency and resource management.
51
+ */
52
+ maxTokens?: number;
53
+ }
54
+ /**
55
+ * xAI chat model integration.
56
+ *
57
+ * The xAI API is compatible to the OpenAI API with some limitations.
58
+ *
59
+ * Setup:
60
+ * Install `@langchain/xai` and set an environment variable named `XAI_API_KEY`.
61
+ *
62
+ * ```bash
63
+ * npm install @langchain/xai
64
+ * export XAI_API_KEY="your-api-key"
65
+ * ```
66
+ *
67
+ * ## [Constructor args](https://api.js.langchain.com/classes/_langchain_xai.ChatXAI.html#constructor)
68
+ *
69
+ * ## [Runtime args](https://api.js.langchain.com/interfaces/_langchain_xai.ChatXAICallOptions.html)
70
+ *
71
+ * Runtime args can be passed as the second argument to any of the base runnable methods `.invoke`. `.stream`, `.batch`, etc.
72
+ * They can also be passed via `.withConfig`, or the second arg in `.bindTools`, like shown in the examples below:
73
+ *
74
+ * ```typescript
75
+ * // When calling `.withConfig`, call options should be passed via the first argument
76
+ * const llmWithArgsBound = llm.withConfig({
77
+ * stop: ["\n"],
78
+ * tools: [...],
79
+ * });
80
+ *
81
+ * // When calling `.bindTools`, call options should be passed via the second argument
82
+ * const llmWithTools = llm.bindTools(
83
+ * [...],
84
+ * {
85
+ * tool_choice: "auto",
86
+ * }
87
+ * );
88
+ * ```
89
+ *
90
+ * ## Examples
91
+ *
92
+ * <details open>
93
+ * <summary><strong>Instantiate</strong></summary>
94
+ *
95
+ * ```typescript
96
+ * import { ChatXAI } from '@langchain/xai';
97
+ *
98
+ * const llm = new ChatXAI({
99
+ * model: "grok-beta",
100
+ * temperature: 0,
101
+ * // other params...
102
+ * });
103
+ * ```
104
+ * </details>
105
+ *
106
+ * <br />
107
+ *
108
+ * <details>
109
+ * <summary><strong>Invoking</strong></summary>
110
+ *
111
+ * ```typescript
112
+ * const input = `Translate "I love programming" into French.`;
113
+ *
114
+ * // Models also accept a list of chat messages or a formatted prompt
115
+ * const result = await llm.invoke(input);
116
+ * console.log(result);
117
+ * ```
118
+ *
119
+ * ```txt
120
+ * AIMessage {
121
+ * "content": "The French translation of \"I love programming\" is \"J'aime programmer\". In this sentence, \"J'aime\" is the first person singular conjugation of the French verb \"aimer\" which means \"to love\", and \"programmer\" is the French infinitive for \"to program\". I hope this helps! Let me know if you have any other questions.",
122
+ * "additional_kwargs": {},
123
+ * "response_metadata": {
124
+ * "tokenUsage": {
125
+ * "completionTokens": 82,
126
+ * "promptTokens": 20,
127
+ * "totalTokens": 102
128
+ * },
129
+ * "finish_reason": "stop"
130
+ * },
131
+ * "tool_calls": [],
132
+ * "invalid_tool_calls": []
133
+ * }
134
+ * ```
135
+ * </details>
136
+ *
137
+ * <br />
138
+ *
139
+ * <details>
140
+ * <summary><strong>Streaming Chunks</strong></summary>
141
+ *
142
+ * ```typescript
143
+ * for await (const chunk of await llm.stream(input)) {
144
+ * console.log(chunk);
145
+ * }
146
+ * ```
147
+ *
148
+ * ```txt
149
+ * AIMessageChunk {
150
+ * "content": "",
151
+ * "additional_kwargs": {},
152
+ * "response_metadata": {
153
+ * "finishReason": null
154
+ * },
155
+ * "tool_calls": [],
156
+ * "tool_call_chunks": [],
157
+ * "invalid_tool_calls": []
158
+ * }
159
+ * AIMessageChunk {
160
+ * "content": "The",
161
+ * "additional_kwargs": {},
162
+ * "response_metadata": {
163
+ * "finishReason": null
164
+ * },
165
+ * "tool_calls": [],
166
+ * "tool_call_chunks": [],
167
+ * "invalid_tool_calls": []
168
+ * }
169
+ * AIMessageChunk {
170
+ * "content": " French",
171
+ * "additional_kwargs": {},
172
+ * "response_metadata": {
173
+ * "finishReason": null
174
+ * },
175
+ * "tool_calls": [],
176
+ * "tool_call_chunks": [],
177
+ * "invalid_tool_calls": []
178
+ * }
179
+ * AIMessageChunk {
180
+ * "content": " translation",
181
+ * "additional_kwargs": {},
182
+ * "response_metadata": {
183
+ * "finishReason": null
184
+ * },
185
+ * "tool_calls": [],
186
+ * "tool_call_chunks": [],
187
+ * "invalid_tool_calls": []
188
+ * }
189
+ * AIMessageChunk {
190
+ * "content": " of",
191
+ * "additional_kwargs": {},
192
+ * "response_metadata": {
193
+ * "finishReason": null
194
+ * },
195
+ * "tool_calls": [],
196
+ * "tool_call_chunks": [],
197
+ * "invalid_tool_calls": []
198
+ * }
199
+ * AIMessageChunk {
200
+ * "content": " \"",
201
+ * "additional_kwargs": {},
202
+ * "response_metadata": {
203
+ * "finishReason": null
204
+ * },
205
+ * "tool_calls": [],
206
+ * "tool_call_chunks": [],
207
+ * "invalid_tool_calls": []
208
+ * }
209
+ * AIMessageChunk {
210
+ * "content": "I",
211
+ * "additional_kwargs": {},
212
+ * "response_metadata": {
213
+ * "finishReason": null
214
+ * },
215
+ * "tool_calls": [],
216
+ * "tool_call_chunks": [],
217
+ * "invalid_tool_calls": []
218
+ * }
219
+ * AIMessageChunk {
220
+ * "content": " love",
221
+ * "additional_kwargs": {},
222
+ * "response_metadata": {
223
+ * "finishReason": null
224
+ * },
225
+ * "tool_calls": [],
226
+ * "tool_call_chunks": [],
227
+ * "invalid_tool_calls": []
228
+ * }
229
+ * ...
230
+ * AIMessageChunk {
231
+ * "content": ".",
232
+ * "additional_kwargs": {},
233
+ * "response_metadata": {
234
+ * "finishReason": null
235
+ * },
236
+ * "tool_calls": [],
237
+ * "tool_call_chunks": [],
238
+ * "invalid_tool_calls": []
239
+ * }
240
+ * AIMessageChunk {
241
+ * "content": "",
242
+ * "additional_kwargs": {},
243
+ * "response_metadata": {
244
+ * "finishReason": "stop"
245
+ * },
246
+ * "tool_calls": [],
247
+ * "tool_call_chunks": [],
248
+ * "invalid_tool_calls": []
249
+ * }
250
+ * ```
251
+ * </details>
252
+ *
253
+ * <br />
254
+ *
255
+ * <details>
256
+ * <summary><strong>Aggregate Streamed Chunks</strong></summary>
257
+ *
258
+ * ```typescript
259
+ * import { AIMessageChunk } from '@langchain/core/messages';
260
+ * import { concat } from '@langchain/core/utils/stream';
261
+ *
262
+ * const stream = await llm.stream(input);
263
+ * let full: AIMessageChunk | undefined;
264
+ * for await (const chunk of stream) {
265
+ * full = !full ? chunk : concat(full, chunk);
266
+ * }
267
+ * console.log(full);
268
+ * ```
269
+ *
270
+ * ```txt
271
+ * AIMessageChunk {
272
+ * "content": "The French translation of \"I love programming\" is \"J'aime programmer\". In this sentence, \"J'aime\" is the first person singular conjugation of the French verb \"aimer\" which means \"to love\", and \"programmer\" is the French infinitive for \"to program\". I hope this helps! Let me know if you have any other questions.",
273
+ * "additional_kwargs": {},
274
+ * "response_metadata": {
275
+ * "finishReason": "stop"
276
+ * },
277
+ * "tool_calls": [],
278
+ * "tool_call_chunks": [],
279
+ * "invalid_tool_calls": []
280
+ * }
281
+ * ```
282
+ * </details>
283
+ *
284
+ * <br />
285
+ *
286
+ * <details>
287
+ * <summary><strong>Bind tools</strong></summary>
288
+ *
289
+ * ```typescript
290
+ * import { z } from 'zod';
291
+ *
292
+ * const llmForToolCalling = new ChatXAI({
293
+ * model: "grok-beta",
294
+ * temperature: 0,
295
+ * // other params...
296
+ * });
297
+ *
298
+ * const GetWeather = {
299
+ * name: "GetWeather",
300
+ * description: "Get the current weather in a given location",
301
+ * schema: z.object({
302
+ * location: z.string().describe("The city and state, e.g. San Francisco, CA")
303
+ * }),
304
+ * }
305
+ *
306
+ * const GetPopulation = {
307
+ * name: "GetPopulation",
308
+ * description: "Get the current population in a given location",
309
+ * schema: z.object({
310
+ * location: z.string().describe("The city and state, e.g. San Francisco, CA")
311
+ * }),
312
+ * }
313
+ *
314
+ * const llmWithTools = llmForToolCalling.bindTools([GetWeather, GetPopulation]);
315
+ * const aiMsg = await llmWithTools.invoke(
316
+ * "Which city is hotter today and which is bigger: LA or NY?"
317
+ * );
318
+ * console.log(aiMsg.tool_calls);
319
+ * ```
320
+ *
321
+ * ```txt
322
+ * [
323
+ * {
324
+ * name: 'GetWeather',
325
+ * args: { location: 'Los Angeles, CA' },
326
+ * type: 'tool_call',
327
+ * id: 'call_cd34'
328
+ * },
329
+ * {
330
+ * name: 'GetWeather',
331
+ * args: { location: 'New York, NY' },
332
+ * type: 'tool_call',
333
+ * id: 'call_68rf'
334
+ * },
335
+ * {
336
+ * name: 'GetPopulation',
337
+ * args: { location: 'Los Angeles, CA' },
338
+ * type: 'tool_call',
339
+ * id: 'call_f81z'
340
+ * },
341
+ * {
342
+ * name: 'GetPopulation',
343
+ * args: { location: 'New York, NY' },
344
+ * type: 'tool_call',
345
+ * id: 'call_8byt'
346
+ * }
347
+ * ]
348
+ * ```
349
+ * </details>
350
+ *
351
+ * <br />
352
+ *
353
+ * <details>
354
+ * <summary><strong>Structured Output</strong></summary>
355
+ *
356
+ * ```typescript
357
+ * import { z } from 'zod';
358
+ *
359
+ * const Joke = z.object({
360
+ * setup: z.string().describe("The setup of the joke"),
361
+ * punchline: z.string().describe("The punchline to the joke"),
362
+ * rating: z.number().optional().describe("How funny the joke is, from 1 to 10")
363
+ * }).describe('Joke to tell user.');
364
+ *
365
+ * const structuredLlm = llmForToolCalling.withStructuredOutput(Joke, { name: "Joke" });
366
+ * const jokeResult = await structuredLlm.invoke("Tell me a joke about cats");
367
+ * console.log(jokeResult);
368
+ * ```
369
+ *
370
+ * ```txt
371
+ * {
372
+ * setup: "Why don't cats play poker in the wild?",
373
+ * punchline: 'Because there are too many cheetahs.'
374
+ * }
375
+ * ```
376
+ * </details>
377
+ *
378
+ * <br />
379
+ */
380
+ declare class ChatXAI extends ChatOpenAICompletions<ChatXAICallOptions> {
381
+ static lc_name(): string;
382
+ _llmType(): string;
383
+ get lc_secrets(): {
384
+ [key: string]: string;
385
+ } | undefined;
386
+ lc_serializable: boolean;
387
+ lc_namespace: string[];
388
+ constructor(fields?: Partial<ChatXAIInput>);
389
+ toJSON(): Serialized;
390
+ getLsParams(options: this["ParsedCallOptions"]): LangSmithParams;
391
+ completionWithRetry(request: OpenAIClient.Chat.ChatCompletionCreateParamsStreaming, options?: OpenAICoreRequestOptions): Promise<AsyncIterable<OpenAIClient.Chat.Completions.ChatCompletionChunk>>;
392
+ completionWithRetry(request: OpenAIClient.Chat.ChatCompletionCreateParamsNonStreaming, options?: OpenAICoreRequestOptions): Promise<OpenAIClient.Chat.Completions.ChatCompletion>;
393
+ protected _convertCompletionsDeltaToBaseMessageChunk(
394
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
395
+ delta: Record<string, any>, rawResponse: OpenAIClient.ChatCompletionChunk, defaultRole?: "function" | "user" | "system" | "developer" | "assistant" | "tool"): AIMessageChunk<_langchain_core_messages0.MessageStructure>;
396
+ protected _convertCompletionsMessageToBaseMessage(message: OpenAIClient.ChatCompletionMessage, rawResponse: OpenAIClient.ChatCompletion): BaseMessage<_langchain_core_messages0.MessageStructure, _langchain_core_messages0.MessageType>;
397
+ withStructuredOutput<
398
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
399
+ RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput>
400
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
401
+ | Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;
402
+ withStructuredOutput<
403
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
404
+ RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput>
405
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
406
+ | Record<string, any>, config?: StructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {
407
+ raw: BaseMessage;
408
+ parsed: RunOutput;
409
+ }>;
410
+ withStructuredOutput<
411
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
412
+ RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput>
413
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
414
+ | Record<string, any>, config?: StructuredOutputMethodOptions<boolean>): Runnable<BaseLanguageModelInput, RunOutput> | Runnable<BaseLanguageModelInput, {
415
+ raw: BaseMessage;
416
+ parsed: RunOutput;
417
+ }>;
418
+ }
419
+ //#endregion
420
+ export { ChatXAI, ChatXAICallOptions, ChatXAIInput };
421
+ //# sourceMappingURL=chat_models.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat_models.d.cts","names":["BaseLanguageModelInput","StructuredOutputMethodOptions","BaseChatModelCallOptions","BindToolsInput","LangSmithParams","BaseChatModelParams","Serialized","AIMessageChunk","BaseMessage","Runnable","InteropZodType","OpenAICoreRequestOptions","OpenAIClient","OpenAIToolChoice","ChatOpenAICompletions","ChatXAIToolType","ChatCompletionTool","ChatXAICallOptions","Record","ChatXAIInput","Array","ChatXAI","Partial","Chat","ChatCompletionCreateParamsStreaming","Completions","ChatCompletionChunk","AsyncIterable","Promise","ChatCompletionCreateParamsNonStreaming","ChatCompletion","_langchain_core_messages0","MessageStructure","ChatCompletionMessage","MessageType","RunOutput"],"sources":["../src/chat_models.d.ts"],"sourcesContent":["import { BaseLanguageModelInput, StructuredOutputMethodOptions } from \"@langchain/core/language_models/base\";\nimport { BaseChatModelCallOptions, BindToolsInput, LangSmithParams, type BaseChatModelParams } from \"@langchain/core/language_models/chat_models\";\nimport { Serialized } from \"@langchain/core/load/serializable\";\nimport { AIMessageChunk, BaseMessage } from \"@langchain/core/messages\";\nimport { Runnable } from \"@langchain/core/runnables\";\nimport { InteropZodType } from \"@langchain/core/utils/types\";\nimport { type OpenAICoreRequestOptions, type OpenAIClient, OpenAIToolChoice, ChatOpenAICompletions } from \"@langchain/openai\";\ntype ChatXAIToolType = BindToolsInput | OpenAIClient.ChatCompletionTool;\nexport interface ChatXAICallOptions extends BaseChatModelCallOptions {\n headers?: Record<string, string>;\n tools?: ChatXAIToolType[];\n tool_choice?: OpenAIToolChoice | string | \"auto\" | \"any\";\n}\nexport interface ChatXAIInput extends BaseChatModelParams {\n /**\n * The xAI API key to use for requests.\n * @default process.env.XAI_API_KEY\n */\n apiKey?: string;\n /**\n * The name of the model to use.\n * @default \"grok-beta\"\n */\n model?: string;\n /**\n * Up to 4 sequences where the API will stop generating further tokens. The\n * returned text will not contain the stop sequence.\n * Alias for `stopSequences`\n */\n stop?: Array<string>;\n /**\n * Up to 4 sequences where the API will stop generating further tokens. The\n * returned text will not contain the stop sequence.\n */\n stopSequences?: Array<string>;\n /**\n * Whether or not to stream responses.\n */\n streaming?: boolean;\n /**\n * The temperature to use for sampling.\n * @default 0.7\n */\n temperature?: number;\n /**\n * The maximum number of tokens that the model can process in a single response.\n * This limits ensures computational efficiency and resource management.\n */\n maxTokens?: number;\n}\n/**\n * xAI chat model integration.\n *\n * The xAI API is compatible to the OpenAI API with some limitations.\n *\n * Setup:\n * Install `@langchain/xai` and set an environment variable named `XAI_API_KEY`.\n *\n * ```bash\n * npm install @langchain/xai\n * export XAI_API_KEY=\"your-api-key\"\n * ```\n *\n * ## [Constructor args](https://api.js.langchain.com/classes/_langchain_xai.ChatXAI.html#constructor)\n *\n * ## [Runtime args](https://api.js.langchain.com/interfaces/_langchain_xai.ChatXAICallOptions.html)\n *\n * Runtime args can be passed as the second argument to any of the base runnable methods `.invoke`. `.stream`, `.batch`, etc.\n * They can also be passed via `.withConfig`, or the second arg in `.bindTools`, like shown in the examples below:\n *\n * ```typescript\n * // When calling `.withConfig`, call options should be passed via the first argument\n * const llmWithArgsBound = llm.withConfig({\n * stop: [\"\\n\"],\n * tools: [...],\n * });\n *\n * // When calling `.bindTools`, call options should be passed via the second argument\n * const llmWithTools = llm.bindTools(\n * [...],\n * {\n * tool_choice: \"auto\",\n * }\n * );\n * ```\n *\n * ## Examples\n *\n * <details open>\n * <summary><strong>Instantiate</strong></summary>\n *\n * ```typescript\n * import { ChatXAI } from '@langchain/xai';\n *\n * const llm = new ChatXAI({\n * model: \"grok-beta\",\n * temperature: 0,\n * // other params...\n * });\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Invoking</strong></summary>\n *\n * ```typescript\n * const input = `Translate \"I love programming\" into French.`;\n *\n * // Models also accept a list of chat messages or a formatted prompt\n * const result = await llm.invoke(input);\n * console.log(result);\n * ```\n *\n * ```txt\n * AIMessage {\n * \"content\": \"The French translation of \\\"I love programming\\\" is \\\"J'aime programmer\\\". In this sentence, \\\"J'aime\\\" is the first person singular conjugation of the French verb \\\"aimer\\\" which means \\\"to love\\\", and \\\"programmer\\\" is the French infinitive for \\\"to program\\\". I hope this helps! Let me know if you have any other questions.\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {\n * \"tokenUsage\": {\n * \"completionTokens\": 82,\n * \"promptTokens\": 20,\n * \"totalTokens\": 102\n * },\n * \"finish_reason\": \"stop\"\n * },\n * \"tool_calls\": [],\n * \"invalid_tool_calls\": []\n * }\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Streaming Chunks</strong></summary>\n *\n * ```typescript\n * for await (const chunk of await llm.stream(input)) {\n * console.log(chunk);\n * }\n * ```\n *\n * ```txt\n * AIMessageChunk {\n * \"content\": \"\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {\n * \"finishReason\": null\n * },\n * \"tool_calls\": [],\n * \"tool_call_chunks\": [],\n * \"invalid_tool_calls\": []\n * }\n * AIMessageChunk {\n * \"content\": \"The\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {\n * \"finishReason\": null\n * },\n * \"tool_calls\": [],\n * \"tool_call_chunks\": [],\n * \"invalid_tool_calls\": []\n * }\n * AIMessageChunk {\n * \"content\": \" French\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {\n * \"finishReason\": null\n * },\n * \"tool_calls\": [],\n * \"tool_call_chunks\": [],\n * \"invalid_tool_calls\": []\n * }\n * AIMessageChunk {\n * \"content\": \" translation\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {\n * \"finishReason\": null\n * },\n * \"tool_calls\": [],\n * \"tool_call_chunks\": [],\n * \"invalid_tool_calls\": []\n * }\n * AIMessageChunk {\n * \"content\": \" of\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {\n * \"finishReason\": null\n * },\n * \"tool_calls\": [],\n * \"tool_call_chunks\": [],\n * \"invalid_tool_calls\": []\n * }\n * AIMessageChunk {\n * \"content\": \" \\\"\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {\n * \"finishReason\": null\n * },\n * \"tool_calls\": [],\n * \"tool_call_chunks\": [],\n * \"invalid_tool_calls\": []\n * }\n * AIMessageChunk {\n * \"content\": \"I\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {\n * \"finishReason\": null\n * },\n * \"tool_calls\": [],\n * \"tool_call_chunks\": [],\n * \"invalid_tool_calls\": []\n * }\n * AIMessageChunk {\n * \"content\": \" love\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {\n * \"finishReason\": null\n * },\n * \"tool_calls\": [],\n * \"tool_call_chunks\": [],\n * \"invalid_tool_calls\": []\n * }\n * ...\n * AIMessageChunk {\n * \"content\": \".\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {\n * \"finishReason\": null\n * },\n * \"tool_calls\": [],\n * \"tool_call_chunks\": [],\n * \"invalid_tool_calls\": []\n * }\n * AIMessageChunk {\n * \"content\": \"\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {\n * \"finishReason\": \"stop\"\n * },\n * \"tool_calls\": [],\n * \"tool_call_chunks\": [],\n * \"invalid_tool_calls\": []\n * }\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Aggregate Streamed Chunks</strong></summary>\n *\n * ```typescript\n * import { AIMessageChunk } from '@langchain/core/messages';\n * import { concat } from '@langchain/core/utils/stream';\n *\n * const stream = await llm.stream(input);\n * let full: AIMessageChunk | undefined;\n * for await (const chunk of stream) {\n * full = !full ? chunk : concat(full, chunk);\n * }\n * console.log(full);\n * ```\n *\n * ```txt\n * AIMessageChunk {\n * \"content\": \"The French translation of \\\"I love programming\\\" is \\\"J'aime programmer\\\". In this sentence, \\\"J'aime\\\" is the first person singular conjugation of the French verb \\\"aimer\\\" which means \\\"to love\\\", and \\\"programmer\\\" is the French infinitive for \\\"to program\\\". I hope this helps! Let me know if you have any other questions.\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {\n * \"finishReason\": \"stop\"\n * },\n * \"tool_calls\": [],\n * \"tool_call_chunks\": [],\n * \"invalid_tool_calls\": []\n * }\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Bind tools</strong></summary>\n *\n * ```typescript\n * import { z } from 'zod';\n *\n * const llmForToolCalling = new ChatXAI({\n * model: \"grok-beta\",\n * temperature: 0,\n * // other params...\n * });\n *\n * const GetWeather = {\n * name: \"GetWeather\",\n * description: \"Get the current weather in a given location\",\n * schema: z.object({\n * location: z.string().describe(\"The city and state, e.g. San Francisco, CA\")\n * }),\n * }\n *\n * const GetPopulation = {\n * name: \"GetPopulation\",\n * description: \"Get the current population in a given location\",\n * schema: z.object({\n * location: z.string().describe(\"The city and state, e.g. San Francisco, CA\")\n * }),\n * }\n *\n * const llmWithTools = llmForToolCalling.bindTools([GetWeather, GetPopulation]);\n * const aiMsg = await llmWithTools.invoke(\n * \"Which city is hotter today and which is bigger: LA or NY?\"\n * );\n * console.log(aiMsg.tool_calls);\n * ```\n *\n * ```txt\n * [\n * {\n * name: 'GetWeather',\n * args: { location: 'Los Angeles, CA' },\n * type: 'tool_call',\n * id: 'call_cd34'\n * },\n * {\n * name: 'GetWeather',\n * args: { location: 'New York, NY' },\n * type: 'tool_call',\n * id: 'call_68rf'\n * },\n * {\n * name: 'GetPopulation',\n * args: { location: 'Los Angeles, CA' },\n * type: 'tool_call',\n * id: 'call_f81z'\n * },\n * {\n * name: 'GetPopulation',\n * args: { location: 'New York, NY' },\n * type: 'tool_call',\n * id: 'call_8byt'\n * }\n * ]\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Structured Output</strong></summary>\n *\n * ```typescript\n * import { z } from 'zod';\n *\n * const Joke = z.object({\n * setup: z.string().describe(\"The setup of the joke\"),\n * punchline: z.string().describe(\"The punchline to the joke\"),\n * rating: z.number().optional().describe(\"How funny the joke is, from 1 to 10\")\n * }).describe('Joke to tell user.');\n *\n * const structuredLlm = llmForToolCalling.withStructuredOutput(Joke, { name: \"Joke\" });\n * const jokeResult = await structuredLlm.invoke(\"Tell me a joke about cats\");\n * console.log(jokeResult);\n * ```\n *\n * ```txt\n * {\n * setup: \"Why don't cats play poker in the wild?\",\n * punchline: 'Because there are too many cheetahs.'\n * }\n * ```\n * </details>\n *\n * <br />\n */\nexport declare class ChatXAI extends ChatOpenAICompletions<ChatXAICallOptions> {\n static lc_name(): string;\n _llmType(): string;\n get lc_secrets(): {\n [key: string]: string;\n } | undefined;\n lc_serializable: boolean;\n lc_namespace: string[];\n constructor(fields?: Partial<ChatXAIInput>);\n toJSON(): Serialized;\n getLsParams(options: this[\"ParsedCallOptions\"]): LangSmithParams;\n completionWithRetry(request: OpenAIClient.Chat.ChatCompletionCreateParamsStreaming, options?: OpenAICoreRequestOptions): Promise<AsyncIterable<OpenAIClient.Chat.Completions.ChatCompletionChunk>>;\n completionWithRetry(request: OpenAIClient.Chat.ChatCompletionCreateParamsNonStreaming, options?: OpenAICoreRequestOptions): Promise<OpenAIClient.Chat.Completions.ChatCompletion>;\n protected _convertCompletionsDeltaToBaseMessageChunk(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n delta: Record<string, any>, rawResponse: OpenAIClient.ChatCompletionChunk, defaultRole?: \"function\" | \"user\" | \"system\" | \"developer\" | \"assistant\" | \"tool\"): AIMessageChunk<import(\"@langchain/core/messages\").MessageStructure>;\n protected _convertCompletionsMessageToBaseMessage(message: OpenAIClient.ChatCompletionMessage, rawResponse: OpenAIClient.ChatCompletion): BaseMessage<import(\"@langchain/core/messages\").MessageStructure, import(\"@langchain/core/messages\").MessageType>;\n withStructuredOutput<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;\n withStructuredOutput<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | Record<string, any>, config?: StructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {\n raw: BaseMessage;\n parsed: RunOutput;\n }>;\n withStructuredOutput<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | Record<string, any>, config?: StructuredOutputMethodOptions<boolean>): Runnable<BaseLanguageModelInput, RunOutput> | Runnable<BaseLanguageModelInput, {\n raw: BaseMessage;\n parsed: RunOutput;\n }>;\n}\nexport {};\n"],"mappings":";;;;;;;;;;KAOKe,eAAAA,GAAkBZ,iBAAiBS,YAAAA,CAAaI;UACpCC,kBAAAA,SAA2Bf;YAC9BgB;EAFTH,KAAAA,CAAAA,EAGOA,eAHQ,EAAA;EAAA,WAAA,CAAA,EAIFF,gBAJE,GAAA,MAAA,GAAA,MAAA,GAAA,KAAA;;AAAoBD,UAMvBO,YAAAA,SAAqBd,mBANeW,CAAAA;EAAkB;AACvE;;;EACoB,MACRD,CAAAA,EAAAA,MAAAA;EAAe;;AAFyC;AAKpE;EAA6B,KAAA,CAAA,EAAA,MAAA;EAAA;;;AAA4B;AA2WzD;EAA4B,IAAA,CAAA,EA3VjBK,KA2ViB,CAAA,MAAA,CAAA;EAAA;;;;EASJ,aAC6BhB,CAAAA,EAhWjCgB,KAgWiChB,CAAAA,MAAAA,CAAAA;EAAe;;;EACgI,SAA/DuB,CAAAA,EAAAA,OAAAA;EAAa;;;;EACkC,WAApDC,CAAAA,EAAAA,MAAAA;EAAO;;;;EAG0C,SAClHhB,CAAAA,EAAAA,MAAaqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAhBlB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAArCZ,OAAAA,SAAgBP,sBAAsBG;;;;;;;;uBAQlCK,QAAQH;YACnBb;mDACuCF;+BACpBQ,YAAAA,CAAaW,IAAAA,CAAKC,+CAA+Cb,2BAA2BiB,QAAQD,cAAcf,YAAAA,CAAaW,IAAAA,CAAKE,WAAAA,CAAYC;+BAChJd,YAAAA,CAAaW,IAAAA,CAAKM,kDAAkDlB,2BAA2BiB,QAAQhB,YAAAA,CAAaW,IAAAA,CAAKE,WAAAA,CAAYK;;;SAG3JZ,kCAAkCN,YAAAA,CAAac,yGAAyGnB,eAAtFwB,yBAAAA,CAAwIC,gBAAAA;6DACtJpB,YAAAA,CAAaqB,oCAAoCrB,YAAAA,CAAakB,iBAAiBtB,YAAHuB,yBAAAA,CAAkDC,gBAAAA,EAAgBD,yBAAAA,CAAqCG,WAAAA;;;oBAG5NhB,sBAAsBA,mCAAmCR,eAAeyB;;IAEvFjB,8BAA8BjB,uCAAuCQ,SAAST,wBAAwBmC;;;oBAGvFjB,sBAAsBA,mCAAmCR,eAAeyB;;IAEvFjB,8BAA8BjB,sCAAsCQ,SAAST;SACvEQ;YACG2B;;;;oBAIMjB,sBAAsBA,mCAAmCR,eAAeyB;;IAEvFjB,8BAA8BjB,yCAAyCQ,SAAST,wBAAwBmC,aAAa1B,SAAST;SACxHQ;YACG2B"}