@langchain/xai 1.3.7 → 1.3.9-dev-1773345797648
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 +9 -0
- package/README.md +3 -3
- package/dist/chat_models/completions.cjs +7 -12
- package/dist/chat_models/completions.cjs.map +1 -1
- package/dist/chat_models/completions.d.cts +9 -19
- package/dist/chat_models/completions.d.cts.map +1 -1
- package/dist/chat_models/completions.d.ts +9 -19
- package/dist/chat_models/completions.d.ts.map +1 -1
- package/dist/chat_models/completions.js +7 -12
- package/dist/chat_models/completions.js.map +1 -1
- package/dist/chat_models/responses.cjs +1 -1
- package/dist/chat_models/responses.cjs.map +1 -1
- package/dist/chat_models/responses.js +1 -1
- package/dist/chat_models/responses.js.map +1 -1
- package/dist/profiles.cjs +19 -61
- package/dist/profiles.cjs.map +1 -1
- package/dist/profiles.js +19 -61
- package/dist/profiles.js.map +1 -1
- package/dist/tools/live_search.cjs +1 -1
- package/dist/tools/live_search.cjs.map +1 -1
- package/dist/tools/live_search.d.cts +1 -1
- package/dist/tools/live_search.d.ts +1 -1
- package/dist/tools/live_search.js +1 -1
- package/dist/tools/live_search.js.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @langchain/xai
|
|
2
2
|
|
|
3
|
+
## 1.3.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#10216](https://github.com/langchain-ai/langchainjs/pull/10216) [`445797f`](https://github.com/langchain-ai/langchainjs/commit/445797fb5f758ac561b3199344b8f0ea173e4d09) Thanks [@colifran](https://github.com/colifran)! - feat(xai): implement standard schema support for structured output
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`3682a8d`](https://github.com/langchain-ai/langchainjs/commit/3682a8d4e0ed0855a5283f26bcfd1c0415dde075)]:
|
|
10
|
+
- @langchain/openai@1.2.12
|
|
11
|
+
|
|
3
12
|
## 1.3.7
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -41,7 +41,7 @@ xAI supports server-side tools that are executed by the API rather than requirin
|
|
|
41
41
|
import { ChatXAI, tools } from "@langchain/xai";
|
|
42
42
|
|
|
43
43
|
const model = new ChatXAI({
|
|
44
|
-
model: "grok-
|
|
44
|
+
model: "grok-3-fast",
|
|
45
45
|
});
|
|
46
46
|
|
|
47
47
|
// Create the built-in live_search tool with optional parameters
|
|
@@ -66,7 +66,7 @@ console.log(result.content);
|
|
|
66
66
|
import { ChatXAI } from "@langchain/xai";
|
|
67
67
|
|
|
68
68
|
const model = new ChatXAI({
|
|
69
|
-
model: "grok-
|
|
69
|
+
model: "grok-3-fast",
|
|
70
70
|
searchParameters: {
|
|
71
71
|
mode: "auto", // "auto" | "on" | "off"
|
|
72
72
|
max_search_results: 5,
|
|
@@ -159,7 +159,7 @@ const result = await model.invoke("Summarize the latest posts from this feed", {
|
|
|
159
159
|
```typescript
|
|
160
160
|
import { ChatXAI, tools } from "@langchain/xai";
|
|
161
161
|
|
|
162
|
-
const model = new ChatXAI({ model: "grok-
|
|
162
|
+
const model = new ChatXAI({ model: "grok-3-fast" });
|
|
163
163
|
|
|
164
164
|
const modelWithTools = model.bindTools([
|
|
165
165
|
tools.xaiLiveSearch(), // Built-in server tool
|
|
@@ -67,7 +67,7 @@ function isXAIBuiltInTool(tool) {
|
|
|
67
67
|
* import { ChatXAI } from '@langchain/xai';
|
|
68
68
|
*
|
|
69
69
|
* const llm = new ChatXAI({
|
|
70
|
-
* model: "grok-
|
|
70
|
+
* model: "grok-3-fast",
|
|
71
71
|
* temperature: 0,
|
|
72
72
|
* // other params...
|
|
73
73
|
* });
|
|
@@ -261,7 +261,7 @@ function isXAIBuiltInTool(tool) {
|
|
|
261
261
|
* import { z } from 'zod';
|
|
262
262
|
*
|
|
263
263
|
* const llmForToolCalling = new ChatXAI({
|
|
264
|
-
* model: "grok-
|
|
264
|
+
* model: "grok-3-fast",
|
|
265
265
|
* temperature: 0,
|
|
266
266
|
* // other params...
|
|
267
267
|
* });
|
|
@@ -358,7 +358,7 @@ function isXAIBuiltInTool(tool) {
|
|
|
358
358
|
* ```typescript
|
|
359
359
|
* // Method 1: Using the built-in live_search tool
|
|
360
360
|
* const llm = new ChatXAI({
|
|
361
|
-
* model: "grok-
|
|
361
|
+
* model: "grok-3-fast",
|
|
362
362
|
* temperature: 0,
|
|
363
363
|
* });
|
|
364
364
|
*
|
|
@@ -371,7 +371,7 @@ function isXAIBuiltInTool(tool) {
|
|
|
371
371
|
* ```typescript
|
|
372
372
|
* // Method 2: Using searchParameters for more control
|
|
373
373
|
* const llm = new ChatXAI({
|
|
374
|
-
* model: "grok-
|
|
374
|
+
* model: "grok-3-fast",
|
|
375
375
|
* searchParameters: {
|
|
376
376
|
* mode: "auto", // "auto" | "on" | "off"
|
|
377
377
|
* max_search_results: 5,
|
|
@@ -428,11 +428,11 @@ var ChatXAI = class extends _langchain_openai.ChatOpenAICompletions {
|
|
|
428
428
|
if (!apiKey) throw new Error(`xAI API key not found. Please set the XAI_API_KEY environment variable or provide the key into "apiKey" field.`);
|
|
429
429
|
super({
|
|
430
430
|
...fields,
|
|
431
|
-
model: fields?.model || "grok-
|
|
431
|
+
model: fields?.model || "grok-3-fast",
|
|
432
432
|
apiKey,
|
|
433
433
|
configuration: { baseURL: fields?.baseURL ?? "https://api.x.ai/v1" }
|
|
434
434
|
});
|
|
435
|
-
this._addVersion("@langchain/xai", "1.3.
|
|
435
|
+
this._addVersion("@langchain/xai", "1.3.9-dev-1773345797648");
|
|
436
436
|
this.searchParameters = fields?.searchParameters;
|
|
437
437
|
}
|
|
438
438
|
toJSON() {
|
|
@@ -549,7 +549,7 @@ var ChatXAI = class extends _langchain_openai.ChatOpenAICompletions {
|
|
|
549
549
|
*
|
|
550
550
|
* @example
|
|
551
551
|
* ```typescript
|
|
552
|
-
* const model = new ChatXAI({ model: "grok-
|
|
552
|
+
* const model = new ChatXAI({ model: "grok-3-fast" });
|
|
553
553
|
* const profile = model.profile;
|
|
554
554
|
* console.log(profile.maxInputTokens); // 128000
|
|
555
555
|
* console.log(profile.imageInputs); // true
|
|
@@ -558,11 +558,6 @@ var ChatXAI = class extends _langchain_openai.ChatOpenAICompletions {
|
|
|
558
558
|
get profile() {
|
|
559
559
|
return require_profiles.default[this.model] ?? {};
|
|
560
560
|
}
|
|
561
|
-
withStructuredOutput(outputSchema, config) {
|
|
562
|
-
const ensuredConfig = { ...config };
|
|
563
|
-
if (ensuredConfig?.method === void 0) ensuredConfig.method = "functionCalling";
|
|
564
|
-
return super.withStructuredOutput(outputSchema, ensuredConfig);
|
|
565
|
-
}
|
|
566
561
|
};
|
|
567
562
|
|
|
568
563
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"completions.cjs","names":["XAI_LIVE_SEARCH_TOOL_TYPE","ChatOpenAICompletions","mergeSearchParams","buildSearchParametersPayload","filterXAIBuiltInTools","PROFILES"],"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(model: string, fields?: Omit<ChatXAIInput, \"model\">);\n constructor(fields?: Partial<ChatXAIInput>);\n constructor(\n modelOrFields?: string | Partial<ChatXAIInput>,\n fieldsArg?: Omit<ChatXAIInput, \"model\">\n ) {\n const fields =\n typeof modelOrFields === \"string\"\n ? { ...(fieldsArg ?? {}), model: modelOrFields }\n : (modelOrFields ?? {});\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._addVersion(\"@langchain/xai\", __PKG_VERSION__);\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,gDACD,CAAC;;;;;;;;AAkEF,SAAgB,iBACd,MACwB;AACxB,QACE,OAAO,SAAS,YAChB,SAAS,QACT,UAAU,QACV,OAAQ,KAA4B,SAAS,YAC7C,wBAAwB,IAAK,KAA0B,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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iBAAiB,iBAAiB;AAEjD,SAAO;;CAGT,AAAmB,wCACjB,SAGA,aACgB;EAChB,MAAM,mBAAmB,MAAM,wCAC7B,SACA,YACD;EAGD,MAAM,mBACJ,iBAAiB;AACnB,mBAAiB,oBAAoB,QAAQ;AAE7C,SAAO;;;;;;;;;;;;;;;;;;;CAoBT,IAAI,UAAwB;AAC1B,SAAOK,yBAAS,KAAK,UAAU,EAAE;;CAsCnC,AAAS,qBAIP,cAIA,QAMI;EACJ,MAAM,gBAAgB,EAAE,GAAG,QAAQ;AACnC,MAAI,eAAe,WAAW,OAC5B,eAAc,SAAS;AAEzB,SAAO,MAAM,qBAAgC,cAAc,cAAc"}
|
|
1
|
+
{"version":3,"file":"completions.cjs","names":["XAI_LIVE_SEARCH_TOOL_TYPE","ChatOpenAICompletions","mergeSearchParams","buildSearchParametersPayload","filterXAIBuiltInTools","PROFILES"],"sources":["../../src/chat_models/completions.ts"],"sourcesContent":["import { BaseLanguageModelInput } 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 { AIMessageChunk, type UsageMetadata } from \"@langchain/core/messages\";\nimport { Runnable } from \"@langchain/core/runnables\";\nimport { getEnvironmentVariable } from \"@langchain/core/utils/env\";\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-3-fast\"\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-3-fast\",\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-3-fast\",\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-3-fast\",\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-3-fast\",\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-3-fast\",\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(model: string, fields?: Omit<ChatXAIInput, \"model\">);\n constructor(fields?: Partial<ChatXAIInput>);\n constructor(\n modelOrFields?: string | Partial<ChatXAIInput>,\n fieldsArg?: Omit<ChatXAIInput, \"model\">\n ) {\n const fields =\n typeof modelOrFields === \"string\"\n ? { ...(fieldsArg ?? {}), model: modelOrFields }\n : (modelOrFields ?? {});\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-3-fast\",\n apiKey,\n configuration: {\n baseURL: fields?.baseURL ?? \"https://api.x.ai/v1\",\n },\n });\n\n this._addVersion(\"@langchain/xai\", __PKG_VERSION__);\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-3-fast\" });\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"],"mappings":";;;;;;;;;;;;;AAiDA,MAAM,0BAA0B,IAAI,IAAwC,CAC1EA,gDACD,CAAC;;;;;;;;AAkEF,SAAgB,iBACd,MACwB;AACxB,QACE,OAAO,SAAS,YAChB,SAAS,QACT,UAAU,QACV,OAAQ,KAA4B,SAAS,YAC7C,wBAAwB,IAAK,KAA0B,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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A,aACgB;EAChB,MAAM,mBAAmB,MAAM,wCAC7B,SACA,YACD;EAGD,MAAM,mBACJ,iBAAiB;AACnB,mBAAiB,oBAAoB,QAAQ;AAE7C,SAAO;;;;;;;;;;;;;;;;;;;CAoBT,IAAI,UAAwB;AAC1B,SAAOK,yBAAS,KAAK,UAAU,EAAE"}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { XAISearchParameters, XAISearchParametersPayload } from "../live_search.cjs";
|
|
2
2
|
import { XAILiveSearchTool } from "../tools/live_search.cjs";
|
|
3
|
-
import { BaseLanguageModelInput
|
|
3
|
+
import { BaseLanguageModelInput } from "@langchain/core/language_models/base";
|
|
4
4
|
import { BaseChatModelCallOptions, BaseChatModelParams, BindToolsInput, LangSmithParams } from "@langchain/core/language_models/chat_models";
|
|
5
5
|
import { ModelProfile } from "@langchain/core/language_models/profile";
|
|
6
6
|
import { Serialized } from "@langchain/core/load/serializable";
|
|
7
|
-
import { AIMessageChunk,
|
|
7
|
+
import { AIMessageChunk, UsageMetadata } from "@langchain/core/messages";
|
|
8
8
|
import { Runnable } from "@langchain/core/runnables";
|
|
9
|
-
import { InteropZodType } from "@langchain/core/utils/types";
|
|
10
9
|
import { ChatOpenAICompletions, OpenAIClient, OpenAICoreRequestOptions } from "@langchain/openai";
|
|
11
10
|
|
|
12
11
|
//#region src/chat_models/completions.d.ts
|
|
@@ -113,7 +112,7 @@ interface ChatXAIInput extends BaseChatModelParams {
|
|
|
113
112
|
apiKey?: string;
|
|
114
113
|
/**
|
|
115
114
|
* The name of the model to use.
|
|
116
|
-
* @default "grok-
|
|
115
|
+
* @default "grok-3-fast"
|
|
117
116
|
*/
|
|
118
117
|
model?: string;
|
|
119
118
|
/**
|
|
@@ -149,7 +148,7 @@ interface ChatXAIInput extends BaseChatModelParams {
|
|
|
149
148
|
* @example
|
|
150
149
|
* ```typescript
|
|
151
150
|
* const llm = new ChatXAI({
|
|
152
|
-
* model: "grok-
|
|
151
|
+
* model: "grok-3-fast",
|
|
153
152
|
* searchParameters: {
|
|
154
153
|
* mode: "auto",
|
|
155
154
|
* max_search_results: 5,
|
|
@@ -209,7 +208,7 @@ interface ChatXAIInput extends BaseChatModelParams {
|
|
|
209
208
|
* import { ChatXAI } from '@langchain/xai';
|
|
210
209
|
*
|
|
211
210
|
* const llm = new ChatXAI({
|
|
212
|
-
* model: "grok-
|
|
211
|
+
* model: "grok-3-fast",
|
|
213
212
|
* temperature: 0,
|
|
214
213
|
* // other params...
|
|
215
214
|
* });
|
|
@@ -403,7 +402,7 @@ interface ChatXAIInput extends BaseChatModelParams {
|
|
|
403
402
|
* import { z } from 'zod';
|
|
404
403
|
*
|
|
405
404
|
* const llmForToolCalling = new ChatXAI({
|
|
406
|
-
* model: "grok-
|
|
405
|
+
* model: "grok-3-fast",
|
|
407
406
|
* temperature: 0,
|
|
408
407
|
* // other params...
|
|
409
408
|
* });
|
|
@@ -500,7 +499,7 @@ interface ChatXAIInput extends BaseChatModelParams {
|
|
|
500
499
|
* ```typescript
|
|
501
500
|
* // Method 1: Using the built-in live_search tool
|
|
502
501
|
* const llm = new ChatXAI({
|
|
503
|
-
* model: "grok-
|
|
502
|
+
* model: "grok-3-fast",
|
|
504
503
|
* temperature: 0,
|
|
505
504
|
* });
|
|
506
505
|
*
|
|
@@ -513,7 +512,7 @@ interface ChatXAIInput extends BaseChatModelParams {
|
|
|
513
512
|
* ```typescript
|
|
514
513
|
* // Method 2: Using searchParameters for more control
|
|
515
514
|
* const llm = new ChatXAI({
|
|
516
|
-
* model: "grok-
|
|
515
|
+
* model: "grok-3-fast",
|
|
517
516
|
* searchParameters: {
|
|
518
517
|
* mode: "auto", // "auto" | "on" | "off"
|
|
519
518
|
* max_search_results: 5,
|
|
@@ -598,22 +597,13 @@ declare class ChatXAI extends ChatOpenAICompletions<ChatXAICallOptions> {
|
|
|
598
597
|
*
|
|
599
598
|
* @example
|
|
600
599
|
* ```typescript
|
|
601
|
-
* const model = new ChatXAI({ model: "grok-
|
|
600
|
+
* const model = new ChatXAI({ model: "grok-3-fast" });
|
|
602
601
|
* const profile = model.profile;
|
|
603
602
|
* console.log(profile.maxInputTokens); // 128000
|
|
604
603
|
* console.log(profile.imageInputs); // true
|
|
605
604
|
* ```
|
|
606
605
|
*/
|
|
607
606
|
get profile(): ModelProfile;
|
|
608
|
-
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;
|
|
609
|
-
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {
|
|
610
|
-
raw: BaseMessage;
|
|
611
|
-
parsed: RunOutput;
|
|
612
|
-
}>;
|
|
613
|
-
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<boolean>): Runnable<BaseLanguageModelInput, RunOutput> | Runnable<BaseLanguageModelInput, {
|
|
614
|
-
raw: BaseMessage;
|
|
615
|
-
parsed: RunOutput;
|
|
616
|
-
}>;
|
|
617
607
|
}
|
|
618
608
|
//#endregion
|
|
619
609
|
export { ChatXAI, ChatXAICallOptions, ChatXAICompletionsInvocationParams, ChatXAIInput, OpenAIToolChoice, XAIAdditionalKwargs, XAIBuiltInTool, XAIResponseMetadata, isXAIBuiltInTool };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"completions.d.cts","names":[],"sources":["../../src/chat_models/completions.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"completions.d.cts","names":[],"sources":["../../src/chat_models/completions.ts"],"mappings":";;;;;;;;;;;KAkCY,gBAAA,GACR,YAAA,CAAa,8BAAA;;AADjB;;KAQY,cAAA,GAAiB,iBAAA;;;AAA7B;KAcK,eAAA,GACD,cAAA,GACA,YAAA,CAAa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AAA,UAqDtB,0CAAA,CAEjB,KAAA,EAAO,MAAA,eACP,WAAA,EAAa,YAAA,CAAa,mBAAA,EAC1B,WAAA,yEAOC,cAAA;EAAA,UAqBgB,uCAAA,CACjB,OAAA,EAAS,YAAA,CAAa,qBAAA;IACpB,iBAAA;EAAA,GAEF,WAAA,EAAa,YAAA,CAAa,cAAA,GACzB,cAAA;;;;;;;;;;;;;;;;;;MA+BC,OAAA,CAAA,GAAW,YAAA;AAAA"}
|
|
@@ -2,12 +2,11 @@ import { XAISearchParameters, XAISearchParametersPayload } from "../live_search.
|
|
|
2
2
|
import { XAILiveSearchTool } from "../tools/live_search.js";
|
|
3
3
|
import { ChatOpenAICompletions, OpenAIClient, OpenAICoreRequestOptions } from "@langchain/openai";
|
|
4
4
|
import { BaseChatModelCallOptions, BaseChatModelParams, BindToolsInput, LangSmithParams } from "@langchain/core/language_models/chat_models";
|
|
5
|
-
import { AIMessageChunk,
|
|
6
|
-
import { BaseLanguageModelInput
|
|
5
|
+
import { AIMessageChunk, UsageMetadata } from "@langchain/core/messages";
|
|
6
|
+
import { BaseLanguageModelInput } from "@langchain/core/language_models/base";
|
|
7
7
|
import { ModelProfile } from "@langchain/core/language_models/profile";
|
|
8
8
|
import { Serialized } from "@langchain/core/load/serializable";
|
|
9
9
|
import { Runnable } from "@langchain/core/runnables";
|
|
10
|
-
import { InteropZodType } from "@langchain/core/utils/types";
|
|
11
10
|
|
|
12
11
|
//#region src/chat_models/completions.d.ts
|
|
13
12
|
type OpenAIToolChoice = OpenAIClient.ChatCompletionToolChoiceOption | "any" | string;
|
|
@@ -113,7 +112,7 @@ interface ChatXAIInput extends BaseChatModelParams {
|
|
|
113
112
|
apiKey?: string;
|
|
114
113
|
/**
|
|
115
114
|
* The name of the model to use.
|
|
116
|
-
* @default "grok-
|
|
115
|
+
* @default "grok-3-fast"
|
|
117
116
|
*/
|
|
118
117
|
model?: string;
|
|
119
118
|
/**
|
|
@@ -149,7 +148,7 @@ interface ChatXAIInput extends BaseChatModelParams {
|
|
|
149
148
|
* @example
|
|
150
149
|
* ```typescript
|
|
151
150
|
* const llm = new ChatXAI({
|
|
152
|
-
* model: "grok-
|
|
151
|
+
* model: "grok-3-fast",
|
|
153
152
|
* searchParameters: {
|
|
154
153
|
* mode: "auto",
|
|
155
154
|
* max_search_results: 5,
|
|
@@ -209,7 +208,7 @@ interface ChatXAIInput extends BaseChatModelParams {
|
|
|
209
208
|
* import { ChatXAI } from '@langchain/xai';
|
|
210
209
|
*
|
|
211
210
|
* const llm = new ChatXAI({
|
|
212
|
-
* model: "grok-
|
|
211
|
+
* model: "grok-3-fast",
|
|
213
212
|
* temperature: 0,
|
|
214
213
|
* // other params...
|
|
215
214
|
* });
|
|
@@ -403,7 +402,7 @@ interface ChatXAIInput extends BaseChatModelParams {
|
|
|
403
402
|
* import { z } from 'zod';
|
|
404
403
|
*
|
|
405
404
|
* const llmForToolCalling = new ChatXAI({
|
|
406
|
-
* model: "grok-
|
|
405
|
+
* model: "grok-3-fast",
|
|
407
406
|
* temperature: 0,
|
|
408
407
|
* // other params...
|
|
409
408
|
* });
|
|
@@ -500,7 +499,7 @@ interface ChatXAIInput extends BaseChatModelParams {
|
|
|
500
499
|
* ```typescript
|
|
501
500
|
* // Method 1: Using the built-in live_search tool
|
|
502
501
|
* const llm = new ChatXAI({
|
|
503
|
-
* model: "grok-
|
|
502
|
+
* model: "grok-3-fast",
|
|
504
503
|
* temperature: 0,
|
|
505
504
|
* });
|
|
506
505
|
*
|
|
@@ -513,7 +512,7 @@ interface ChatXAIInput extends BaseChatModelParams {
|
|
|
513
512
|
* ```typescript
|
|
514
513
|
* // Method 2: Using searchParameters for more control
|
|
515
514
|
* const llm = new ChatXAI({
|
|
516
|
-
* model: "grok-
|
|
515
|
+
* model: "grok-3-fast",
|
|
517
516
|
* searchParameters: {
|
|
518
517
|
* mode: "auto", // "auto" | "on" | "off"
|
|
519
518
|
* max_search_results: 5,
|
|
@@ -598,22 +597,13 @@ declare class ChatXAI extends ChatOpenAICompletions<ChatXAICallOptions> {
|
|
|
598
597
|
*
|
|
599
598
|
* @example
|
|
600
599
|
* ```typescript
|
|
601
|
-
* const model = new ChatXAI({ model: "grok-
|
|
600
|
+
* const model = new ChatXAI({ model: "grok-3-fast" });
|
|
602
601
|
* const profile = model.profile;
|
|
603
602
|
* console.log(profile.maxInputTokens); // 128000
|
|
604
603
|
* console.log(profile.imageInputs); // true
|
|
605
604
|
* ```
|
|
606
605
|
*/
|
|
607
606
|
get profile(): ModelProfile;
|
|
608
|
-
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;
|
|
609
|
-
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {
|
|
610
|
-
raw: BaseMessage;
|
|
611
|
-
parsed: RunOutput;
|
|
612
|
-
}>;
|
|
613
|
-
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<boolean>): Runnable<BaseLanguageModelInput, RunOutput> | Runnable<BaseLanguageModelInput, {
|
|
614
|
-
raw: BaseMessage;
|
|
615
|
-
parsed: RunOutput;
|
|
616
|
-
}>;
|
|
617
607
|
}
|
|
618
608
|
//#endregion
|
|
619
609
|
export { ChatXAI, ChatXAICallOptions, ChatXAICompletionsInvocationParams, ChatXAIInput, OpenAIToolChoice, XAIAdditionalKwargs, XAIBuiltInTool, XAIResponseMetadata, isXAIBuiltInTool };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"completions.d.ts","names":[],"sources":["../../src/chat_models/completions.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"completions.d.ts","names":[],"sources":["../../src/chat_models/completions.ts"],"mappings":";;;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OAAA,EAAS,YAAA,CAAa,IAAA,CAAK,sCAAA,EAC3B,OAAA,GAAU,wBAAA,GACT,OAAA,CAAQ,YAAA,CAAa,IAAA,CAAK,WAAA,CAAY,cAAA;EAAA,UAqDtB,0CAAA,CAEjB,KAAA,EAAO,MAAA,eACP,WAAA,EAAa,YAAA,CAAa,mBAAA,EAC1B,WAAA,yEAOC,cAAA;EAAA,UAqBgB,uCAAA,CACjB,OAAA,EAAS,YAAA,CAAa,qBAAA;IACpB,iBAAA;EAAA,GAEF,WAAA,EAAa,YAAA,CAAa,cAAA,GACzB,cAAA;;;;;;;;;;;;;;;;;;MA+BC,OAAA,CAAA,GAAW,YAAA;AAAA"}
|
|
@@ -67,7 +67,7 @@ function isXAIBuiltInTool(tool) {
|
|
|
67
67
|
* import { ChatXAI } from '@langchain/xai';
|
|
68
68
|
*
|
|
69
69
|
* const llm = new ChatXAI({
|
|
70
|
-
* model: "grok-
|
|
70
|
+
* model: "grok-3-fast",
|
|
71
71
|
* temperature: 0,
|
|
72
72
|
* // other params...
|
|
73
73
|
* });
|
|
@@ -261,7 +261,7 @@ function isXAIBuiltInTool(tool) {
|
|
|
261
261
|
* import { z } from 'zod';
|
|
262
262
|
*
|
|
263
263
|
* const llmForToolCalling = new ChatXAI({
|
|
264
|
-
* model: "grok-
|
|
264
|
+
* model: "grok-3-fast",
|
|
265
265
|
* temperature: 0,
|
|
266
266
|
* // other params...
|
|
267
267
|
* });
|
|
@@ -358,7 +358,7 @@ function isXAIBuiltInTool(tool) {
|
|
|
358
358
|
* ```typescript
|
|
359
359
|
* // Method 1: Using the built-in live_search tool
|
|
360
360
|
* const llm = new ChatXAI({
|
|
361
|
-
* model: "grok-
|
|
361
|
+
* model: "grok-3-fast",
|
|
362
362
|
* temperature: 0,
|
|
363
363
|
* });
|
|
364
364
|
*
|
|
@@ -371,7 +371,7 @@ function isXAIBuiltInTool(tool) {
|
|
|
371
371
|
* ```typescript
|
|
372
372
|
* // Method 2: Using searchParameters for more control
|
|
373
373
|
* const llm = new ChatXAI({
|
|
374
|
-
* model: "grok-
|
|
374
|
+
* model: "grok-3-fast",
|
|
375
375
|
* searchParameters: {
|
|
376
376
|
* mode: "auto", // "auto" | "on" | "off"
|
|
377
377
|
* max_search_results: 5,
|
|
@@ -428,11 +428,11 @@ var ChatXAI = class extends ChatOpenAICompletions {
|
|
|
428
428
|
if (!apiKey) throw new Error(`xAI API key not found. Please set the XAI_API_KEY environment variable or provide the key into "apiKey" field.`);
|
|
429
429
|
super({
|
|
430
430
|
...fields,
|
|
431
|
-
model: fields?.model || "grok-
|
|
431
|
+
model: fields?.model || "grok-3-fast",
|
|
432
432
|
apiKey,
|
|
433
433
|
configuration: { baseURL: fields?.baseURL ?? "https://api.x.ai/v1" }
|
|
434
434
|
});
|
|
435
|
-
this._addVersion("@langchain/xai", "1.3.
|
|
435
|
+
this._addVersion("@langchain/xai", "1.3.9-dev-1773345797648");
|
|
436
436
|
this.searchParameters = fields?.searchParameters;
|
|
437
437
|
}
|
|
438
438
|
toJSON() {
|
|
@@ -549,7 +549,7 @@ var ChatXAI = class extends ChatOpenAICompletions {
|
|
|
549
549
|
*
|
|
550
550
|
* @example
|
|
551
551
|
* ```typescript
|
|
552
|
-
* const model = new ChatXAI({ model: "grok-
|
|
552
|
+
* const model = new ChatXAI({ model: "grok-3-fast" });
|
|
553
553
|
* const profile = model.profile;
|
|
554
554
|
* console.log(profile.maxInputTokens); // 128000
|
|
555
555
|
* console.log(profile.imageInputs); // true
|
|
@@ -558,11 +558,6 @@ var ChatXAI = class extends ChatOpenAICompletions {
|
|
|
558
558
|
get profile() {
|
|
559
559
|
return PROFILES[this.model] ?? {};
|
|
560
560
|
}
|
|
561
|
-
withStructuredOutput(outputSchema, config) {
|
|
562
|
-
const ensuredConfig = { ...config };
|
|
563
|
-
if (ensuredConfig?.method === void 0) ensuredConfig.method = "functionCalling";
|
|
564
|
-
return super.withStructuredOutput(outputSchema, ensuredConfig);
|
|
565
|
-
}
|
|
566
561
|
};
|
|
567
562
|
|
|
568
563
|
//#endregion
|