@langchain/xai 1.0.3-dev-1765433794876 → 1.1.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.
@@ -1,19 +1,109 @@
1
- import * as _langchain_core_messages0 from "@langchain/core/messages";
2
- import { AIMessageChunk, BaseMessage } from "@langchain/core/messages";
1
+ import { XAISearchParameters, XAISearchParametersPayload } from "./live_search.cjs";
2
+ import { XAILiveSearchTool } from "./tools/live_search.cjs";
3
3
  import { BaseLanguageModelInput, StructuredOutputMethodOptions } 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, BaseMessage, UsageMetadata } from "@langchain/core/messages";
7
8
  import { Runnable } from "@langchain/core/runnables";
8
9
  import { InteropZodType } from "@langchain/core/utils/types";
9
- import { ChatOpenAICompletions, OpenAIClient, OpenAICoreRequestOptions, OpenAIToolChoice } from "@langchain/openai";
10
+ import { ChatOpenAICompletions, OpenAIClient, OpenAICoreRequestOptions } from "@langchain/openai";
10
11
 
11
12
  //#region src/chat_models.d.ts
12
- type ChatXAIToolType = BindToolsInput | OpenAIClient.ChatCompletionTool;
13
+ type OpenAIToolChoice = OpenAIClient.ChatCompletionToolChoiceOption | "any" | string;
14
+ /**
15
+ * Union type for all xAI built-in server-side tools.
16
+ */
17
+ type XAIBuiltInTool = XAILiveSearchTool;
18
+ /**
19
+ * Tool type that includes both standard tools and xAI built-in tools.
20
+ */
21
+ type ChatXAIToolType = BindToolsInput | OpenAIClient.ChatCompletionTool | XAIBuiltInTool;
22
+ /**
23
+ * xAI-specific invocation parameters that extend the OpenAI completion params
24
+ * with xAI's search_parameters field.
25
+ */
26
+ type ChatXAICompletionsInvocationParams = Omit<OpenAIClient.Chat.Completions.ChatCompletionCreateParams, "messages"> & {
27
+ /**
28
+ * Search parameters for xAI's Live Search API.
29
+ * When present, enables the model to search the web for real-time information.
30
+ */
31
+ search_parameters?: XAISearchParametersPayload;
32
+ };
33
+ /**
34
+ * xAI-specific additional kwargs that may be present on AI messages.
35
+ * Includes xAI-specific fields like reasoning_content.
36
+ */
37
+ interface XAIAdditionalKwargs {
38
+ /**
39
+ * The reasoning content from xAI models that support chain-of-thought reasoning.
40
+ * This contains the model's internal reasoning process.
41
+ */
42
+ reasoning_content?: string;
43
+ /**
44
+ * Tool calls made by the model.
45
+ */
46
+ tool_calls?: OpenAIClient.ChatCompletionMessageToolCall[];
47
+ /**
48
+ * Additional properties that may be present.
49
+ */
50
+ [key: string]: unknown;
51
+ }
52
+ /**
53
+ * xAI-specific response metadata that may include usage information.
54
+ */
55
+ interface XAIResponseMetadata {
56
+ /**
57
+ * Token usage information.
58
+ */
59
+ usage?: UsageMetadata;
60
+ /**
61
+ * Additional metadata properties.
62
+ */
63
+ [key: string]: unknown;
64
+ }
65
+ /**
66
+ * Checks if a tool is an xAI built-in tool (like live_search).
67
+ * Built-in tools are executed server-side by the xAI API.
68
+ *
69
+ * @param tool - The tool to check
70
+ * @returns true if the tool is an xAI built-in tool
71
+ */
72
+ declare function isXAIBuiltInTool(tool: ChatXAIToolType): tool is XAIBuiltInTool;
13
73
  interface ChatXAICallOptions extends BaseChatModelCallOptions {
14
74
  headers?: Record<string, string>;
75
+ /**
76
+ * A list of tools the model may call.
77
+ * Can include standard function tools and xAI built-in tools like `{ type: "live_search" }`.
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * // Using built-in live_search tool
82
+ * const llm = new ChatXAI().bindTools([{ type: "live_search" }]);
83
+ * const result = await llm.invoke("What happened in tech news today?");
84
+ * ```
85
+ */
15
86
  tools?: ChatXAIToolType[];
16
87
  tool_choice?: OpenAIToolChoice | string | "auto" | "any";
88
+ /**
89
+ * Search parameters for xAI's Live Search API.
90
+ * Enables the model to search the web for real-time information.
91
+ *
92
+ * @note This is an alternative to using `tools: [{ type: "live_search" }]`.
93
+ * The Live Search API parameters approach may be deprecated in favor of
94
+ * the tool-based approach.
95
+ *
96
+ * @example
97
+ * ```typescript
98
+ * const result = await llm.invoke("What's the latest news?", {
99
+ * searchParameters: {
100
+ * mode: "auto",
101
+ * max_search_results: 5,
102
+ * }
103
+ * });
104
+ * ```
105
+ */
106
+ searchParameters?: XAISearchParameters;
17
107
  }
18
108
  interface ChatXAIInput extends BaseChatModelParams {
19
109
  /**
@@ -51,6 +141,23 @@ interface ChatXAIInput extends BaseChatModelParams {
51
141
  * This limits ensures computational efficiency and resource management.
52
142
  */
53
143
  maxTokens?: number;
144
+ /**
145
+ * Default search parameters for xAI's Live Search API.
146
+ * When set, these parameters will be applied to all requests unless
147
+ * overridden in the call options.
148
+ *
149
+ * @example
150
+ * ```typescript
151
+ * const llm = new ChatXAI({
152
+ * model: "grok-beta",
153
+ * searchParameters: {
154
+ * mode: "auto",
155
+ * max_search_results: 5,
156
+ * }
157
+ * });
158
+ * ```
159
+ */
160
+ searchParameters?: XAISearchParameters;
54
161
  }
55
162
  /**
56
163
  * xAI chat model integration.
@@ -377,6 +484,57 @@ interface ChatXAIInput extends BaseChatModelParams {
377
484
  * </details>
378
485
  *
379
486
  * <br />
487
+ *
488
+ * <details>
489
+ * <summary><strong>Server Tool Calling (Live Search)</strong></summary>
490
+ *
491
+ * xAI supports server-side tools that are executed by the API rather than
492
+ * requiring client-side execution. The `live_search` tool enables the model
493
+ * to search the web for real-time information.
494
+ *
495
+ * ```typescript
496
+ * // Method 1: Using the built-in live_search tool
497
+ * const llm = new ChatXAI({
498
+ * model: "grok-beta",
499
+ * temperature: 0,
500
+ * });
501
+ *
502
+ * const llmWithSearch = llm.bindTools([{ type: "live_search" }]);
503
+ * const result = await llmWithSearch.invoke("What happened in tech news today?");
504
+ * console.log(result.content);
505
+ * // The model will search the web and include real-time information in its response
506
+ * ```
507
+ *
508
+ * ```typescript
509
+ * // Method 2: Using searchParameters for more control
510
+ * const llm = new ChatXAI({
511
+ * model: "grok-beta",
512
+ * searchParameters: {
513
+ * mode: "auto", // "auto" | "on" | "off"
514
+ * max_search_results: 5,
515
+ * from_date: "2024-01-01", // ISO date string
516
+ * return_citations: true,
517
+ * }
518
+ * });
519
+ *
520
+ * const result = await llm.invoke("What are the latest AI developments?");
521
+ * ```
522
+ *
523
+ * ```typescript
524
+ * // Method 3: Override search parameters per request
525
+ * const result = await llm.invoke("Find recent news about SpaceX", {
526
+ * searchParameters: {
527
+ * mode: "on",
528
+ * max_search_results: 10,
529
+ * sources: [
530
+ * { type: "web", allowed_websites: ["spacex.com", "nasa.gov"] },
531
+ * ],
532
+ * }
533
+ * });
534
+ * ```
535
+ * </details>
536
+ *
537
+ * <br />
380
538
  */
381
539
  declare class ChatXAI extends ChatOpenAICompletions<ChatXAICallOptions> {
382
540
  static lc_name(): string;
@@ -386,13 +544,43 @@ declare class ChatXAI extends ChatOpenAICompletions<ChatXAICallOptions> {
386
544
  } | undefined;
387
545
  lc_serializable: boolean;
388
546
  lc_namespace: string[];
547
+ /**
548
+ * Default search parameters for the Live Search API.
549
+ */
550
+ searchParameters?: XAISearchParameters;
389
551
  constructor(fields?: Partial<ChatXAIInput>);
390
552
  toJSON(): Serialized;
391
553
  getLsParams(options: this["ParsedCallOptions"]): LangSmithParams;
554
+ /**
555
+ * Get the effective search parameters, merging defaults with call options.
556
+ * @param options Call options that may contain search parameters
557
+ * @returns Merged search parameters or undefined if none are configured
558
+ */
559
+ protected _getEffectiveSearchParameters(options?: this["ParsedCallOptions"]): XAISearchParameters | undefined;
560
+ /**
561
+ * Check if any built-in tools (like live_search) are in the tools list.
562
+ * @param tools List of tools to check
563
+ * @returns true if any built-in tools are present
564
+ */
565
+ protected _hasBuiltInTools(tools?: ChatXAIToolType[]): boolean;
566
+ /**
567
+ * Formats tools to xAI/OpenAI format, preserving provider-specific definitions.
568
+ *
569
+ * @param tools The tools to format
570
+ * @returns The formatted tools
571
+ */
572
+ formatStructuredToolToXAI(tools: ChatXAIToolType[]): (OpenAIClient.ChatCompletionTool | XAIBuiltInTool)[] | undefined;
573
+ bindTools(tools: ChatXAIToolType[], kwargs?: Partial<ChatXAICallOptions>): Runnable<BaseLanguageModelInput, AIMessageChunk, ChatXAICallOptions>;
574
+ /** @internal */
575
+ invocationParams(options?: this["ParsedCallOptions"], extra?: {
576
+ streaming?: boolean;
577
+ }): ChatXAICompletionsInvocationParams;
392
578
  completionWithRetry(request: OpenAIClient.Chat.ChatCompletionCreateParamsStreaming, options?: OpenAICoreRequestOptions): Promise<AsyncIterable<OpenAIClient.Chat.Completions.ChatCompletionChunk>>;
393
579
  completionWithRetry(request: OpenAIClient.Chat.ChatCompletionCreateParamsNonStreaming, options?: OpenAICoreRequestOptions): Promise<OpenAIClient.Chat.Completions.ChatCompletion>;
394
- protected _convertCompletionsDeltaToBaseMessageChunk(delta: Record<string, any>, rawResponse: OpenAIClient.ChatCompletionChunk, defaultRole?: "function" | "user" | "system" | "developer" | "assistant" | "tool"): AIMessageChunk<_langchain_core_messages0.MessageStructure>;
395
- protected _convertCompletionsMessageToBaseMessage(message: OpenAIClient.ChatCompletionMessage, rawResponse: OpenAIClient.ChatCompletion): BaseMessage<_langchain_core_messages0.MessageStructure, _langchain_core_messages0.MessageType>;
580
+ protected _convertCompletionsDeltaToBaseMessageChunk(delta: Record<string, any>, rawResponse: OpenAIClient.ChatCompletionChunk, defaultRole?: "function" | "user" | "system" | "developer" | "assistant" | "tool"): AIMessageChunk;
581
+ protected _convertCompletionsMessageToBaseMessage(message: OpenAIClient.ChatCompletionMessage & {
582
+ reasoning_content?: string;
583
+ }, rawResponse: OpenAIClient.ChatCompletion): AIMessageChunk;
396
584
  /**
397
585
  * Return profiling information for the model.
398
586
  *
@@ -422,5 +610,5 @@ declare class ChatXAI extends ChatOpenAICompletions<ChatXAICallOptions> {
422
610
  }>;
423
611
  }
424
612
  //#endregion
425
- export { ChatXAI, ChatXAICallOptions, ChatXAIInput };
613
+ export { ChatXAI, ChatXAICallOptions, ChatXAICompletionsInvocationParams, ChatXAIInput, OpenAIToolChoice, XAIAdditionalKwargs, XAIBuiltInTool, XAIResponseMetadata, isXAIBuiltInTool };
426
614
  //# sourceMappingURL=chat_models.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"chat_models.d.cts","names":["BaseLanguageModelInput","StructuredOutputMethodOptions","BaseChatModelCallOptions","BindToolsInput","LangSmithParams","BaseChatModelParams","ModelProfile","Serialized","AIMessageChunk","BaseMessage","Runnable","InteropZodType","OpenAICoreRequestOptions","OpenAIClient","OpenAIToolChoice","ChatOpenAICompletions","ChatXAIToolType","ChatCompletionTool","ChatXAICallOptions","Record","ChatXAIInput","Array","ChatXAI","RunOutput","Partial","Chat","ChatCompletionCreateParamsStreaming","Completions","ChatCompletionChunk","AsyncIterable","Promise","ChatCompletionCreateParamsNonStreaming","ChatCompletion","_langchain_core_messages0","MessageStructure","ChatCompletionMessage","MessageType"],"sources":["../src/chat_models.d.ts"],"sourcesContent":["import { BaseLanguageModelInput, StructuredOutputMethodOptions } from \"@langchain/core/language_models/base\";\nimport { BaseChatModelCallOptions, BindToolsInput, LangSmithParams, type BaseChatModelParams } from \"@langchain/core/language_models/chat_models\";\nimport { ModelProfile } from \"@langchain/core/language_models/profile\";\nimport { Serialized } from \"@langchain/core/load/serializable\";\nimport { AIMessageChunk, BaseMessage } from \"@langchain/core/messages\";\nimport { Runnable } from \"@langchain/core/runnables\";\nimport { InteropZodType } from \"@langchain/core/utils/types\";\nimport { type OpenAICoreRequestOptions, type OpenAIClient, OpenAIToolChoice, ChatOpenAICompletions } from \"@langchain/openai\";\ntype ChatXAIToolType = BindToolsInput | OpenAIClient.ChatCompletionTool;\nexport interface ChatXAICallOptions extends BaseChatModelCallOptions {\n headers?: Record<string, string>;\n tools?: ChatXAIToolType[];\n tool_choice?: OpenAIToolChoice | string | \"auto\" | \"any\";\n}\nexport interface ChatXAIInput extends BaseChatModelParams {\n /**\n * The xAI API key to use for requests.\n * @default process.env.XAI_API_KEY\n */\n apiKey?: string;\n /**\n * The name of the model to use.\n * @default \"grok-beta\"\n */\n model?: string;\n /**\n * Up to 4 sequences where the API will stop generating further tokens. The\n * returned text will not contain the stop sequence.\n * Alias for `stopSequences`\n */\n stop?: Array<string>;\n /**\n * Up to 4 sequences where the API will stop generating further tokens. The\n * returned text will not contain the stop sequence.\n */\n stopSequences?: Array<string>;\n /**\n * Whether or not to stream responses.\n */\n streaming?: boolean;\n /**\n * The temperature to use for sampling.\n * @default 0.7\n */\n temperature?: number;\n /**\n * The maximum number of tokens that the model can process in a single response.\n * This limits ensures computational efficiency and resource management.\n */\n maxTokens?: number;\n}\n/**\n * xAI chat model integration.\n *\n * The xAI API is compatible to the OpenAI API with some limitations.\n *\n * Setup:\n * Install `@langchain/xai` and set an environment variable named `XAI_API_KEY`.\n *\n * ```bash\n * npm install @langchain/xai\n * export XAI_API_KEY=\"your-api-key\"\n * ```\n *\n * ## [Constructor args](https://api.js.langchain.com/classes/_langchain_xai.ChatXAI.html#constructor)\n *\n * ## [Runtime args](https://api.js.langchain.com/interfaces/_langchain_xai.ChatXAICallOptions.html)\n *\n * Runtime args can be passed as the second argument to any of the base runnable methods `.invoke`. `.stream`, `.batch`, etc.\n * They can also be passed via `.withConfig`, or the second arg in `.bindTools`, like shown in the examples below:\n *\n * ```typescript\n * // When calling `.withConfig`, call options should be passed via the first argument\n * const llmWithArgsBound = llm.withConfig({\n * stop: [\"\\n\"],\n * tools: [...],\n * });\n *\n * // When calling `.bindTools`, call options should be passed via the second argument\n * const llmWithTools = llm.bindTools(\n * [...],\n * {\n * tool_choice: \"auto\",\n * }\n * );\n * ```\n *\n * ## Examples\n *\n * <details open>\n * <summary><strong>Instantiate</strong></summary>\n *\n * ```typescript\n * import { ChatXAI } from '@langchain/xai';\n *\n * const llm = new ChatXAI({\n * model: \"grok-beta\",\n * temperature: 0,\n * // other params...\n * });\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Invoking</strong></summary>\n *\n * ```typescript\n * const input = `Translate \"I love programming\" into French.`;\n *\n * // Models also accept a list of chat messages or a formatted prompt\n * const result = await llm.invoke(input);\n * console.log(result);\n * ```\n *\n * ```txt\n * AIMessage {\n * \"content\": \"The French translation of \\\"I love programming\\\" is \\\"J'aime programmer\\\". In this sentence, \\\"J'aime\\\" is the first person singular conjugation of the French verb \\\"aimer\\\" which means \\\"to love\\\", and \\\"programmer\\\" is the French infinitive for \\\"to program\\\". I hope this helps! Let me know if you have any other questions.\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {\n * \"tokenUsage\": {\n * \"completionTokens\": 82,\n * \"promptTokens\": 20,\n * \"totalTokens\": 102\n * },\n * \"finish_reason\": \"stop\"\n * },\n * \"tool_calls\": [],\n * \"invalid_tool_calls\": []\n * }\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Streaming Chunks</strong></summary>\n *\n * ```typescript\n * for await (const chunk of await llm.stream(input)) {\n * console.log(chunk);\n * }\n * ```\n *\n * ```txt\n * AIMessageChunk {\n * \"content\": \"\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {\n * \"finishReason\": null\n * },\n * \"tool_calls\": [],\n * \"tool_call_chunks\": [],\n * \"invalid_tool_calls\": []\n * }\n * AIMessageChunk {\n * \"content\": \"The\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {\n * \"finishReason\": null\n * },\n * \"tool_calls\": [],\n * \"tool_call_chunks\": [],\n * \"invalid_tool_calls\": []\n * }\n * AIMessageChunk {\n * \"content\": \" French\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {\n * \"finishReason\": null\n * },\n * \"tool_calls\": [],\n * \"tool_call_chunks\": [],\n * \"invalid_tool_calls\": []\n * }\n * AIMessageChunk {\n * \"content\": \" translation\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {\n * \"finishReason\": null\n * },\n * \"tool_calls\": [],\n * \"tool_call_chunks\": [],\n * \"invalid_tool_calls\": []\n * }\n * AIMessageChunk {\n * \"content\": \" of\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {\n * \"finishReason\": null\n * },\n * \"tool_calls\": [],\n * \"tool_call_chunks\": [],\n * \"invalid_tool_calls\": []\n * }\n * AIMessageChunk {\n * \"content\": \" \\\"\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {\n * \"finishReason\": null\n * },\n * \"tool_calls\": [],\n * \"tool_call_chunks\": [],\n * \"invalid_tool_calls\": []\n * }\n * AIMessageChunk {\n * \"content\": \"I\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {\n * \"finishReason\": null\n * },\n * \"tool_calls\": [],\n * \"tool_call_chunks\": [],\n * \"invalid_tool_calls\": []\n * }\n * AIMessageChunk {\n * \"content\": \" love\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {\n * \"finishReason\": null\n * },\n * \"tool_calls\": [],\n * \"tool_call_chunks\": [],\n * \"invalid_tool_calls\": []\n * }\n * ...\n * AIMessageChunk {\n * \"content\": \".\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {\n * \"finishReason\": null\n * },\n * \"tool_calls\": [],\n * \"tool_call_chunks\": [],\n * \"invalid_tool_calls\": []\n * }\n * AIMessageChunk {\n * \"content\": \"\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {\n * \"finishReason\": \"stop\"\n * },\n * \"tool_calls\": [],\n * \"tool_call_chunks\": [],\n * \"invalid_tool_calls\": []\n * }\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Aggregate Streamed Chunks</strong></summary>\n *\n * ```typescript\n * import { AIMessageChunk } from '@langchain/core/messages';\n * import { concat } from '@langchain/core/utils/stream';\n *\n * const stream = await llm.stream(input);\n * let full: AIMessageChunk | undefined;\n * for await (const chunk of stream) {\n * full = !full ? chunk : concat(full, chunk);\n * }\n * console.log(full);\n * ```\n *\n * ```txt\n * AIMessageChunk {\n * \"content\": \"The French translation of \\\"I love programming\\\" is \\\"J'aime programmer\\\". In this sentence, \\\"J'aime\\\" is the first person singular conjugation of the French verb \\\"aimer\\\" which means \\\"to love\\\", and \\\"programmer\\\" is the French infinitive for \\\"to program\\\". I hope this helps! Let me know if you have any other questions.\",\n * \"additional_kwargs\": {},\n * \"response_metadata\": {\n * \"finishReason\": \"stop\"\n * },\n * \"tool_calls\": [],\n * \"tool_call_chunks\": [],\n * \"invalid_tool_calls\": []\n * }\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Bind tools</strong></summary>\n *\n * ```typescript\n * import { z } from 'zod';\n *\n * const llmForToolCalling = new ChatXAI({\n * model: \"grok-beta\",\n * temperature: 0,\n * // other params...\n * });\n *\n * const GetWeather = {\n * name: \"GetWeather\",\n * description: \"Get the current weather in a given location\",\n * schema: z.object({\n * location: z.string().describe(\"The city and state, e.g. San Francisco, CA\")\n * }),\n * }\n *\n * const GetPopulation = {\n * name: \"GetPopulation\",\n * description: \"Get the current population in a given location\",\n * schema: z.object({\n * location: z.string().describe(\"The city and state, e.g. San Francisco, CA\")\n * }),\n * }\n *\n * const llmWithTools = llmForToolCalling.bindTools([GetWeather, GetPopulation]);\n * const aiMsg = await llmWithTools.invoke(\n * \"Which city is hotter today and which is bigger: LA or NY?\"\n * );\n * console.log(aiMsg.tool_calls);\n * ```\n *\n * ```txt\n * [\n * {\n * name: 'GetWeather',\n * args: { location: 'Los Angeles, CA' },\n * type: 'tool_call',\n * id: 'call_cd34'\n * },\n * {\n * name: 'GetWeather',\n * args: { location: 'New York, NY' },\n * type: 'tool_call',\n * id: 'call_68rf'\n * },\n * {\n * name: 'GetPopulation',\n * args: { location: 'Los Angeles, CA' },\n * type: 'tool_call',\n * id: 'call_f81z'\n * },\n * {\n * name: 'GetPopulation',\n * args: { location: 'New York, NY' },\n * type: 'tool_call',\n * id: 'call_8byt'\n * }\n * ]\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Structured Output</strong></summary>\n *\n * ```typescript\n * import { z } from 'zod';\n *\n * const Joke = z.object({\n * setup: z.string().describe(\"The setup of the joke\"),\n * punchline: z.string().describe(\"The punchline to the joke\"),\n * rating: z.number().optional().describe(\"How funny the joke is, from 1 to 10\")\n * }).describe('Joke to tell user.');\n *\n * const structuredLlm = llmForToolCalling.withStructuredOutput(Joke, { name: \"Joke\" });\n * const jokeResult = await structuredLlm.invoke(\"Tell me a joke about cats\");\n * console.log(jokeResult);\n * ```\n *\n * ```txt\n * {\n * setup: \"Why don't cats play poker in the wild?\",\n * punchline: 'Because there are too many cheetahs.'\n * }\n * ```\n * </details>\n *\n * <br />\n */\nexport declare class ChatXAI extends ChatOpenAICompletions<ChatXAICallOptions> {\n static lc_name(): string;\n _llmType(): string;\n get lc_secrets(): {\n [key: string]: string;\n } | undefined;\n lc_serializable: boolean;\n lc_namespace: string[];\n constructor(fields?: Partial<ChatXAIInput>);\n toJSON(): Serialized;\n getLsParams(options: this[\"ParsedCallOptions\"]): LangSmithParams;\n completionWithRetry(request: OpenAIClient.Chat.ChatCompletionCreateParamsStreaming, options?: OpenAICoreRequestOptions): Promise<AsyncIterable<OpenAIClient.Chat.Completions.ChatCompletionChunk>>;\n completionWithRetry(request: OpenAIClient.Chat.ChatCompletionCreateParamsNonStreaming, options?: OpenAICoreRequestOptions): Promise<OpenAIClient.Chat.Completions.ChatCompletion>;\n protected _convertCompletionsDeltaToBaseMessageChunk(delta: Record<string, any>, rawResponse: OpenAIClient.ChatCompletionChunk, defaultRole?: \"function\" | \"user\" | \"system\" | \"developer\" | \"assistant\" | \"tool\"): AIMessageChunk<import(\"@langchain/core/messages\").MessageStructure>;\n protected _convertCompletionsMessageToBaseMessage(message: OpenAIClient.ChatCompletionMessage, rawResponse: OpenAIClient.ChatCompletion): BaseMessage<import(\"@langchain/core/messages\").MessageStructure, import(\"@langchain/core/messages\").MessageType>;\n /**\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=chat_models.d.ts.map"],"mappings":";;;;;;;;;;;KAQKgB,eAAAA,GAAkBb,iBAAiBU,YAAAA,CAAaI;UACpCC,kBAAAA,SAA2BhB;YAC9BiB;EAFTH,KAAAA,CAAAA,EAGOA,eAHQ,EAAA;EACHE,WAAAA,CAAAA,EAGCJ,gBAHiB,GAAA,MAAA,GAAA,MAAA,GAAA,KAAA;;AAEvBE,UAGKI,YAAAA,SAAqBf,mBAH1BW,CAAAA;EACMF;;AAHkD;AAKpE;EAgBWO,MAAAA,CAAAA,EAAAA,MAAAA;EAKSA;;AArBqC;AA2WzD;EAA2DH,KAAAA,CAAAA,EAAAA,MAAAA;EAQ1BE;;;;;EAGiER,IAAAA,CAAAA,EAtWvFS,KAsWuFT,CAAAA,MAAAA,CAAAA;EAAiDC;;;;EAC9CD,aAAAA,CAAAA,EAlWjFS,KAkWiFT,CAAAA,MAAAA,CAAAA;EAAmCC;;;EACtCA,SAAA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BJ,sBAAsBA,mCAAmCR,eAAeY,aAAaJ,8BAA8BlB,yCAAyCS,SAASV,wBAAwBuB,aAAab,SAASV;SACjPS;YACGc"}
1
+ {"version":3,"file":"chat_models.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.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>): Run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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"}
@@ -1,19 +1,109 @@
1
- import { ChatOpenAICompletions, OpenAIClient, OpenAICoreRequestOptions, OpenAIToolChoice } from "@langchain/openai";
2
- import * as _langchain_core_messages0 from "@langchain/core/messages";
3
- import { AIMessageChunk, BaseMessage } from "@langchain/core/messages";
1
+ import { XAISearchParameters, XAISearchParametersPayload } from "./live_search.js";
2
+ import { XAILiveSearchTool } from "./tools/live_search.js";
3
+ import { ChatOpenAICompletions, OpenAIClient, OpenAICoreRequestOptions } from "@langchain/openai";
4
4
  import { BaseLanguageModelInput, StructuredOutputMethodOptions } from "@langchain/core/language_models/base";
5
5
  import { BaseChatModelCallOptions, BaseChatModelParams, BindToolsInput, LangSmithParams } from "@langchain/core/language_models/chat_models";
6
6
  import { ModelProfile } from "@langchain/core/language_models/profile";
7
7
  import { Serialized } from "@langchain/core/load/serializable";
8
+ import { AIMessageChunk, BaseMessage, UsageMetadata } from "@langchain/core/messages";
8
9
  import { Runnable } from "@langchain/core/runnables";
9
10
  import { InteropZodType } from "@langchain/core/utils/types";
10
11
 
11
12
  //#region src/chat_models.d.ts
12
- type ChatXAIToolType = BindToolsInput | OpenAIClient.ChatCompletionTool;
13
+ type OpenAIToolChoice = OpenAIClient.ChatCompletionToolChoiceOption | "any" | string;
14
+ /**
15
+ * Union type for all xAI built-in server-side tools.
16
+ */
17
+ type XAIBuiltInTool = XAILiveSearchTool;
18
+ /**
19
+ * Tool type that includes both standard tools and xAI built-in tools.
20
+ */
21
+ type ChatXAIToolType = BindToolsInput | OpenAIClient.ChatCompletionTool | XAIBuiltInTool;
22
+ /**
23
+ * xAI-specific invocation parameters that extend the OpenAI completion params
24
+ * with xAI's search_parameters field.
25
+ */
26
+ type ChatXAICompletionsInvocationParams = Omit<OpenAIClient.Chat.Completions.ChatCompletionCreateParams, "messages"> & {
27
+ /**
28
+ * Search parameters for xAI's Live Search API.
29
+ * When present, enables the model to search the web for real-time information.
30
+ */
31
+ search_parameters?: XAISearchParametersPayload;
32
+ };
33
+ /**
34
+ * xAI-specific additional kwargs that may be present on AI messages.
35
+ * Includes xAI-specific fields like reasoning_content.
36
+ */
37
+ interface XAIAdditionalKwargs {
38
+ /**
39
+ * The reasoning content from xAI models that support chain-of-thought reasoning.
40
+ * This contains the model's internal reasoning process.
41
+ */
42
+ reasoning_content?: string;
43
+ /**
44
+ * Tool calls made by the model.
45
+ */
46
+ tool_calls?: OpenAIClient.ChatCompletionMessageToolCall[];
47
+ /**
48
+ * Additional properties that may be present.
49
+ */
50
+ [key: string]: unknown;
51
+ }
52
+ /**
53
+ * xAI-specific response metadata that may include usage information.
54
+ */
55
+ interface XAIResponseMetadata {
56
+ /**
57
+ * Token usage information.
58
+ */
59
+ usage?: UsageMetadata;
60
+ /**
61
+ * Additional metadata properties.
62
+ */
63
+ [key: string]: unknown;
64
+ }
65
+ /**
66
+ * Checks if a tool is an xAI built-in tool (like live_search).
67
+ * Built-in tools are executed server-side by the xAI API.
68
+ *
69
+ * @param tool - The tool to check
70
+ * @returns true if the tool is an xAI built-in tool
71
+ */
72
+ declare function isXAIBuiltInTool(tool: ChatXAIToolType): tool is XAIBuiltInTool;
13
73
  interface ChatXAICallOptions extends BaseChatModelCallOptions {
14
74
  headers?: Record<string, string>;
75
+ /**
76
+ * A list of tools the model may call.
77
+ * Can include standard function tools and xAI built-in tools like `{ type: "live_search" }`.
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * // Using built-in live_search tool
82
+ * const llm = new ChatXAI().bindTools([{ type: "live_search" }]);
83
+ * const result = await llm.invoke("What happened in tech news today?");
84
+ * ```
85
+ */
15
86
  tools?: ChatXAIToolType[];
16
87
  tool_choice?: OpenAIToolChoice | string | "auto" | "any";
88
+ /**
89
+ * Search parameters for xAI's Live Search API.
90
+ * Enables the model to search the web for real-time information.
91
+ *
92
+ * @note This is an alternative to using `tools: [{ type: "live_search" }]`.
93
+ * The Live Search API parameters approach may be deprecated in favor of
94
+ * the tool-based approach.
95
+ *
96
+ * @example
97
+ * ```typescript
98
+ * const result = await llm.invoke("What's the latest news?", {
99
+ * searchParameters: {
100
+ * mode: "auto",
101
+ * max_search_results: 5,
102
+ * }
103
+ * });
104
+ * ```
105
+ */
106
+ searchParameters?: XAISearchParameters;
17
107
  }
18
108
  interface ChatXAIInput extends BaseChatModelParams {
19
109
  /**
@@ -51,6 +141,23 @@ interface ChatXAIInput extends BaseChatModelParams {
51
141
  * This limits ensures computational efficiency and resource management.
52
142
  */
53
143
  maxTokens?: number;
144
+ /**
145
+ * Default search parameters for xAI's Live Search API.
146
+ * When set, these parameters will be applied to all requests unless
147
+ * overridden in the call options.
148
+ *
149
+ * @example
150
+ * ```typescript
151
+ * const llm = new ChatXAI({
152
+ * model: "grok-beta",
153
+ * searchParameters: {
154
+ * mode: "auto",
155
+ * max_search_results: 5,
156
+ * }
157
+ * });
158
+ * ```
159
+ */
160
+ searchParameters?: XAISearchParameters;
54
161
  }
55
162
  /**
56
163
  * xAI chat model integration.
@@ -377,6 +484,57 @@ interface ChatXAIInput extends BaseChatModelParams {
377
484
  * </details>
378
485
  *
379
486
  * <br />
487
+ *
488
+ * <details>
489
+ * <summary><strong>Server Tool Calling (Live Search)</strong></summary>
490
+ *
491
+ * xAI supports server-side tools that are executed by the API rather than
492
+ * requiring client-side execution. The `live_search` tool enables the model
493
+ * to search the web for real-time information.
494
+ *
495
+ * ```typescript
496
+ * // Method 1: Using the built-in live_search tool
497
+ * const llm = new ChatXAI({
498
+ * model: "grok-beta",
499
+ * temperature: 0,
500
+ * });
501
+ *
502
+ * const llmWithSearch = llm.bindTools([{ type: "live_search" }]);
503
+ * const result = await llmWithSearch.invoke("What happened in tech news today?");
504
+ * console.log(result.content);
505
+ * // The model will search the web and include real-time information in its response
506
+ * ```
507
+ *
508
+ * ```typescript
509
+ * // Method 2: Using searchParameters for more control
510
+ * const llm = new ChatXAI({
511
+ * model: "grok-beta",
512
+ * searchParameters: {
513
+ * mode: "auto", // "auto" | "on" | "off"
514
+ * max_search_results: 5,
515
+ * from_date: "2024-01-01", // ISO date string
516
+ * return_citations: true,
517
+ * }
518
+ * });
519
+ *
520
+ * const result = await llm.invoke("What are the latest AI developments?");
521
+ * ```
522
+ *
523
+ * ```typescript
524
+ * // Method 3: Override search parameters per request
525
+ * const result = await llm.invoke("Find recent news about SpaceX", {
526
+ * searchParameters: {
527
+ * mode: "on",
528
+ * max_search_results: 10,
529
+ * sources: [
530
+ * { type: "web", allowed_websites: ["spacex.com", "nasa.gov"] },
531
+ * ],
532
+ * }
533
+ * });
534
+ * ```
535
+ * </details>
536
+ *
537
+ * <br />
380
538
  */
381
539
  declare class ChatXAI extends ChatOpenAICompletions<ChatXAICallOptions> {
382
540
  static lc_name(): string;
@@ -386,13 +544,43 @@ declare class ChatXAI extends ChatOpenAICompletions<ChatXAICallOptions> {
386
544
  } | undefined;
387
545
  lc_serializable: boolean;
388
546
  lc_namespace: string[];
547
+ /**
548
+ * Default search parameters for the Live Search API.
549
+ */
550
+ searchParameters?: XAISearchParameters;
389
551
  constructor(fields?: Partial<ChatXAIInput>);
390
552
  toJSON(): Serialized;
391
553
  getLsParams(options: this["ParsedCallOptions"]): LangSmithParams;
554
+ /**
555
+ * Get the effective search parameters, merging defaults with call options.
556
+ * @param options Call options that may contain search parameters
557
+ * @returns Merged search parameters or undefined if none are configured
558
+ */
559
+ protected _getEffectiveSearchParameters(options?: this["ParsedCallOptions"]): XAISearchParameters | undefined;
560
+ /**
561
+ * Check if any built-in tools (like live_search) are in the tools list.
562
+ * @param tools List of tools to check
563
+ * @returns true if any built-in tools are present
564
+ */
565
+ protected _hasBuiltInTools(tools?: ChatXAIToolType[]): boolean;
566
+ /**
567
+ * Formats tools to xAI/OpenAI format, preserving provider-specific definitions.
568
+ *
569
+ * @param tools The tools to format
570
+ * @returns The formatted tools
571
+ */
572
+ formatStructuredToolToXAI(tools: ChatXAIToolType[]): (OpenAIClient.ChatCompletionTool | XAIBuiltInTool)[] | undefined;
573
+ bindTools(tools: ChatXAIToolType[], kwargs?: Partial<ChatXAICallOptions>): Runnable<BaseLanguageModelInput, AIMessageChunk, ChatXAICallOptions>;
574
+ /** @internal */
575
+ invocationParams(options?: this["ParsedCallOptions"], extra?: {
576
+ streaming?: boolean;
577
+ }): ChatXAICompletionsInvocationParams;
392
578
  completionWithRetry(request: OpenAIClient.Chat.ChatCompletionCreateParamsStreaming, options?: OpenAICoreRequestOptions): Promise<AsyncIterable<OpenAIClient.Chat.Completions.ChatCompletionChunk>>;
393
579
  completionWithRetry(request: OpenAIClient.Chat.ChatCompletionCreateParamsNonStreaming, options?: OpenAICoreRequestOptions): Promise<OpenAIClient.Chat.Completions.ChatCompletion>;
394
- protected _convertCompletionsDeltaToBaseMessageChunk(delta: Record<string, any>, rawResponse: OpenAIClient.ChatCompletionChunk, defaultRole?: "function" | "user" | "system" | "developer" | "assistant" | "tool"): AIMessageChunk<_langchain_core_messages0.MessageStructure>;
395
- protected _convertCompletionsMessageToBaseMessage(message: OpenAIClient.ChatCompletionMessage, rawResponse: OpenAIClient.ChatCompletion): BaseMessage<_langchain_core_messages0.MessageStructure, _langchain_core_messages0.MessageType>;
580
+ protected _convertCompletionsDeltaToBaseMessageChunk(delta: Record<string, any>, rawResponse: OpenAIClient.ChatCompletionChunk, defaultRole?: "function" | "user" | "system" | "developer" | "assistant" | "tool"): AIMessageChunk;
581
+ protected _convertCompletionsMessageToBaseMessage(message: OpenAIClient.ChatCompletionMessage & {
582
+ reasoning_content?: string;
583
+ }, rawResponse: OpenAIClient.ChatCompletion): AIMessageChunk;
396
584
  /**
397
585
  * Return profiling information for the model.
398
586
  *
@@ -422,5 +610,5 @@ declare class ChatXAI extends ChatOpenAICompletions<ChatXAICallOptions> {
422
610
  }>;
423
611
  }
424
612
  //#endregion
425
- export { ChatXAI, ChatXAICallOptions, ChatXAIInput };
613
+ export { ChatXAI, ChatXAICallOptions, ChatXAICompletionsInvocationParams, ChatXAIInput, OpenAIToolChoice, XAIAdditionalKwargs, XAIBuiltInTool, XAIResponseMetadata, isXAIBuiltInTool };
426
614
  //# sourceMappingURL=chat_models.d.ts.map