@langchain/xai 1.2.2-dev-1768440391024 → 1.3.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/CHANGELOG.md +48 -0
- package/dist/chat_models/completions.cjs +1 -1
- package/dist/chat_models/completions.cjs.map +1 -1
- package/dist/chat_models/completions.d.cts +5 -0
- package/dist/chat_models/completions.d.cts.map +1 -1
- package/dist/chat_models/completions.d.ts +5 -0
- package/dist/chat_models/completions.d.ts.map +1 -1
- package/dist/chat_models/completions.js +1 -1
- package/dist/chat_models/completions.js.map +1 -1
- package/dist/chat_models/responses-types.d.cts +37 -7
- package/dist/chat_models/responses-types.d.cts.map +1 -1
- package/dist/chat_models/responses-types.d.ts +37 -7
- package/dist/chat_models/responses-types.d.ts.map +1 -1
- package/dist/chat_models/responses.cjs +5 -0
- package/dist/chat_models/responses.cjs.map +1 -1
- package/dist/chat_models/responses.d.cts +2 -1
- package/dist/chat_models/responses.d.cts.map +1 -1
- package/dist/chat_models/responses.d.ts +2 -1
- package/dist/chat_models/responses.d.ts.map +1 -1
- package/dist/chat_models/responses.js +5 -0
- package/dist/chat_models/responses.js.map +1 -1
- package/dist/tools/code_execution.cjs +52 -0
- package/dist/tools/code_execution.cjs.map +1 -0
- package/dist/tools/code_execution.d.cts +64 -0
- package/dist/tools/code_execution.d.cts.map +1 -0
- package/dist/tools/code_execution.d.ts +64 -0
- package/dist/tools/code_execution.d.ts.map +1 -0
- package/dist/tools/code_execution.js +50 -0
- package/dist/tools/code_execution.js.map +1 -0
- package/dist/tools/collections_search.cjs +60 -0
- package/dist/tools/collections_search.cjs.map +1 -0
- package/dist/tools/collections_search.d.cts +90 -0
- package/dist/tools/collections_search.d.cts.map +1 -0
- package/dist/tools/collections_search.d.ts +90 -0
- package/dist/tools/collections_search.d.ts.map +1 -0
- package/dist/tools/collections_search.js +58 -0
- package/dist/tools/collections_search.js.map +1 -0
- package/dist/tools/index.cjs +11 -1
- package/dist/tools/index.cjs.map +1 -1
- package/dist/tools/index.d.cts +10 -1
- package/dist/tools/index.d.cts.map +1 -1
- package/dist/tools/index.d.ts +10 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +12 -2
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/live_search.cjs +14 -0
- package/dist/tools/live_search.cjs.map +1 -1
- package/dist/tools/live_search.d.cts +14 -1
- package/dist/tools/live_search.d.cts.map +1 -1
- package/dist/tools/live_search.d.ts +14 -1
- package/dist/tools/live_search.d.ts.map +1 -1
- package/dist/tools/live_search.js +14 -1
- package/dist/tools/live_search.js.map +1 -1
- package/dist/tools/web_search.cjs +57 -0
- package/dist/tools/web_search.cjs.map +1 -0
- package/dist/tools/web_search.d.cts +104 -0
- package/dist/tools/web_search.d.cts.map +1 -0
- package/dist/tools/web_search.d.ts +104 -0
- package/dist/tools/web_search.d.ts.map +1 -0
- package/dist/tools/web_search.js +55 -0
- package/dist/tools/web_search.js.map +1 -0
- package/dist/tools/x_search.cjs +63 -0
- package/dist/tools/x_search.cjs.map +1 -0
- package/dist/tools/x_search.d.cts +145 -0
- package/dist/tools/x_search.d.cts.map +1 -0
- package/dist/tools/x_search.d.ts +145 -0
- package/dist/tools/x_search.d.ts.map +1 -0
- package/dist/tools/x_search.js +61 -0
- package/dist/tools/x_search.js.map +1 -0
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,53 @@
|
|
|
1
1
|
# @langchain/xai
|
|
2
2
|
|
|
3
|
+
## 1.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#9890](https://github.com/langchain-ai/langchainjs/pull/9890) [`e3ea086`](https://github.com/langchain-ai/langchainjs/commit/e3ea086121b5936668ba01ae43f8087df9263ab3) Thanks [@hntrl](https://github.com/hntrl)! - feat(xai): add server-side agentic tools and deprecate live_search
|
|
8
|
+
|
|
9
|
+
Added new xAI server-side agentic tools for the Responses API:
|
|
10
|
+
- `xaiWebSearch()`: Web search with domain filtering and image understanding
|
|
11
|
+
- `xaiXSearch()`: X (Twitter) search with handle filtering, date ranges, and media understanding
|
|
12
|
+
- `xaiCodeExecution()`: Python code execution for calculations and analysis
|
|
13
|
+
- `xaiCollectionsSearch()`: Search through uploaded knowledge bases (vector stores)
|
|
14
|
+
|
|
15
|
+
Also:
|
|
16
|
+
- Deprecated `xaiLiveSearch()` with migration guidance to new tools
|
|
17
|
+
- Added `tools` support to `ChatXAIResponses` constructor and call options
|
|
18
|
+
- Updated `XAIResponsesWebSearchTool` type with correct filtering options
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- [#9900](https://github.com/langchain-ai/langchainjs/pull/9900) [`a9b5059`](https://github.com/langchain-ai/langchainjs/commit/a9b50597186002221aaa4585246e569fa44c27c8) Thanks [@hntrl](https://github.com/hntrl)! - Improved abort signal handling for chat models:
|
|
23
|
+
- Added `ModelAbortError` class in `@langchain/core/errors` that contains partial output when a model invocation is aborted mid-stream
|
|
24
|
+
- `invoke()` now throws `ModelAbortError` with accumulated `partialOutput` when aborted during streaming (when using streaming callback handlers)
|
|
25
|
+
- `stream()` throws a regular `AbortError` when aborted (since chunks are already yielded to the caller)
|
|
26
|
+
- All provider implementations now properly check and propagate abort signals in both `_generate()` and `_streamResponseChunks()` methods
|
|
27
|
+
- Added standard tests for abort signal behavior
|
|
28
|
+
|
|
29
|
+
- [#9900](https://github.com/langchain-ai/langchainjs/pull/9900) [`a9b5059`](https://github.com/langchain-ai/langchainjs/commit/a9b50597186002221aaa4585246e569fa44c27c8) Thanks [@hntrl](https://github.com/hntrl)! - fix(providers): add proper abort signal handling for invoke and stream operations
|
|
30
|
+
- Added early abort check (`signal.throwIfAborted()`) at the start of `_generate` methods to immediately throw when signal is already aborted
|
|
31
|
+
- Added abort signal checks inside streaming loops in `_streamResponseChunks` to return early when signal is aborted
|
|
32
|
+
- Propagated abort signals to underlying SDK calls where applicable (Google GenAI, Google Common/VertexAI, Cohere)
|
|
33
|
+
- Added standard tests for abort signal behavior in `@langchain/standard-tests`
|
|
34
|
+
|
|
35
|
+
This enables proper cancellation behavior for both invoke and streaming operations, and allows fallback chains to correctly proceed to the next runnable when the previous one is aborted.
|
|
36
|
+
|
|
37
|
+
- [#9889](https://github.com/langchain-ai/langchainjs/pull/9889) [`b303711`](https://github.com/langchain-ai/langchainjs/commit/b303711736e06f3c04d6bb5f50032da2dfb021f3) Thanks [@hntrl](https://github.com/hntrl)! - feat(xai): add baseURL option to ChatXAI
|
|
38
|
+
|
|
39
|
+
Added `baseURL` configuration option to `ChatXAI` class, allowing users to override the default xAI API endpoint. This is useful for connecting to custom endpoints, proxies, or alternative API-compatible services.
|
|
40
|
+
|
|
41
|
+
- Updated dependencies [[`1fa865b`](https://github.com/langchain-ai/langchainjs/commit/1fa865b1cb8a30c2269b83cdb5fc84d374c3fca9), [`28efb57`](https://github.com/langchain-ai/langchainjs/commit/28efb57448933368094ca41c63d9262ac0f348a6), [`4e42452`](https://github.com/langchain-ai/langchainjs/commit/4e42452e4c020408bd6687667e931497b05aaff5), [`a9b5059`](https://github.com/langchain-ai/langchainjs/commit/a9b50597186002221aaa4585246e569fa44c27c8), [`a9b5059`](https://github.com/langchain-ai/langchainjs/commit/a9b50597186002221aaa4585246e569fa44c27c8)]:
|
|
42
|
+
- @langchain/openai@1.2.4
|
|
43
|
+
|
|
44
|
+
## 1.2.2
|
|
45
|
+
|
|
46
|
+
### Patch Changes
|
|
47
|
+
|
|
48
|
+
- Updated dependencies [[`a7c6ec5`](https://github.com/langchain-ai/langchainjs/commit/a7c6ec51ab9baa186ab5ebf815599c08f5c7e8ab), [`04923f9`](https://github.com/langchain-ai/langchainjs/commit/04923f9835e5b3677c180b601ae8f3e7d8be0236), [`e16c218`](https://github.com/langchain-ai/langchainjs/commit/e16c218b81980a1c576af5192342019975bb95b9)]:
|
|
49
|
+
- @langchain/openai@1.2.3
|
|
50
|
+
|
|
3
51
|
## 1.2.1
|
|
4
52
|
|
|
5
53
|
### Patch Changes
|
|
@@ -427,7 +427,7 @@ var ChatXAI = class extends __langchain_openai.ChatOpenAICompletions {
|
|
|
427
427
|
...fields,
|
|
428
428
|
model: fields?.model || "grok-beta",
|
|
429
429
|
apiKey,
|
|
430
|
-
configuration: { baseURL: "https://api.x.ai/v1" }
|
|
430
|
+
configuration: { baseURL: fields?.baseURL ?? "https://api.x.ai/v1" }
|
|
431
431
|
});
|
|
432
432
|
this.searchParameters = fields?.searchParameters;
|
|
433
433
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"completions.cjs","names":["XAI_LIVE_SEARCH_TOOL_TYPE","tool: ChatXAIToolType","ChatOpenAICompletions","fields?: Partial<ChatXAIInput>","options: this[\"ParsedCallOptions\"]","options?: this[\"ParsedCallOptions\"]","mergeSearchParams","tools?: ChatXAIToolType[]","tools: ChatXAIToolType[]","kwargs?: Partial<ChatXAICallOptions>","extra?: { streaming?: boolean }","params: ChatXAICompletionsInvocationParams","buildSearchParametersPayload","request:\n | OpenAIClient.Chat.ChatCompletionCreateParamsStreaming\n | OpenAIClient.Chat.ChatCompletionCreateParamsNonStreaming","options?: OpenAICoreRequestOptions","filteredTools: OpenAIClient.ChatCompletionTool[] | undefined","filterXAIBuiltInTools","delta: Record<string, any>","rawResponse: OpenAIClient.ChatCompletionChunk","defaultRole?:\n | \"function\"\n | \"user\"\n | \"system\"\n | \"developer\"\n | \"assistant\"\n | \"tool\"","message: OpenAIClient.ChatCompletionMessage & {\n reasoning_content?: string;\n }","rawResponse: OpenAIClient.ChatCompletion","PROFILES","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/completions.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 {\n isLangChainTool,\n convertToOpenAITool,\n} from \"@langchain/core/utils/function_calling\";\nimport { ModelProfile } from \"@langchain/core/language_models/profile\";\nimport { Serialized } from \"@langchain/core/load/serializable\";\nimport {\n AIMessageChunk,\n BaseMessage,\n type UsageMetadata,\n} 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 ChatOpenAICompletions,\n} from \"@langchain/openai\";\nimport {\n buildSearchParametersPayload,\n filterXAIBuiltInTools,\n mergeSearchParams,\n type XAISearchParameters,\n type XAISearchParametersPayload,\n} from \"../live_search.js\";\nimport PROFILES from \"../profiles.js\";\nimport {\n XAI_LIVE_SEARCH_TOOL_TYPE,\n XAILiveSearchTool,\n} from \"../tools/live_search.js\";\n\nexport type OpenAIToolChoice =\n | OpenAIClient.ChatCompletionToolChoiceOption\n | \"any\"\n | string;\n\n/**\n * Union type for all xAI built-in server-side tools.\n */\nexport type XAIBuiltInTool = XAILiveSearchTool;\n\n/**\n * Set of all supported xAI built-in server-side tool types.\n * This allows us to easily extend support for future built-in tools\n * without changing the core detection logic.\n */\nconst XAI_BUILT_IN_TOOL_TYPES = new Set<XAILiveSearchTool[\"type\"] | string>([\n XAI_LIVE_SEARCH_TOOL_TYPE,\n]);\n\n/**\n * Tool type that includes both standard tools and xAI built-in tools.\n */\ntype ChatXAIToolType =\n | BindToolsInput\n | OpenAIClient.ChatCompletionTool\n | XAIBuiltInTool;\n\n/**\n * xAI-specific invocation parameters that extend the OpenAI completion params\n * with xAI's search_parameters field.\n */\nexport type ChatXAICompletionsInvocationParams = Omit<\n OpenAIClient.Chat.Completions.ChatCompletionCreateParams,\n \"messages\"\n> & {\n /**\n * Search parameters for xAI's Live Search API.\n * When present, enables the model to search the web for real-time information.\n */\n search_parameters?: XAISearchParametersPayload;\n};\n\n/**\n * xAI-specific additional kwargs that may be present on AI messages.\n * Includes xAI-specific fields like reasoning_content.\n */\nexport interface XAIAdditionalKwargs {\n /**\n * The reasoning content from xAI models that support chain-of-thought reasoning.\n * This contains the model's internal reasoning process.\n */\n reasoning_content?: string;\n /**\n * Tool calls made by the model.\n */\n tool_calls?: OpenAIClient.ChatCompletionMessageToolCall[];\n /**\n * Additional properties that may be present.\n */\n [key: string]: unknown;\n}\n\n/**\n * xAI-specific response metadata that may include usage information.\n */\nexport interface XAIResponseMetadata {\n /**\n * Token usage information.\n */\n usage?: UsageMetadata;\n /**\n * Additional metadata properties.\n */\n [key: string]: unknown;\n}\n\n/**\n * Checks if a tool is an xAI built-in tool (like live_search).\n * Built-in tools are executed server-side by the xAI API.\n *\n * @param tool - The tool to check\n * @returns true if the tool is an xAI built-in tool\n */\nexport function isXAIBuiltInTool(\n tool: ChatXAIToolType\n): tool is XAIBuiltInTool {\n return (\n typeof tool === \"object\" &&\n tool !== null &&\n \"type\" in tool &&\n typeof (tool as { type?: unknown }).type === \"string\" &&\n XAI_BUILT_IN_TOOL_TYPES.has((tool as { type: string }).type)\n );\n}\n\nexport interface ChatXAICallOptions extends BaseChatModelCallOptions {\n headers?: Record<string, string>;\n /**\n * A list of tools the model may call.\n * Can include standard function tools and xAI built-in tools like `{ type: \"live_search\" }`.\n *\n * @example\n * ```typescript\n * // Using built-in live_search tool\n * const llm = new ChatXAI().bindTools([{ type: \"live_search\" }]);\n * const result = await llm.invoke(\"What happened in tech news today?\");\n * ```\n */\n tools?: ChatXAIToolType[];\n tool_choice?: OpenAIToolChoice | string | \"auto\" | \"any\";\n /**\n * Search parameters for xAI's Live Search API.\n * Enables the model to search the web for real-time information.\n *\n * @note This is an alternative to using `tools: [{ type: \"live_search\" }]`.\n * The Live Search API parameters approach may be deprecated in favor of\n * the tool-based approach.\n *\n * @example\n * ```typescript\n * const result = await llm.invoke(\"What's the latest news?\", {\n * searchParameters: {\n * mode: \"auto\",\n * max_search_results: 5,\n * }\n * });\n * ```\n */\n searchParameters?: XAISearchParameters;\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 * Default search parameters for xAI's Live Search API.\n * When set, these parameters will be applied to all requests unless\n * overridden in the call options.\n *\n * @example\n * ```typescript\n * const llm = new ChatXAI({\n * model: \"grok-beta\",\n * searchParameters: {\n * mode: \"auto\",\n * max_search_results: 5,\n * }\n * });\n * ```\n */\n searchParameters?: XAISearchParameters;\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 *\n * <details>\n * <summary><strong>Server Tool Calling (Live Search)</strong></summary>\n *\n * xAI supports server-side tools that are executed by the API rather than\n * requiring client-side execution. The `live_search` tool enables the model\n * to search the web for real-time information.\n *\n * ```typescript\n * // Method 1: Using the built-in live_search tool\n * const llm = new ChatXAI({\n * model: \"grok-beta\",\n * temperature: 0,\n * });\n *\n * const llmWithSearch = llm.bindTools([{ type: \"live_search\" }]);\n * const result = await llmWithSearch.invoke(\"What happened in tech news today?\");\n * console.log(result.content);\n * // The model will search the web and include real-time information in its response\n * ```\n *\n * ```typescript\n * // Method 2: Using searchParameters for more control\n * const llm = new ChatXAI({\n * model: \"grok-beta\",\n * searchParameters: {\n * mode: \"auto\", // \"auto\" | \"on\" | \"off\"\n * max_search_results: 5,\n * from_date: \"2024-01-01\", // ISO date string\n * return_citations: true,\n * }\n * });\n *\n * const result = await llm.invoke(\"What are the latest AI developments?\");\n * ```\n *\n * ```typescript\n * // Method 3: Override search parameters per request\n * const result = await llm.invoke(\"Find recent news about SpaceX\", {\n * searchParameters: {\n * mode: \"on\",\n * max_search_results: 10,\n * sources: [\n * { type: \"web\", allowed_websites: [\"spacex.com\", \"nasa.gov\"] },\n * ],\n * }\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 /**\n * Default search parameters for the Live Search API.\n */\n searchParameters?: XAISearchParameters;\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 this.searchParameters = fields?.searchParameters;\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 /**\n * Get the effective search parameters, merging defaults with call options.\n * @param options Call options that may contain search parameters\n * @returns Merged search parameters or undefined if none are configured\n */\n protected _getEffectiveSearchParameters(\n options?: this[\"ParsedCallOptions\"]\n ): XAISearchParameters | undefined {\n return mergeSearchParams(this.searchParameters, options?.searchParameters);\n }\n\n /**\n * Check if any built-in tools (like live_search) are in the tools list.\n * @param tools List of tools to check\n * @returns true if any built-in tools are present\n */\n protected _hasBuiltInTools(tools?: ChatXAIToolType[]): boolean {\n return tools?.some(isXAIBuiltInTool) ?? false;\n }\n\n /**\n * Formats tools to xAI/OpenAI format, preserving provider-specific definitions.\n *\n * @param tools The tools to format\n * @returns The formatted tools\n */\n formatStructuredToolToXAI(\n tools: ChatXAIToolType[]\n ): (OpenAIClient.ChatCompletionTool | XAIBuiltInTool)[] | undefined {\n if (!tools || !tools.length) {\n return undefined;\n }\n return tools.map((tool) => {\n // 1. Check for provider definition first (from xaiLiveSearch factory)\n if (isLangChainTool(tool) && tool.extras?.providerToolDefinition) {\n return tool.extras.providerToolDefinition as XAIBuiltInTool;\n }\n // 2. Check for built-in tools (legacy { type: \"live_search\" })\n if (isXAIBuiltInTool(tool)) {\n return tool;\n }\n // 3. Convert standard tools to OpenAI format\n return convertToOpenAITool(tool) as OpenAIClient.ChatCompletionTool;\n });\n }\n\n override bindTools(\n tools: ChatXAIToolType[],\n kwargs?: Partial<ChatXAICallOptions>\n ): Runnable<BaseLanguageModelInput, AIMessageChunk, ChatXAICallOptions> {\n return this.withConfig({\n tools: this.formatStructuredToolToXAI(tools),\n ...kwargs,\n } as Partial<ChatXAICallOptions>);\n }\n\n /** @internal */\n override invocationParams(\n options?: this[\"ParsedCallOptions\"],\n extra?: { streaming?: boolean }\n ): ChatXAICompletionsInvocationParams {\n const baseParams = super.invocationParams(options, extra);\n\n // Cast to xAI-specific params type\n const params: ChatXAICompletionsInvocationParams = { ...baseParams };\n\n // Check if live_search tool is being used\n // We also need to extract params from the tool definition if present\n const liveSearchTool = options?.tools?.find(isXAIBuiltInTool) as\n | XAILiveSearchTool\n | undefined;\n\n const mergedSearchParams = mergeSearchParams(\n this.searchParameters,\n options?.searchParameters,\n liveSearchTool\n );\n\n // Add search_parameters if needed\n if (mergedSearchParams) {\n params.search_parameters =\n buildSearchParametersPayload(mergedSearchParams);\n }\n\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 let filteredTools: OpenAIClient.ChatCompletionTool[] | undefined;\n if (request.tools) {\n filteredTools = filterXAIBuiltInTools({\n tools: request.tools,\n excludedTypes: [XAI_LIVE_SEARCH_TOOL_TYPE],\n }) as OpenAIClient.ChatCompletionTool[] | undefined;\n }\n\n const newRequest = {\n ...request,\n messages: newRequestMessages,\n tools: filteredTools,\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 ): AIMessageChunk {\n const messageChunk = super._convertCompletionsDeltaToBaseMessageChunk(\n delta,\n rawResponse,\n defaultRole\n ) as AIMessageChunk;\n\n // Cast to xAI-specific types for proper typing\n const responseMetadata =\n messageChunk.response_metadata as XAIResponseMetadata;\n\n // Make concatenating chunks work without merge warning\n if (!rawResponse.choices[0]?.finish_reason) {\n delete responseMetadata.usage;\n delete messageChunk.usage_metadata;\n } else {\n messageChunk.usage_metadata = responseMetadata.usage;\n }\n return messageChunk;\n }\n\n protected override _convertCompletionsMessageToBaseMessage(\n message: OpenAIClient.ChatCompletionMessage & {\n reasoning_content?: string;\n },\n rawResponse: OpenAIClient.ChatCompletion\n ): AIMessageChunk {\n const langChainMessage = super._convertCompletionsMessageToBaseMessage(\n message,\n rawResponse\n ) as AIMessageChunk;\n\n // Cast additional_kwargs to xAI-specific type and add reasoning_content\n const additionalKwargs =\n langChainMessage.additional_kwargs as XAIAdditionalKwargs;\n additionalKwargs.reasoning_content = message.reasoning_content;\n\n return langChainMessage;\n }\n\n /**\n * Return profiling information for the model.\n *\n * Provides information about the model's capabilities and constraints,\n * including token limits, multimodal support, and advanced features like\n * tool calling and structured output.\n *\n * @returns {ModelProfile} An object describing the model's capabilities and constraints\n *\n * @example\n * ```typescript\n * const model = new ChatXAI({ model: \"grok-beta\" });\n * const profile = model.profile;\n * console.log(profile.maxInputTokens); // 128000\n * console.log(profile.imageInputs); // true\n * ```\n */\n get profile(): ModelProfile {\n return PROFILES[this.model] ?? {};\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":";;;;;;;;;;;;;;AAyDA,MAAM,0BAA0B,IAAI,IAAwC,CAC1EA,+CACD;;;;;;;;AAkED,SAAgB,iBACdC,MACwB;AACxB,QACE,OAAO,SAAS,YAChB,SAAS,QACT,UAAU,QACV,OAAQ,KAA4B,SAAS,YAC7C,wBAAwB,IAAK,KAA0B,KAAK;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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ACD;EAGD,MAAM,mBACJ,aAAa;AAGf,MAAI,CAAC,YAAY,QAAQ,IAAI,eAAe;GAC1C,OAAO,iBAAiB;GACxB,OAAO,aAAa;EACrB,OACC,aAAa,iBAAiB,iBAAiB;AAEjD,SAAO;CACR;CAED,AAAmB,wCACjBC,SAGAC,aACgB;EAChB,MAAM,mBAAmB,MAAM,wCAC7B,SACA,YACD;EAGD,MAAM,mBACJ,iBAAiB;EACnB,iBAAiB,oBAAoB,QAAQ;AAE7C,SAAO;CACR;;;;;;;;;;;;;;;;;;CAmBD,IAAI,UAAwB;AAC1B,SAAOC,yBAAS,KAAK,UAAU,CAAE;CAClC;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"}
|
|
1
|
+
{"version":3,"file":"completions.cjs","names":["XAI_LIVE_SEARCH_TOOL_TYPE","tool: ChatXAIToolType","ChatOpenAICompletions","fields?: Partial<ChatXAIInput>","options: this[\"ParsedCallOptions\"]","options?: this[\"ParsedCallOptions\"]","mergeSearchParams","tools?: ChatXAIToolType[]","tools: ChatXAIToolType[]","kwargs?: Partial<ChatXAICallOptions>","extra?: { streaming?: boolean }","params: ChatXAICompletionsInvocationParams","buildSearchParametersPayload","request:\n | OpenAIClient.Chat.ChatCompletionCreateParamsStreaming\n | OpenAIClient.Chat.ChatCompletionCreateParamsNonStreaming","options?: OpenAICoreRequestOptions","filteredTools: OpenAIClient.ChatCompletionTool[] | undefined","filterXAIBuiltInTools","delta: Record<string, any>","rawResponse: OpenAIClient.ChatCompletionChunk","defaultRole?:\n | \"function\"\n | \"user\"\n | \"system\"\n | \"developer\"\n | \"assistant\"\n | \"tool\"","message: OpenAIClient.ChatCompletionMessage & {\n reasoning_content?: string;\n }","rawResponse: OpenAIClient.ChatCompletion","PROFILES","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/completions.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 {\n isLangChainTool,\n convertToOpenAITool,\n} from \"@langchain/core/utils/function_calling\";\nimport { ModelProfile } from \"@langchain/core/language_models/profile\";\nimport { Serialized } from \"@langchain/core/load/serializable\";\nimport {\n AIMessageChunk,\n BaseMessage,\n type UsageMetadata,\n} 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 ChatOpenAICompletions,\n} from \"@langchain/openai\";\nimport {\n buildSearchParametersPayload,\n filterXAIBuiltInTools,\n mergeSearchParams,\n type XAISearchParameters,\n type XAISearchParametersPayload,\n} from \"../live_search.js\";\nimport PROFILES from \"../profiles.js\";\nimport {\n XAI_LIVE_SEARCH_TOOL_TYPE,\n XAILiveSearchTool,\n} from \"../tools/live_search.js\";\n\nexport type OpenAIToolChoice =\n | OpenAIClient.ChatCompletionToolChoiceOption\n | \"any\"\n | string;\n\n/**\n * Union type for all xAI built-in server-side tools.\n */\nexport type XAIBuiltInTool = XAILiveSearchTool;\n\n/**\n * Set of all supported xAI built-in server-side tool types.\n * This allows us to easily extend support for future built-in tools\n * without changing the core detection logic.\n */\nconst XAI_BUILT_IN_TOOL_TYPES = new Set<XAILiveSearchTool[\"type\"] | string>([\n XAI_LIVE_SEARCH_TOOL_TYPE,\n]);\n\n/**\n * Tool type that includes both standard tools and xAI built-in tools.\n */\ntype ChatXAIToolType =\n | BindToolsInput\n | OpenAIClient.ChatCompletionTool\n | XAIBuiltInTool;\n\n/**\n * xAI-specific invocation parameters that extend the OpenAI completion params\n * with xAI's search_parameters field.\n */\nexport type ChatXAICompletionsInvocationParams = Omit<\n OpenAIClient.Chat.Completions.ChatCompletionCreateParams,\n \"messages\"\n> & {\n /**\n * Search parameters for xAI's Live Search API.\n * When present, enables the model to search the web for real-time information.\n */\n search_parameters?: XAISearchParametersPayload;\n};\n\n/**\n * xAI-specific additional kwargs that may be present on AI messages.\n * Includes xAI-specific fields like reasoning_content.\n */\nexport interface XAIAdditionalKwargs {\n /**\n * The reasoning content from xAI models that support chain-of-thought reasoning.\n * This contains the model's internal reasoning process.\n */\n reasoning_content?: string;\n /**\n * Tool calls made by the model.\n */\n tool_calls?: OpenAIClient.ChatCompletionMessageToolCall[];\n /**\n * Additional properties that may be present.\n */\n [key: string]: unknown;\n}\n\n/**\n * xAI-specific response metadata that may include usage information.\n */\nexport interface XAIResponseMetadata {\n /**\n * Token usage information.\n */\n usage?: UsageMetadata;\n /**\n * Additional metadata properties.\n */\n [key: string]: unknown;\n}\n\n/**\n * Checks if a tool is an xAI built-in tool (like live_search).\n * Built-in tools are executed server-side by the xAI API.\n *\n * @param tool - The tool to check\n * @returns true if the tool is an xAI built-in tool\n */\nexport function isXAIBuiltInTool(\n tool: ChatXAIToolType\n): tool is XAIBuiltInTool {\n return (\n typeof tool === \"object\" &&\n tool !== null &&\n \"type\" in tool &&\n typeof (tool as { type?: unknown }).type === \"string\" &&\n XAI_BUILT_IN_TOOL_TYPES.has((tool as { type: string }).type)\n );\n}\n\nexport interface ChatXAICallOptions extends BaseChatModelCallOptions {\n headers?: Record<string, string>;\n /**\n * A list of tools the model may call.\n * Can include standard function tools and xAI built-in tools like `{ type: \"live_search\" }`.\n *\n * @example\n * ```typescript\n * // Using built-in live_search tool\n * const llm = new ChatXAI().bindTools([{ type: \"live_search\" }]);\n * const result = await llm.invoke(\"What happened in tech news today?\");\n * ```\n */\n tools?: ChatXAIToolType[];\n tool_choice?: OpenAIToolChoice | string | \"auto\" | \"any\";\n /**\n * Search parameters for xAI's Live Search API.\n * Enables the model to search the web for real-time information.\n *\n * @note This is an alternative to using `tools: [{ type: \"live_search\" }]`.\n * The Live Search API parameters approach may be deprecated in favor of\n * the tool-based approach.\n *\n * @example\n * ```typescript\n * const result = await llm.invoke(\"What's the latest news?\", {\n * searchParameters: {\n * mode: \"auto\",\n * max_search_results: 5,\n * }\n * });\n * ```\n */\n searchParameters?: XAISearchParameters;\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 * Default search parameters for xAI's Live Search API.\n * When set, these parameters will be applied to all requests unless\n * overridden in the call options.\n *\n * @example\n * ```typescript\n * const llm = new ChatXAI({\n * model: \"grok-beta\",\n * searchParameters: {\n * mode: \"auto\",\n * max_search_results: 5,\n * }\n * });\n * ```\n */\n searchParameters?: XAISearchParameters;\n /**\n * The base URL for the xAI API.\n * @default \"https://api.x.ai/v1\"\n */\n baseURL?: string;\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 *\n * <details>\n * <summary><strong>Server Tool Calling (Live Search)</strong></summary>\n *\n * xAI supports server-side tools that are executed by the API rather than\n * requiring client-side execution. The `live_search` tool enables the model\n * to search the web for real-time information.\n *\n * ```typescript\n * // Method 1: Using the built-in live_search tool\n * const llm = new ChatXAI({\n * model: \"grok-beta\",\n * temperature: 0,\n * });\n *\n * const llmWithSearch = llm.bindTools([{ type: \"live_search\" }]);\n * const result = await llmWithSearch.invoke(\"What happened in tech news today?\");\n * console.log(result.content);\n * // The model will search the web and include real-time information in its response\n * ```\n *\n * ```typescript\n * // Method 2: Using searchParameters for more control\n * const llm = new ChatXAI({\n * model: \"grok-beta\",\n * searchParameters: {\n * mode: \"auto\", // \"auto\" | \"on\" | \"off\"\n * max_search_results: 5,\n * from_date: \"2024-01-01\", // ISO date string\n * return_citations: true,\n * }\n * });\n *\n * const result = await llm.invoke(\"What are the latest AI developments?\");\n * ```\n *\n * ```typescript\n * // Method 3: Override search parameters per request\n * const result = await llm.invoke(\"Find recent news about SpaceX\", {\n * searchParameters: {\n * mode: \"on\",\n * max_search_results: 10,\n * sources: [\n * { type: \"web\", allowed_websites: [\"spacex.com\", \"nasa.gov\"] },\n * ],\n * }\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 /**\n * Default search parameters for the Live Search API.\n */\n searchParameters?: XAISearchParameters;\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: fields?.baseURL ?? \"https://api.x.ai/v1\",\n },\n });\n\n this.searchParameters = fields?.searchParameters;\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 /**\n * Get the effective search parameters, merging defaults with call options.\n * @param options Call options that may contain search parameters\n * @returns Merged search parameters or undefined if none are configured\n */\n protected _getEffectiveSearchParameters(\n options?: this[\"ParsedCallOptions\"]\n ): XAISearchParameters | undefined {\n return mergeSearchParams(this.searchParameters, options?.searchParameters);\n }\n\n /**\n * Check if any built-in tools (like live_search) are in the tools list.\n * @param tools List of tools to check\n * @returns true if any built-in tools are present\n */\n protected _hasBuiltInTools(tools?: ChatXAIToolType[]): boolean {\n return tools?.some(isXAIBuiltInTool) ?? false;\n }\n\n /**\n * Formats tools to xAI/OpenAI format, preserving provider-specific definitions.\n *\n * @param tools The tools to format\n * @returns The formatted tools\n */\n formatStructuredToolToXAI(\n tools: ChatXAIToolType[]\n ): (OpenAIClient.ChatCompletionTool | XAIBuiltInTool)[] | undefined {\n if (!tools || !tools.length) {\n return undefined;\n }\n return tools.map((tool) => {\n // 1. Check for provider definition first (from xaiLiveSearch factory)\n if (isLangChainTool(tool) && tool.extras?.providerToolDefinition) {\n return tool.extras.providerToolDefinition as XAIBuiltInTool;\n }\n // 2. Check for built-in tools (legacy { type: \"live_search\" })\n if (isXAIBuiltInTool(tool)) {\n return tool;\n }\n // 3. Convert standard tools to OpenAI format\n return convertToOpenAITool(tool) as OpenAIClient.ChatCompletionTool;\n });\n }\n\n override bindTools(\n tools: ChatXAIToolType[],\n kwargs?: Partial<ChatXAICallOptions>\n ): Runnable<BaseLanguageModelInput, AIMessageChunk, ChatXAICallOptions> {\n return this.withConfig({\n tools: this.formatStructuredToolToXAI(tools),\n ...kwargs,\n } as Partial<ChatXAICallOptions>);\n }\n\n /** @internal */\n override invocationParams(\n options?: this[\"ParsedCallOptions\"],\n extra?: { streaming?: boolean }\n ): ChatXAICompletionsInvocationParams {\n const baseParams = super.invocationParams(options, extra);\n\n // Cast to xAI-specific params type\n const params: ChatXAICompletionsInvocationParams = { ...baseParams };\n\n // Check if live_search tool is being used\n // We also need to extract params from the tool definition if present\n const liveSearchTool = options?.tools?.find(isXAIBuiltInTool) as\n | XAILiveSearchTool\n | undefined;\n\n const mergedSearchParams = mergeSearchParams(\n this.searchParameters,\n options?.searchParameters,\n liveSearchTool\n );\n\n // Add search_parameters if needed\n if (mergedSearchParams) {\n params.search_parameters =\n buildSearchParametersPayload(mergedSearchParams);\n }\n\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 let filteredTools: OpenAIClient.ChatCompletionTool[] | undefined;\n if (request.tools) {\n filteredTools = filterXAIBuiltInTools({\n tools: request.tools,\n excludedTypes: [XAI_LIVE_SEARCH_TOOL_TYPE],\n }) as OpenAIClient.ChatCompletionTool[] | undefined;\n }\n\n const newRequest = {\n ...request,\n messages: newRequestMessages,\n tools: filteredTools,\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 ): AIMessageChunk {\n const messageChunk = super._convertCompletionsDeltaToBaseMessageChunk(\n delta,\n rawResponse,\n defaultRole\n ) as AIMessageChunk;\n\n // Cast to xAI-specific types for proper typing\n const responseMetadata =\n messageChunk.response_metadata as XAIResponseMetadata;\n\n // Make concatenating chunks work without merge warning\n if (!rawResponse.choices[0]?.finish_reason) {\n delete responseMetadata.usage;\n delete messageChunk.usage_metadata;\n } else {\n messageChunk.usage_metadata = responseMetadata.usage;\n }\n return messageChunk;\n }\n\n protected override _convertCompletionsMessageToBaseMessage(\n message: OpenAIClient.ChatCompletionMessage & {\n reasoning_content?: string;\n },\n rawResponse: OpenAIClient.ChatCompletion\n ): AIMessageChunk {\n const langChainMessage = super._convertCompletionsMessageToBaseMessage(\n message,\n rawResponse\n ) as AIMessageChunk;\n\n // Cast additional_kwargs to xAI-specific type and add reasoning_content\n const additionalKwargs =\n langChainMessage.additional_kwargs as XAIAdditionalKwargs;\n additionalKwargs.reasoning_content = message.reasoning_content;\n\n return langChainMessage;\n }\n\n /**\n * Return profiling information for the model.\n *\n * Provides information about the model's capabilities and constraints,\n * including token limits, multimodal support, and advanced features like\n * tool calling and structured output.\n *\n * @returns {ModelProfile} An object describing the model's capabilities and constraints\n *\n * @example\n * ```typescript\n * const model = new ChatXAI({ model: \"grok-beta\" });\n * const profile = model.profile;\n * console.log(profile.maxInputTokens); // 128000\n * console.log(profile.imageInputs); // true\n * ```\n */\n get profile(): ModelProfile {\n return PROFILES[this.model] ?? {};\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":";;;;;;;;;;;;;;AAyDA,MAAM,0BAA0B,IAAI,IAAwC,CAC1EA,+CACD;;;;;;;;A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0CAAsB;GACpC,OAAO,QAAQ;GACf,eAAe,CAAChB,+CAA0B;EAC3C,EAAC;EAGJ,MAAM,aAAa;GACjB,GAAG;GACH,UAAU;GACV,OAAO;EACR;AAED,MAAI,WAAW,WAAW,KACxB,QAAO,MAAM,oBAAoB,YAAY,QAAQ;AAGvD,SAAO,MAAM,oBAAoB,YAAY,QAAQ;CACtD;CAED,AAAmB,2CAEjBiB,OACAC,aACAC,aAOgB;EAChB,MAAM,eAAe,MAAM,2CACzB,OACA,aACA,YACD;EAGD,MAAM,mBACJ,aAAa;AAGf,MAAI,CAAC,YAAY,QAAQ,IAAI,eAAe;GAC1C,OAAO,iBAAiB;GACxB,OAAO,aAAa;EACrB,OACC,aAAa,iBAAiB,iBAAiB;AAEjD,SAAO;CACR;CAED,AAAmB,wCACjBC,SAGAC,aACgB;EAChB,MAAM,mBAAmB,MAAM,wCAC7B,SACA,YACD;EAGD,MAAM,mBACJ,iBAAiB;EACnB,iBAAiB,oBAAoB,QAAQ;AAE7C,SAAO;CACR;;;;;;;;;;;;;;;;;;CAmBD,IAAI,UAAwB;AAC1B,SAAOC,yBAAS,KAAK,UAAU,CAAE;CAClC;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"}
|
|
@@ -158,6 +158,11 @@ interface ChatXAIInput extends BaseChatModelParams {
|
|
|
158
158
|
* ```
|
|
159
159
|
*/
|
|
160
160
|
searchParameters?: XAISearchParameters;
|
|
161
|
+
/**
|
|
162
|
+
* The base URL for the xAI API.
|
|
163
|
+
* @default "https://api.x.ai/v1"
|
|
164
|
+
*/
|
|
165
|
+
baseURL?: string;
|
|
161
166
|
}
|
|
162
167
|
/**
|
|
163
168
|
* xAI chat model integration.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"completions.d.cts","names":["BaseLanguageModelInput","StructuredOutputMethodOptions","BaseChatModelCallOptions","BindToolsInput","LangSmithParams","BaseChatModelParams","ModelProfile","Serialized","AIMessageChunk","BaseMessage","UsageMetadata","Runnable","InteropZodType","OpenAICoreRequestOptions","OpenAIClient","ChatOpenAICompletions","XAISearchParameters","XAISearchParametersPayload","XAILiveSearchTool","OpenAIToolChoice","ChatCompletionToolChoiceOption","XAIBuiltInTool","ChatXAIToolType","ChatCompletionTool","ChatXAICompletionsInvocationParams","Chat","Completions","ChatCompletionCreateParams","Omit","XAIAdditionalKwargs","ChatCompletionMessageToolCall","XAIResponseMetadata","isXAIBuiltInTool","ChatXAICallOptions","Record","ChatXAIInput","Array","ChatXAI","RunOutput","Partial","ChatCompletionCreateParamsStreaming","ChatCompletionChunk","AsyncIterable","Promise","ChatCompletionCreateParamsNonStreaming","ChatCompletion","ChatCompletionMessage"],"sources":["../../src/chat_models/completions.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 { ModelProfile } from \"@langchain/core/language_models/profile\";\nimport { Serialized } from \"@langchain/core/load/serializable\";\nimport { AIMessageChunk, BaseMessage, type UsageMetadata } from \"@langchain/core/messages\";\nimport { Runnable } from \"@langchain/core/runnables\";\nimport { InteropZodType } from \"@langchain/core/utils/types\";\nimport { type OpenAICoreRequestOptions, type OpenAIClient, ChatOpenAICompletions } from \"@langchain/openai\";\nimport { type XAISearchParameters, type XAISearchParametersPayload } from \"../live_search.js\";\nimport { XAILiveSearchTool } from \"../tools/live_search.js\";\nexport type OpenAIToolChoice = OpenAIClient.ChatCompletionToolChoiceOption | \"any\" | string;\n/**\n * Union type for all xAI built-in server-side tools.\n */\nexport type XAIBuiltInTool = XAILiveSearchTool;\n/**\n * Tool type that includes both standard tools and xAI built-in tools.\n */\ntype ChatXAIToolType = BindToolsInput | OpenAIClient.ChatCompletionTool | XAIBuiltInTool;\n/**\n * xAI-specific invocation parameters that extend the OpenAI completion params\n * with xAI's search_parameters field.\n */\nexport type ChatXAICompletionsInvocationParams = Omit<OpenAIClient.Chat.Completions.ChatCompletionCreateParams, \"messages\"> & {\n /**\n * Search parameters for xAI's Live Search API.\n * When present, enables the model to search the web for real-time information.\n */\n search_parameters?: XAISearchParametersPayload;\n};\n/**\n * xAI-specific additional kwargs that may be present on AI messages.\n * Includes xAI-specific fields like reasoning_content.\n */\nexport interface XAIAdditionalKwargs {\n /**\n * The reasoning content from xAI models that support chain-of-thought reasoning.\n * This contains the model's internal reasoning process.\n */\n reasoning_content?: string;\n /**\n * Tool calls made by the model.\n */\n tool_calls?: OpenAIClient.ChatCompletionMessageToolCall[];\n /**\n * Additional properties that may be present.\n */\n [key: string]: unknown;\n}\n/**\n * xAI-specific response metadata that may include usage information.\n */\nexport interface XAIResponseMetadata {\n /**\n * Token usage information.\n */\n usage?: UsageMetadata;\n /**\n * Additional metadata properties.\n */\n [key: string]: unknown;\n}\n/**\n * Checks if a tool is an xAI built-in tool (like live_search).\n * Built-in tools are executed server-side by the xAI API.\n *\n * @param tool - The tool to check\n * @returns true if the tool is an xAI built-in tool\n */\nexport declare function isXAIBuiltInTool(tool: ChatXAIToolType): tool is XAIBuiltInTool;\nexport interface ChatXAICallOptions extends BaseChatModelCallOptions {\n headers?: Record<string, string>;\n /**\n * A list of tools the model may call.\n * Can include standard function tools and xAI built-in tools like `{ type: \"live_search\" }`.\n *\n * @example\n * ```typescript\n * // Using built-in live_search tool\n * const llm = new ChatXAI().bindTools([{ type: \"live_search\" }]);\n * const result = await llm.invoke(\"What happened in tech news today?\");\n * ```\n */\n tools?: ChatXAIToolType[];\n tool_choice?: OpenAIToolChoice | string | \"auto\" | \"any\";\n /**\n * Search parameters for xAI's Live Search API.\n * Enables the model to search the web for real-time information.\n *\n * @note This is an alternative to using `tools: [{ type: \"live_search\" }]`.\n * The Live Search API parameters approach may be deprecated in favor of\n * the tool-based approach.\n *\n * @example\n * ```typescript\n * const result = await llm.invoke(\"What's the latest news?\", {\n * searchParameters: {\n * mode: \"auto\",\n * max_search_results: 5,\n * }\n * });\n * ```\n */\n searchParameters?: XAISearchParameters;\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 * Default search parameters for xAI's Live Search API.\n * When set, these parameters will be applied to all requests unless\n * overridden in the call options.\n *\n * @example\n * ```typescript\n * const llm = new ChatXAI({\n * model: \"grok-beta\",\n * searchParameters: {\n * mode: \"auto\",\n * max_search_results: 5,\n * }\n * });\n * ```\n */\n searchParameters?: XAISearchParameters;\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 *\n * <details>\n * <summary><strong>Server Tool Calling (Live Search)</strong></summary>\n *\n * xAI supports server-side tools that are executed by the API rather than\n * requiring client-side execution. The `live_search` tool enables the model\n * to search the web for real-time information.\n *\n * ```typescript\n * // Method 1: Using the built-in live_search tool\n * const llm = new ChatXAI({\n * model: \"grok-beta\",\n * temperature: 0,\n * });\n *\n * const llmWithSearch = llm.bindTools([{ type: \"live_search\" }]);\n * const result = await llmWithSearch.invoke(\"What happened in tech news today?\");\n * console.log(result.content);\n * // The model will search the web and include real-time information in its response\n * ```\n *\n * ```typescript\n * // Method 2: Using searchParameters for more control\n * const llm = new ChatXAI({\n * model: \"grok-beta\",\n * searchParameters: {\n * mode: \"auto\", // \"auto\" | \"on\" | \"off\"\n * max_search_results: 5,\n * from_date: \"2024-01-01\", // ISO date string\n * return_citations: true,\n * }\n * });\n *\n * const result = await llm.invoke(\"What are the latest AI developments?\");\n * ```\n *\n * ```typescript\n * // Method 3: Override search parameters per request\n * const result = await llm.invoke(\"Find recent news about SpaceX\", {\n * searchParameters: {\n * mode: \"on\",\n * max_search_results: 10,\n * sources: [\n * { type: \"web\", allowed_websites: [\"spacex.com\", \"nasa.gov\"] },\n * ],\n * }\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 /**\n * Default search parameters for the Live Search API.\n */\n searchParameters?: XAISearchParameters;\n constructor(fields?: Partial<ChatXAIInput>);\n toJSON(): Serialized;\n getLsParams(options: this[\"ParsedCallOptions\"]): LangSmithParams;\n /**\n * Get the effective search parameters, merging defaults with call options.\n * @param options Call options that may contain search parameters\n * @returns Merged search parameters or undefined if none are configured\n */\n protected _getEffectiveSearchParameters(options?: this[\"ParsedCallOptions\"]): XAISearchParameters | undefined;\n /**\n * Check if any built-in tools (like live_search) are in the tools list.\n * @param tools List of tools to check\n * @returns true if any built-in tools are present\n */\n protected _hasBuiltInTools(tools?: ChatXAIToolType[]): boolean;\n /**\n * Formats tools to xAI/OpenAI format, preserving provider-specific definitions.\n *\n * @param tools The tools to format\n * @returns The formatted tools\n */\n formatStructuredToolToXAI(tools: ChatXAIToolType[]): (OpenAIClient.ChatCompletionTool | XAIBuiltInTool)[] | undefined;\n bindTools(tools: ChatXAIToolType[], kwargs?: Partial<ChatXAICallOptions>): Runnable<BaseLanguageModelInput, AIMessageChunk, ChatXAICallOptions>;\n /** @internal */\n invocationParams(options?: this[\"ParsedCallOptions\"], extra?: {\n streaming?: boolean;\n }): ChatXAICompletionsInvocationParams;\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(delta: Record<string, any>, rawResponse: OpenAIClient.ChatCompletionChunk, defaultRole?: \"function\" | \"user\" | \"system\" | \"developer\" | \"assistant\" | \"tool\"): AIMessageChunk;\n protected _convertCompletionsMessageToBaseMessage(message: OpenAIClient.ChatCompletionMessage & {\n reasoning_content?: string;\n }, rawResponse: OpenAIClient.ChatCompletion): AIMessageChunk;\n /**\n * Return profiling information for the model.\n *\n * Provides information about the model's capabilities and constraints,\n * including token limits, multimodal support, and advanced features like\n * tool calling and structured output.\n *\n * @returns {ModelProfile} An object describing the model's capabilities and constraints\n *\n * @example\n * ```typescript\n * const model = new ChatXAI({ model: \"grok-beta\" });\n * const profile = model.profile;\n * console.log(profile.maxInputTokens); // 128000\n * console.log(profile.imageInputs); // true\n * ```\n */\n get profile(): ModelProfile;\n withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;\n withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {\n raw: BaseMessage;\n parsed: RunOutput;\n }>;\n withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<boolean>): Runnable<BaseLanguageModelInput, RunOutput> | Runnable<BaseLanguageModelInput, {\n raw: BaseMessage;\n parsed: RunOutput;\n }>;\n}\nexport {};\n//# sourceMappingURL=completions.d.ts.map"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kBAExDhC,YAAAA,CAAa+B,iBAAiBrC;;;;;;;;;;;;;;;;;;iBAkB/BF;yCACwB4B,sBAAsBA,mCAAmCtB,eAAe0B,aAAaJ,8BAA8BjC,uCAAuCU,SAASX,wBAAwBsC;yCAC3LJ,sBAAsBA,mCAAmCtB,eAAe0B,aAAaJ,8BAA8BjC,sCAAsCU,SAASX;SAChMS;YACG6B;;yCAE2BJ,sBAAsBA,mCAAmCtB,eAAe0B,aAAaJ,8BAA8BjC,yCAAyCU,SAASX,wBAAwBsC,aAAa3B,SAASX;SACjPS;YACG6B"}
|
|
1
|
+
{"version":3,"file":"completions.d.cts","names":["BaseLanguageModelInput","StructuredOutputMethodOptions","BaseChatModelCallOptions","BindToolsInput","LangSmithParams","BaseChatModelParams","ModelProfile","Serialized","AIMessageChunk","BaseMessage","UsageMetadata","Runnable","InteropZodType","OpenAICoreRequestOptions","OpenAIClient","ChatOpenAICompletions","XAISearchParameters","XAISearchParametersPayload","XAILiveSearchTool","OpenAIToolChoice","ChatCompletionToolChoiceOption","XAIBuiltInTool","ChatXAIToolType","ChatCompletionTool","ChatXAICompletionsInvocationParams","Chat","Completions","ChatCompletionCreateParams","Omit","XAIAdditionalKwargs","ChatCompletionMessageToolCall","XAIResponseMetadata","isXAIBuiltInTool","ChatXAICallOptions","Record","ChatXAIInput","Array","ChatXAI","RunOutput","Partial","ChatCompletionCreateParamsStreaming","ChatCompletionChunk","AsyncIterable","Promise","ChatCompletionCreateParamsNonStreaming","ChatCompletion","ChatCompletionMessage"],"sources":["../../src/chat_models/completions.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 { ModelProfile } from \"@langchain/core/language_models/profile\";\nimport { Serialized } from \"@langchain/core/load/serializable\";\nimport { AIMessageChunk, BaseMessage, type UsageMetadata } from \"@langchain/core/messages\";\nimport { Runnable } from \"@langchain/core/runnables\";\nimport { InteropZodType } from \"@langchain/core/utils/types\";\nimport { type OpenAICoreRequestOptions, type OpenAIClient, ChatOpenAICompletions } from \"@langchain/openai\";\nimport { type XAISearchParameters, type XAISearchParametersPayload } from \"../live_search.js\";\nimport { XAILiveSearchTool } from \"../tools/live_search.js\";\nexport type OpenAIToolChoice = OpenAIClient.ChatCompletionToolChoiceOption | \"any\" | string;\n/**\n * Union type for all xAI built-in server-side tools.\n */\nexport type XAIBuiltInTool = XAILiveSearchTool;\n/**\n * Tool type that includes both standard tools and xAI built-in tools.\n */\ntype ChatXAIToolType = BindToolsInput | OpenAIClient.ChatCompletionTool | XAIBuiltInTool;\n/**\n * xAI-specific invocation parameters that extend the OpenAI completion params\n * with xAI's search_parameters field.\n */\nexport type ChatXAICompletionsInvocationParams = Omit<OpenAIClient.Chat.Completions.ChatCompletionCreateParams, \"messages\"> & {\n /**\n * Search parameters for xAI's Live Search API.\n * When present, enables the model to search the web for real-time information.\n */\n search_parameters?: XAISearchParametersPayload;\n};\n/**\n * xAI-specific additional kwargs that may be present on AI messages.\n * Includes xAI-specific fields like reasoning_content.\n */\nexport interface XAIAdditionalKwargs {\n /**\n * The reasoning content from xAI models that support chain-of-thought reasoning.\n * This contains the model's internal reasoning process.\n */\n reasoning_content?: string;\n /**\n * Tool calls made by the model.\n */\n tool_calls?: OpenAIClient.ChatCompletionMessageToolCall[];\n /**\n * Additional properties that may be present.\n */\n [key: string]: unknown;\n}\n/**\n * xAI-specific response metadata that may include usage information.\n */\nexport interface XAIResponseMetadata {\n /**\n * Token usage information.\n */\n usage?: UsageMetadata;\n /**\n * Additional metadata properties.\n */\n [key: string]: unknown;\n}\n/**\n * Checks if a tool is an xAI built-in tool (like live_search).\n * Built-in tools are executed server-side by the xAI API.\n *\n * @param tool - The tool to check\n * @returns true if the tool is an xAI built-in tool\n */\nexport declare function isXAIBuiltInTool(tool: ChatXAIToolType): tool is XAIBuiltInTool;\nexport interface ChatXAICallOptions extends BaseChatModelCallOptions {\n headers?: Record<string, string>;\n /**\n * A list of tools the model may call.\n * Can include standard function tools and xAI built-in tools like `{ type: \"live_search\" }`.\n *\n * @example\n * ```typescript\n * // Using built-in live_search tool\n * const llm = new ChatXAI().bindTools([{ type: \"live_search\" }]);\n * const result = await llm.invoke(\"What happened in tech news today?\");\n * ```\n */\n tools?: ChatXAIToolType[];\n tool_choice?: OpenAIToolChoice | string | \"auto\" | \"any\";\n /**\n * Search parameters for xAI's Live Search API.\n * Enables the model to search the web for real-time information.\n *\n * @note This is an alternative to using `tools: [{ type: \"live_search\" }]`.\n * The Live Search API parameters approach may be deprecated in favor of\n * the tool-based approach.\n *\n * @example\n * ```typescript\n * const result = await llm.invoke(\"What's the latest news?\", {\n * searchParameters: {\n * mode: \"auto\",\n * max_search_results: 5,\n * }\n * });\n * ```\n */\n searchParameters?: XAISearchParameters;\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 * Default search parameters for xAI's Live Search API.\n * When set, these parameters will be applied to all requests unless\n * overridden in the call options.\n *\n * @example\n * ```typescript\n * const llm = new ChatXAI({\n * model: \"grok-beta\",\n * searchParameters: {\n * mode: \"auto\",\n * max_search_results: 5,\n * }\n * });\n * ```\n */\n searchParameters?: XAISearchParameters;\n /**\n * The base URL for the xAI API.\n * @default \"https://api.x.ai/v1\"\n */\n baseURL?: string;\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 *\n * <details>\n * <summary><strong>Server Tool Calling (Live Search)</strong></summary>\n *\n * xAI supports server-side tools that are executed by the API rather than\n * requiring client-side execution. The `live_search` tool enables the model\n * to search the web for real-time information.\n *\n * ```typescript\n * // Method 1: Using the built-in live_search tool\n * const llm = new ChatXAI({\n * model: \"grok-beta\",\n * temperature: 0,\n * });\n *\n * const llmWithSearch = llm.bindTools([{ type: \"live_search\" }]);\n * const result = await llmWithSearch.invoke(\"What happened in tech news today?\");\n * console.log(result.content);\n * // The model will search the web and include real-time information in its response\n * ```\n *\n * ```typescript\n * // Method 2: Using searchParameters for more control\n * const llm = new ChatXAI({\n * model: \"grok-beta\",\n * searchParameters: {\n * mode: \"auto\", // \"auto\" | \"on\" | \"off\"\n * max_search_results: 5,\n * from_date: \"2024-01-01\", // ISO date string\n * return_citations: true,\n * }\n * });\n *\n * const result = await llm.invoke(\"What are the latest AI developments?\");\n * ```\n *\n * ```typescript\n * // Method 3: Override search parameters per request\n * const result = await llm.invoke(\"Find recent news about SpaceX\", {\n * searchParameters: {\n * mode: \"on\",\n * max_search_results: 10,\n * sources: [\n * { type: \"web\", allowed_websites: [\"spacex.com\", \"nasa.gov\"] },\n * ],\n * }\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 /**\n * Default search parameters for the Live Search API.\n */\n searchParameters?: XAISearchParameters;\n constructor(fields?: Partial<ChatXAIInput>);\n toJSON(): Serialized;\n getLsParams(options: this[\"ParsedCallOptions\"]): LangSmithParams;\n /**\n * Get the effective search parameters, merging defaults with call options.\n * @param options Call options that may contain search parameters\n * @returns Merged search parameters or undefined if none are configured\n */\n protected _getEffectiveSearchParameters(options?: this[\"ParsedCallOptions\"]): XAISearchParameters | undefined;\n /**\n * Check if any built-in tools (like live_search) are in the tools list.\n * @param tools List of tools to check\n * @returns true if any built-in tools are present\n */\n protected _hasBuiltInTools(tools?: ChatXAIToolType[]): boolean;\n /**\n * Formats tools to xAI/OpenAI format, preserving provider-specific definitions.\n *\n * @param tools The tools to format\n * @returns The formatted tools\n */\n formatStructuredToolToXAI(tools: ChatXAIToolType[]): (OpenAIClient.ChatCompletionTool | XAIBuiltInTool)[] | undefined;\n bindTools(tools: ChatXAIToolType[], kwargs?: Partial<ChatXAICallOptions>): Runnable<BaseLanguageModelInput, AIMessageChunk, ChatXAICallOptions>;\n /** @internal */\n invocationParams(options?: this[\"ParsedCallOptions\"], extra?: {\n streaming?: boolean;\n }): ChatXAICompletionsInvocationParams;\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(delta: Record<string, any>, rawResponse: OpenAIClient.ChatCompletionChunk, defaultRole?: \"function\" | \"user\" | \"system\" | \"developer\" | \"assistant\" | \"tool\"): AIMessageChunk;\n protected _convertCompletionsMessageToBaseMessage(message: OpenAIClient.ChatCompletionMessage & {\n reasoning_content?: string;\n }, rawResponse: OpenAIClient.ChatCompletion): AIMessageChunk;\n /**\n * Return profiling information for the model.\n *\n * Provides information about the model's capabilities and constraints,\n * including token limits, multimodal support, and advanced features like\n * tool calling and structured output.\n *\n * @returns {ModelProfile} An object describing the model's capabilities and constraints\n *\n * @example\n * ```typescript\n * const model = new ChatXAI({ model: \"grok-beta\" });\n * const profile = model.profile;\n * console.log(profile.maxInputTokens); // 128000\n * console.log(profile.imageInputs); // true\n * ```\n */\n get profile(): ModelProfile;\n withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;\n withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {\n raw: BaseMessage;\n parsed: RunOutput;\n }>;\n withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<boolean>): Runnable<BaseLanguageModelInput, RunOutput> | Runnable<BaseLanguageModelInput, {\n raw: BaseMessage;\n parsed: RunOutput;\n }>;\n}\nexport {};\n//# sourceMappingURL=completions.d.ts.map"],"mappings":";;;;;;;;;;;;KAUYmB,gBAAAA,GAAmBL,YAAAA,CAAaM;;AAA5C;AAIA;AAIKE,KAJOD,cAAAA,GAAiBH,iBAIT;;;;AAAoE,KAAnFI,eAAAA,GAAkBnB,cAAiE,GAAhDW,YAAAA,CAAaS,kBAAmC,GAAdF,cAAc;AAKxF;;;;AAKkD,KALtCG,kCAAAA,GAAqCI,IAKC,CALId,YAAAA,CAAaW,IAAAA,CAAKC,WAAAA,CAAYC,0BAKlC,EAAA,UAAA,CAAA,GAAA;EAMjCE;AAkBjB;AAiBA;AACA;EACcK,iBAAAA,CAAAA,EA3CUjB,0BA2CViB;CAYFZ;;;;AAbwD;AAmCnDa,UAvEAN,mBAAAA,CAuEY;EAgBlBO;;;;EAhB8C,iBAAA,CAAA,EAAA,MAAA;EAobpCC;;;EAYYF,UAAAA,CAAAA,EA9fhBrB,YAAAA,CAAagB,6BA8fGK,EAAAA;EAARI;;;EAQyDvB,CAAAA,GAAAA,EAAAA,MAAAA,CAAAA,EAAAA,OAAAA;;;;;AAc7DM,UA3gBJS,mBAAAA,CA2gBIT;EAAoCW;;;EAAuDzB,KAAAA,CAAAA,EAvgBpGE,aAugBoGF;EAAgByB;;;EAK/FnB,CAAAA,GAAAA,EAAAA,MAAa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;;;;gFAM6BY;;;;;;qCAM3CM;;;;;;;mCAOFA,qBAAqBR,YAAAA,CAAaS,qBAAqBF;mBACvEC,4BAA4BiB,QAAQN,sBAAsBtB,SAASX,wBAAwBQ,gBAAgByB;;;;MAIxHT;+BACyBV,YAAAA,CAAaW,IAAAA,CAAKe,+CAA+C3B,2BAA2B8B,QAAQD,cAAc5B,YAAAA,CAAaW,IAAAA,CAAKC,WAAAA,CAAYe;+BAChJ3B,YAAAA,CAAaW,IAAAA,CAAKmB,kDAAkD/B,2BAA2B8B,QAAQ7B,YAAAA,CAAaW,IAAAA,CAAKC,WAAAA,CAAYmB;8DACtGX,kCAAkCpB,YAAAA,CAAa2B,yGAAyGjC;6DACzJM,YAAAA,CAAagC;;kBAExDhC,YAAAA,CAAa+B,iBAAiBrC;;;;;;;;;;;;;;;;;;iBAkB/BF;yCACwB4B,sBAAsBA,mCAAmCtB,eAAe0B,aAAaJ,8BAA8BjC,uCAAuCU,SAASX,wBAAwBsC;yCAC3LJ,sBAAsBA,mCAAmCtB,eAAe0B,aAAaJ,8BAA8BjC,sCAAsCU,SAASX;SAChMS;YACG6B;;yCAE2BJ,sBAAsBA,mCAAmCtB,eAAe0B,aAAaJ,8BAA8BjC,yCAAyCU,SAASX,wBAAwBsC,aAAa3B,SAASX;SACjPS;YACG6B"}
|
|
@@ -158,6 +158,11 @@ interface ChatXAIInput extends BaseChatModelParams {
|
|
|
158
158
|
* ```
|
|
159
159
|
*/
|
|
160
160
|
searchParameters?: XAISearchParameters;
|
|
161
|
+
/**
|
|
162
|
+
* The base URL for the xAI API.
|
|
163
|
+
* @default "https://api.x.ai/v1"
|
|
164
|
+
*/
|
|
165
|
+
baseURL?: string;
|
|
161
166
|
}
|
|
162
167
|
/**
|
|
163
168
|
* xAI chat model integration.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"completions.d.ts","names":["BaseLanguageModelInput","StructuredOutputMethodOptions","BaseChatModelCallOptions","BindToolsInput","LangSmithParams","BaseChatModelParams","ModelProfile","Serialized","AIMessageChunk","BaseMessage","UsageMetadata","Runnable","InteropZodType","OpenAICoreRequestOptions","OpenAIClient","ChatOpenAICompletions","XAISearchParameters","XAISearchParametersPayload","XAILiveSearchTool","OpenAIToolChoice","ChatCompletionToolChoiceOption","XAIBuiltInTool","ChatXAIToolType","ChatCompletionTool","ChatXAICompletionsInvocationParams","Chat","Completions","ChatCompletionCreateParams","Omit","XAIAdditionalKwargs","ChatCompletionMessageToolCall","XAIResponseMetadata","isXAIBuiltInTool","ChatXAICallOptions","Record","ChatXAIInput","Array","ChatXAI","RunOutput","Partial","ChatCompletionCreateParamsStreaming","ChatCompletionChunk","AsyncIterable","Promise","ChatCompletionCreateParamsNonStreaming","ChatCompletion","ChatCompletionMessage"],"sources":["../../src/chat_models/completions.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 { ModelProfile } from \"@langchain/core/language_models/profile\";\nimport { Serialized } from \"@langchain/core/load/serializable\";\nimport { AIMessageChunk, BaseMessage, type UsageMetadata } from \"@langchain/core/messages\";\nimport { Runnable } from \"@langchain/core/runnables\";\nimport { InteropZodType } from \"@langchain/core/utils/types\";\nimport { type OpenAICoreRequestOptions, type OpenAIClient, ChatOpenAICompletions } from \"@langchain/openai\";\nimport { type XAISearchParameters, type XAISearchParametersPayload } from \"../live_search.js\";\nimport { XAILiveSearchTool } from \"../tools/live_search.js\";\nexport type OpenAIToolChoice = OpenAIClient.ChatCompletionToolChoiceOption | \"any\" | string;\n/**\n * Union type for all xAI built-in server-side tools.\n */\nexport type XAIBuiltInTool = XAILiveSearchTool;\n/**\n * Tool type that includes both standard tools and xAI built-in tools.\n */\ntype ChatXAIToolType = BindToolsInput | OpenAIClient.ChatCompletionTool | XAIBuiltInTool;\n/**\n * xAI-specific invocation parameters that extend the OpenAI completion params\n * with xAI's search_parameters field.\n */\nexport type ChatXAICompletionsInvocationParams = Omit<OpenAIClient.Chat.Completions.ChatCompletionCreateParams, \"messages\"> & {\n /**\n * Search parameters for xAI's Live Search API.\n * When present, enables the model to search the web for real-time information.\n */\n search_parameters?: XAISearchParametersPayload;\n};\n/**\n * xAI-specific additional kwargs that may be present on AI messages.\n * Includes xAI-specific fields like reasoning_content.\n */\nexport interface XAIAdditionalKwargs {\n /**\n * The reasoning content from xAI models that support chain-of-thought reasoning.\n * This contains the model's internal reasoning process.\n */\n reasoning_content?: string;\n /**\n * Tool calls made by the model.\n */\n tool_calls?: OpenAIClient.ChatCompletionMessageToolCall[];\n /**\n * Additional properties that may be present.\n */\n [key: string]: unknown;\n}\n/**\n * xAI-specific response metadata that may include usage information.\n */\nexport interface XAIResponseMetadata {\n /**\n * Token usage information.\n */\n usage?: UsageMetadata;\n /**\n * Additional metadata properties.\n */\n [key: string]: unknown;\n}\n/**\n * Checks if a tool is an xAI built-in tool (like live_search).\n * Built-in tools are executed server-side by the xAI API.\n *\n * @param tool - The tool to check\n * @returns true if the tool is an xAI built-in tool\n */\nexport declare function isXAIBuiltInTool(tool: ChatXAIToolType): tool is XAIBuiltInTool;\nexport interface ChatXAICallOptions extends BaseChatModelCallOptions {\n headers?: Record<string, string>;\n /**\n * A list of tools the model may call.\n * Can include standard function tools and xAI built-in tools like `{ type: \"live_search\" }`.\n *\n * @example\n * ```typescript\n * // Using built-in live_search tool\n * const llm = new ChatXAI().bindTools([{ type: \"live_search\" }]);\n * const result = await llm.invoke(\"What happened in tech news today?\");\n * ```\n */\n tools?: ChatXAIToolType[];\n tool_choice?: OpenAIToolChoice | string | \"auto\" | \"any\";\n /**\n * Search parameters for xAI's Live Search API.\n * Enables the model to search the web for real-time information.\n *\n * @note This is an alternative to using `tools: [{ type: \"live_search\" }]`.\n * The Live Search API parameters approach may be deprecated in favor of\n * the tool-based approach.\n *\n * @example\n * ```typescript\n * const result = await llm.invoke(\"What's the latest news?\", {\n * searchParameters: {\n * mode: \"auto\",\n * max_search_results: 5,\n * }\n * });\n * ```\n */\n searchParameters?: XAISearchParameters;\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 * Default search parameters for xAI's Live Search API.\n * When set, these parameters will be applied to all requests unless\n * overridden in the call options.\n *\n * @example\n * ```typescript\n * const llm = new ChatXAI({\n * model: \"grok-beta\",\n * searchParameters: {\n * mode: \"auto\",\n * max_search_results: 5,\n * }\n * });\n * ```\n */\n searchParameters?: XAISearchParameters;\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 *\n * <details>\n * <summary><strong>Server Tool Calling (Live Search)</strong></summary>\n *\n * xAI supports server-side tools that are executed by the API rather than\n * requiring client-side execution. The `live_search` tool enables the model\n * to search the web for real-time information.\n *\n * ```typescript\n * // Method 1: Using the built-in live_search tool\n * const llm = new ChatXAI({\n * model: \"grok-beta\",\n * temperature: 0,\n * });\n *\n * const llmWithSearch = llm.bindTools([{ type: \"live_search\" }]);\n * const result = await llmWithSearch.invoke(\"What happened in tech news today?\");\n * console.log(result.content);\n * // The model will search the web and include real-time information in its response\n * ```\n *\n * ```typescript\n * // Method 2: Using searchParameters for more control\n * const llm = new ChatXAI({\n * model: \"grok-beta\",\n * searchParameters: {\n * mode: \"auto\", // \"auto\" | \"on\" | \"off\"\n * max_search_results: 5,\n * from_date: \"2024-01-01\", // ISO date string\n * return_citations: true,\n * }\n * });\n *\n * const result = await llm.invoke(\"What are the latest AI developments?\");\n * ```\n *\n * ```typescript\n * // Method 3: Override search parameters per request\n * const result = await llm.invoke(\"Find recent news about SpaceX\", {\n * searchParameters: {\n * mode: \"on\",\n * max_search_results: 10,\n * sources: [\n * { type: \"web\", allowed_websites: [\"spacex.com\", \"nasa.gov\"] },\n * ],\n * }\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 /**\n * Default search parameters for the Live Search API.\n */\n searchParameters?: XAISearchParameters;\n constructor(fields?: Partial<ChatXAIInput>);\n toJSON(): Serialized;\n getLsParams(options: this[\"ParsedCallOptions\"]): LangSmithParams;\n /**\n * Get the effective search parameters, merging defaults with call options.\n * @param options Call options that may contain search parameters\n * @returns Merged search parameters or undefined if none are configured\n */\n protected _getEffectiveSearchParameters(options?: this[\"ParsedCallOptions\"]): XAISearchParameters | undefined;\n /**\n * Check if any built-in tools (like live_search) are in the tools list.\n * @param tools List of tools to check\n * @returns true if any built-in tools are present\n */\n protected _hasBuiltInTools(tools?: ChatXAIToolType[]): boolean;\n /**\n * Formats tools to xAI/OpenAI format, preserving provider-specific definitions.\n *\n * @param tools The tools to format\n * @returns The formatted tools\n */\n formatStructuredToolToXAI(tools: ChatXAIToolType[]): (OpenAIClient.ChatCompletionTool | XAIBuiltInTool)[] | undefined;\n bindTools(tools: ChatXAIToolType[], kwargs?: Partial<ChatXAICallOptions>): Runnable<BaseLanguageModelInput, AIMessageChunk, ChatXAICallOptions>;\n /** @internal */\n invocationParams(options?: this[\"ParsedCallOptions\"], extra?: {\n streaming?: boolean;\n }): ChatXAICompletionsInvocationParams;\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(delta: Record<string, any>, rawResponse: OpenAIClient.ChatCompletionChunk, defaultRole?: \"function\" | \"user\" | \"system\" | \"developer\" | \"assistant\" | \"tool\"): AIMessageChunk;\n protected _convertCompletionsMessageToBaseMessage(message: OpenAIClient.ChatCompletionMessage & {\n reasoning_content?: string;\n }, rawResponse: OpenAIClient.ChatCompletion): AIMessageChunk;\n /**\n * Return profiling information for the model.\n *\n * Provides information about the model's capabilities and constraints,\n * including token limits, multimodal support, and advanced features like\n * tool calling and structured output.\n *\n * @returns {ModelProfile} An object describing the model's capabilities and constraints\n *\n * @example\n * ```typescript\n * const model = new ChatXAI({ model: \"grok-beta\" });\n * const profile = model.profile;\n * console.log(profile.maxInputTokens); // 128000\n * console.log(profile.imageInputs); // true\n * ```\n */\n get profile(): ModelProfile;\n withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;\n withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {\n raw: BaseMessage;\n parsed: RunOutput;\n }>;\n withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<boolean>): Runnable<BaseLanguageModelInput, RunOutput> | Runnable<BaseLanguageModelInput, {\n raw: BaseMessage;\n parsed: RunOutput;\n }>;\n}\nexport {};\n//# sourceMappingURL=completions.d.ts.map"],"mappings":";;;;;;;;;;;;KAUYmB,gBAAAA,GAAmBL,YAAAA,CAAaM;;AAA5C;AAIA;A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sBAAsBA,mCAAmCtB,eAAe0B,aAAaJ,8BAA8BjC,uCAAuCU,SAASX,wBAAwBsC;yCAC3LJ,sBAAsBA,mCAAmCtB,eAAe0B,aAAaJ,8BAA8BjC,sCAAsCU,SAASX;SAChMS;YACG6B;;yCAE2BJ,sBAAsBA,mCAAmCtB,eAAe0B,aAAaJ,8BAA8BjC,yCAAyCU,SAASX,wBAAwBsC,aAAa3B,SAASX;SACjPS;YACG6B"}
|
|
1
|
+
{"version":3,"file":"completions.d.ts","names":["BaseLanguageModelInput","StructuredOutputMethodOptions","BaseChatModelCallOptions","BindToolsInput","LangSmithParams","BaseChatModelParams","ModelProfile","Serialized","AIMessageChunk","BaseMessage","UsageMetadata","Runnable","InteropZodType","OpenAICoreRequestOptions","OpenAIClient","ChatOpenAICompletions","XAISearchParameters","XAISearchParametersPayload","XAILiveSearchTool","OpenAIToolChoice","ChatCompletionToolChoiceOption","XAIBuiltInTool","ChatXAIToolType","ChatCompletionTool","ChatXAICompletionsInvocationParams","Chat","Completions","ChatCompletionCreateParams","Omit","XAIAdditionalKwargs","ChatCompletionMessageToolCall","XAIResponseMetadata","isXAIBuiltInTool","ChatXAICallOptions","Record","ChatXAIInput","Array","ChatXAI","RunOutput","Partial","ChatCompletionCreateParamsStreaming","ChatCompletionChunk","AsyncIterable","Promise","ChatCompletionCreateParamsNonStreaming","ChatCompletion","ChatCompletionMessage"],"sources":["../../src/chat_models/completions.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 { ModelProfile } from \"@langchain/core/language_models/profile\";\nimport { Serialized } from \"@langchain/core/load/serializable\";\nimport { AIMessageChunk, BaseMessage, type UsageMetadata } from \"@langchain/core/messages\";\nimport { Runnable } from \"@langchain/core/runnables\";\nimport { InteropZodType } from \"@langchain/core/utils/types\";\nimport { type OpenAICoreRequestOptions, type OpenAIClient, ChatOpenAICompletions } from \"@langchain/openai\";\nimport { type XAISearchParameters, type XAISearchParametersPayload } from \"../live_search.js\";\nimport { XAILiveSearchTool } from \"../tools/live_search.js\";\nexport type OpenAIToolChoice = OpenAIClient.ChatCompletionToolChoiceOption | \"any\" | string;\n/**\n * Union type for all xAI built-in server-side tools.\n */\nexport type XAIBuiltInTool = XAILiveSearchTool;\n/**\n * Tool type that includes both standard tools and xAI built-in tools.\n */\ntype ChatXAIToolType = BindToolsInput | OpenAIClient.ChatCompletionTool | XAIBuiltInTool;\n/**\n * xAI-specific invocation parameters that extend the OpenAI completion params\n * with xAI's search_parameters field.\n */\nexport type ChatXAICompletionsInvocationParams = Omit<OpenAIClient.Chat.Completions.ChatCompletionCreateParams, \"messages\"> & {\n /**\n * Search parameters for xAI's Live Search API.\n * When present, enables the model to search the web for real-time information.\n */\n search_parameters?: XAISearchParametersPayload;\n};\n/**\n * xAI-specific additional kwargs that may be present on AI messages.\n * Includes xAI-specific fields like reasoning_content.\n */\nexport interface XAIAdditionalKwargs {\n /**\n * The reasoning content from xAI models that support chain-of-thought reasoning.\n * This contains the model's internal reasoning process.\n */\n reasoning_content?: string;\n /**\n * Tool calls made by the model.\n */\n tool_calls?: OpenAIClient.ChatCompletionMessageToolCall[];\n /**\n * Additional properties that may be present.\n */\n [key: string]: unknown;\n}\n/**\n * xAI-specific response metadata that may include usage information.\n */\nexport interface XAIResponseMetadata {\n /**\n * Token usage information.\n */\n usage?: UsageMetadata;\n /**\n * Additional metadata properties.\n */\n [key: string]: unknown;\n}\n/**\n * Checks if a tool is an xAI built-in tool (like live_search).\n * Built-in tools are executed server-side by the xAI API.\n *\n * @param tool - The tool to check\n * @returns true if the tool is an xAI built-in tool\n */\nexport declare function isXAIBuiltInTool(tool: ChatXAIToolType): tool is XAIBuiltInTool;\nexport interface ChatXAICallOptions extends BaseChatModelCallOptions {\n headers?: Record<string, string>;\n /**\n * A list of tools the model may call.\n * Can include standard function tools and xAI built-in tools like `{ type: \"live_search\" }`.\n *\n * @example\n * ```typescript\n * // Using built-in live_search tool\n * const llm = new ChatXAI().bindTools([{ type: \"live_search\" }]);\n * const result = await llm.invoke(\"What happened in tech news today?\");\n * ```\n */\n tools?: ChatXAIToolType[];\n tool_choice?: OpenAIToolChoice | string | \"auto\" | \"any\";\n /**\n * Search parameters for xAI's Live Search API.\n * Enables the model to search the web for real-time information.\n *\n * @note This is an alternative to using `tools: [{ type: \"live_search\" }]`.\n * The Live Search API parameters approach may be deprecated in favor of\n * the tool-based approach.\n *\n * @example\n * ```typescript\n * const result = await llm.invoke(\"What's the latest news?\", {\n * searchParameters: {\n * mode: \"auto\",\n * max_search_results: 5,\n * }\n * });\n * ```\n */\n searchParameters?: XAISearchParameters;\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 * Default search parameters for xAI's Live Search API.\n * When set, these parameters will be applied to all requests unless\n * overridden in the call options.\n *\n * @example\n * ```typescript\n * const llm = new ChatXAI({\n * model: \"grok-beta\",\n * searchParameters: {\n * mode: \"auto\",\n * max_search_results: 5,\n * }\n * });\n * ```\n */\n searchParameters?: XAISearchParameters;\n /**\n * The base URL for the xAI API.\n * @default \"https://api.x.ai/v1\"\n */\n baseURL?: string;\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 *\n * <details>\n * <summary><strong>Server Tool Calling (Live Search)</strong></summary>\n *\n * xAI supports server-side tools that are executed by the API rather than\n * requiring client-side execution. The `live_search` tool enables the model\n * to search the web for real-time information.\n *\n * ```typescript\n * // Method 1: Using the built-in live_search tool\n * const llm = new ChatXAI({\n * model: \"grok-beta\",\n * temperature: 0,\n * });\n *\n * const llmWithSearch = llm.bindTools([{ type: \"live_search\" }]);\n * const result = await llmWithSearch.invoke(\"What happened in tech news today?\");\n * console.log(result.content);\n * // The model will search the web and include real-time information in its response\n * ```\n *\n * ```typescript\n * // Method 2: Using searchParameters for more control\n * const llm = new ChatXAI({\n * model: \"grok-beta\",\n * searchParameters: {\n * mode: \"auto\", // \"auto\" | \"on\" | \"off\"\n * max_search_results: 5,\n * from_date: \"2024-01-01\", // ISO date string\n * return_citations: true,\n * }\n * });\n *\n * const result = await llm.invoke(\"What are the latest AI developments?\");\n * ```\n *\n * ```typescript\n * // Method 3: Override search parameters per request\n * const result = await llm.invoke(\"Find recent news about SpaceX\", {\n * searchParameters: {\n * mode: \"on\",\n * max_search_results: 10,\n * sources: [\n * { type: \"web\", allowed_websites: [\"spacex.com\", \"nasa.gov\"] },\n * ],\n * }\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 /**\n * Default search parameters for the Live Search API.\n */\n searchParameters?: XAISearchParameters;\n constructor(fields?: Partial<ChatXAIInput>);\n toJSON(): Serialized;\n getLsParams(options: this[\"ParsedCallOptions\"]): LangSmithParams;\n /**\n * Get the effective search parameters, merging defaults with call options.\n * @param options Call options that may contain search parameters\n * @returns Merged search parameters or undefined if none are configured\n */\n protected _getEffectiveSearchParameters(options?: this[\"ParsedCallOptions\"]): XAISearchParameters | undefined;\n /**\n * Check if any built-in tools (like live_search) are in the tools list.\n * @param tools List of tools to check\n * @returns true if any built-in tools are present\n */\n protected _hasBuiltInTools(tools?: ChatXAIToolType[]): boolean;\n /**\n * Formats tools to xAI/OpenAI format, preserving provider-specific definitions.\n *\n * @param tools The tools to format\n * @returns The formatted tools\n */\n formatStructuredToolToXAI(tools: ChatXAIToolType[]): (OpenAIClient.ChatCompletionTool | XAIBuiltInTool)[] | undefined;\n bindTools(tools: ChatXAIToolType[], kwargs?: Partial<ChatXAICallOptions>): Runnable<BaseLanguageModelInput, AIMessageChunk, ChatXAICallOptions>;\n /** @internal */\n invocationParams(options?: this[\"ParsedCallOptions\"], extra?: {\n streaming?: boolean;\n }): ChatXAICompletionsInvocationParams;\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(delta: Record<string, any>, rawResponse: OpenAIClient.ChatCompletionChunk, defaultRole?: \"function\" | \"user\" | \"system\" | \"developer\" | \"assistant\" | \"tool\"): AIMessageChunk;\n protected _convertCompletionsMessageToBaseMessage(message: OpenAIClient.ChatCompletionMessage & {\n reasoning_content?: string;\n }, rawResponse: OpenAIClient.ChatCompletion): AIMessageChunk;\n /**\n * Return profiling information for the model.\n *\n * Provides information about the model's capabilities and constraints,\n * including token limits, multimodal support, and advanced features like\n * tool calling and structured output.\n *\n * @returns {ModelProfile} An object describing the model's capabilities and constraints\n *\n * @example\n * ```typescript\n * const model = new ChatXAI({ model: \"grok-beta\" });\n * const profile = model.profile;\n * console.log(profile.maxInputTokens); // 128000\n * console.log(profile.imageInputs); // true\n * ```\n */\n get profile(): ModelProfile;\n withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;\n withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {\n raw: BaseMessage;\n parsed: RunOutput;\n }>;\n withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<boolean>): Runnable<BaseLanguageModelInput, RunOutput> | Runnable<BaseLanguageModelInput, {\n raw: BaseMessage;\n parsed: RunOutput;\n }>;\n}\nexport {};\n//# sourceMappingURL=completions.d.ts.map"],"mappings":";;;;;;;;;;;;KAUYmB,gBAAAA,GAAmBL,YAAAA,CAAaM;;AAA5C;AAIA;AAIKE,KAJOD,cAAAA,GAAiBH,iBAIT;;;;AAAoE,KAAnFI,eAAAA,GAAkBnB,cAAiE,GAAhDW,YAAAA,CAAaS,kBAAmC,GAAdF,cAAc;AAKxF;;;;AAKkD,KALtCG,kCAAAA,GAAqCI,IAKC,CALId,YAAAA,CAAaW,IAAAA,CAAKC,WAAAA,CAAYC,0BAKlC,EAAA,UAAA,CAAA,GAAA;EAMjCE;AAkBjB;AAiBA;AACA;EACcK,iBAAAA,CAAAA,EA3CUjB,0BA2CViB;CAYFZ;;;;AAbwD;AAmCnDa,UAvEAN,mBAAAA,CAuEY;EAgBlBO;;;;EAhB8C,iBAAA,CAAA,EAAA,MAAA;EAobpCC;;;EAYYF,UAAAA,CAAAA,EA9fhBrB,YAAAA,CAAagB,6BA8fGK,EAAAA;EAARI;;;EAQyDvB,CAAAA,GAAAA,EAAAA,MAAAA,CAAAA,EAAAA,OAAAA;;;;;AAc7DM,UA3gBJS,mBAAAA,CA2gBIT;EAAoCW;;;EAAuDzB,KAAAA,CAAAA,EAvgBpGE,aAugBoGF;EAAgByB;;;EAK/FnB,CAAAA,GAAAA,EAAAA,MAAaW,CAAAA,EAAKe,OAAAA;;;;;;;;;AAEaN,iBAjgBxCF,gBAAAA,CAigBwCE,IAAAA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F;mBACvEC,4BAA4BiB,QAAQN,sBAAsBtB,SAASX,wBAAwBQ,gBAAgByB;;;;MAIxHT;+BACyBV,YAAAA,CAAaW,IAAAA,CAAKe,+CAA+C3B,2BAA2B8B,QAAQD,cAAc5B,YAAAA,CAAaW,IAAAA,CAAKC,WAAAA,CAAYe;+BAChJ3B,YAAAA,CAAaW,IAAAA,CAAKmB,kDAAkD/B,2BAA2B8B,QAAQ7B,YAAAA,CAAaW,IAAAA,CAAKC,WAAAA,CAAYmB;8DACtGX,kCAAkCpB,YAAAA,CAAa2B,yGAAyGjC;6DACzJM,YAAAA,CAAagC;;kBAExDhC,YAAAA,CAAa+B,iBAAiBrC;;;;;;;;;;;;;;;;;;iBAkB/BF;yCACwB4B,sBAAsBA,mCAAmCtB,eAAe0B,aAAaJ,8BAA8BjC,uCAAuCU,SAASX,wBAAwBsC;yCAC3LJ,sBAAsBA,mCAAmCtB,eAAe0B,aAAaJ,8BAA8BjC,sCAAsCU,SAASX;SAChMS;YACG6B;;yCAE2BJ,sBAAsBA,mCAAmCtB,eAAe0B,aAAaJ,8BAA8BjC,yCAAyCU,SAASX,wBAAwBsC,aAAa3B,SAASX;SACjPS;YACG6B"}
|
|
@@ -426,7 +426,7 @@ var ChatXAI = class extends ChatOpenAICompletions {
|
|
|
426
426
|
...fields,
|
|
427
427
|
model: fields?.model || "grok-beta",
|
|
428
428
|
apiKey,
|
|
429
|
-
configuration: { baseURL: "https://api.x.ai/v1" }
|
|
429
|
+
configuration: { baseURL: fields?.baseURL ?? "https://api.x.ai/v1" }
|
|
430
430
|
});
|
|
431
431
|
this.searchParameters = fields?.searchParameters;
|
|
432
432
|
}
|