@langchain/deepseek 0.0.2 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,413 +1,402 @@
1
1
  import { getEnvironmentVariable } from "@langchain/core/utils/env";
2
- import { ChatOpenAI, } from "@langchain/openai";
2
+ import { ChatOpenAICompletions } from "@langchain/openai";
3
+
4
+ //#region src/chat_models.ts
3
5
  /**
4
- * Deepseek chat model integration.
5
- *
6
- * The Deepseek API is compatible to the OpenAI API with some limitations.
7
- *
8
- * Setup:
9
- * Install `@langchain/deepseek` and set an environment variable named `DEEPSEEK_API_KEY`.
10
- *
11
- * ```bash
12
- * npm install @langchain/deepseek
13
- * export DEEPSEEK_API_KEY="your-api-key"
14
- * ```
15
- *
16
- * ## [Constructor args](https://api.js.langchain.com/classes/_langchain_deepseek.ChatDeepSeek.html#constructor)
17
- *
18
- * ## [Runtime args](https://api.js.langchain.com/interfaces/_langchain_deepseek.ChatDeepSeekCallOptions.html)
19
- *
20
- * Runtime args can be passed as the second argument to any of the base runnable methods `.invoke`. `.stream`, `.batch`, etc.
21
- * They can also be passed via `.withConfig`, or the second arg in `.bindTools`, like shown in the examples below:
22
- *
23
- * ```typescript
24
- * // When calling `.withConfig`, call options should be passed via the first argument
25
- * const llmWithArgsBound = llm.withConfig({
26
- * stop: ["\n"],
27
- * tools: [...],
28
- * });
29
- *
30
- * // When calling `.bindTools`, call options should be passed via the second argument
31
- * const llmWithTools = llm.bindTools(
32
- * [...],
33
- * {
34
- * tool_choice: "auto",
35
- * }
36
- * );
37
- * ```
38
- *
39
- * ## Examples
40
- *
41
- * <details open>
42
- * <summary><strong>Instantiate</strong></summary>
43
- *
44
- * ```typescript
45
- * import { ChatDeepSeek } from '@langchain/deepseek';
46
- *
47
- * const llm = new ChatDeepSeek({
48
- * model: "deepseek-reasoner",
49
- * temperature: 0,
50
- * // other params...
51
- * });
52
- * ```
53
- * </details>
54
- *
55
- * <br />
56
- *
57
- * <details>
58
- * <summary><strong>Invoking</strong></summary>
59
- *
60
- * ```typescript
61
- * const input = `Translate "I love programming" into French.`;
62
- *
63
- * // Models also accept a list of chat messages or a formatted prompt
64
- * const result = await llm.invoke(input);
65
- * console.log(result);
66
- * ```
67
- *
68
- * ```txt
69
- * AIMessage {
70
- * "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.",
71
- * "additional_kwargs": {
72
- * "reasoning_content": "...",
73
- * },
74
- * "response_metadata": {
75
- * "tokenUsage": {
76
- * "completionTokens": 82,
77
- * "promptTokens": 20,
78
- * "totalTokens": 102
79
- * },
80
- * "finish_reason": "stop"
81
- * },
82
- * "tool_calls": [],
83
- * "invalid_tool_calls": []
84
- * }
85
- * ```
86
- * </details>
87
- *
88
- * <br />
89
- *
90
- * <details>
91
- * <summary><strong>Streaming Chunks</strong></summary>
92
- *
93
- * ```typescript
94
- * for await (const chunk of await llm.stream(input)) {
95
- * console.log(chunk);
96
- * }
97
- * ```
98
- *
99
- * ```txt
100
- * AIMessageChunk {
101
- * "content": "",
102
- * "additional_kwargs": {
103
- * "reasoning_content": "...",
104
- * },
105
- * "response_metadata": {
106
- * "finishReason": null
107
- * },
108
- * "tool_calls": [],
109
- * "tool_call_chunks": [],
110
- * "invalid_tool_calls": []
111
- * }
112
- * AIMessageChunk {
113
- * "content": "The",
114
- * "additional_kwargs": {
115
- * "reasoning_content": "...",
116
- * },
117
- * "response_metadata": {
118
- * "finishReason": null
119
- * },
120
- * "tool_calls": [],
121
- * "tool_call_chunks": [],
122
- * "invalid_tool_calls": []
123
- * }
124
- * AIMessageChunk {
125
- * "content": " French",
126
- * "additional_kwargs": {
127
- * "reasoning_content": "...",
128
- * },
129
- * "response_metadata": {
130
- * "finishReason": null
131
- * },
132
- * "tool_calls": [],
133
- * "tool_call_chunks": [],
134
- * "invalid_tool_calls": []
135
- * }
136
- * AIMessageChunk {
137
- * "content": " translation",
138
- * "additional_kwargs": {
139
- * "reasoning_content": "...",
140
- * },
141
- * "response_metadata": {
142
- * "finishReason": null
143
- * },
144
- * "tool_calls": [],
145
- * "tool_call_chunks": [],
146
- * "invalid_tool_calls": []
147
- * }
148
- * AIMessageChunk {
149
- * "content": " of",
150
- * "additional_kwargs": {
151
- * "reasoning_content": "...",
152
- * },
153
- * "response_metadata": {
154
- * "finishReason": null
155
- * },
156
- * "tool_calls": [],
157
- * "tool_call_chunks": [],
158
- * "invalid_tool_calls": []
159
- * }
160
- * AIMessageChunk {
161
- * "content": " \"",
162
- * "additional_kwargs": {
163
- * "reasoning_content": "...",
164
- * },
165
- * "response_metadata": {
166
- * "finishReason": null
167
- * },
168
- * "tool_calls": [],
169
- * "tool_call_chunks": [],
170
- * "invalid_tool_calls": []
171
- * }
172
- * AIMessageChunk {
173
- * "content": "I",
174
- * "additional_kwargs": {
175
- * "reasoning_content": "...",
176
- * },
177
- * "response_metadata": {
178
- * "finishReason": null
179
- * },
180
- * "tool_calls": [],
181
- * "tool_call_chunks": [],
182
- * "invalid_tool_calls": []
183
- * }
184
- * AIMessageChunk {
185
- * "content": " love",
186
- * "additional_kwargs": {
187
- * "reasoning_content": "...",
188
- * },
189
- * "response_metadata": {
190
- * "finishReason": null
191
- * },
192
- * "tool_calls": [],
193
- * "tool_call_chunks": [],
194
- * "invalid_tool_calls": []
195
- * }
196
- * ...
197
- * AIMessageChunk {
198
- * "content": ".",
199
- * "additional_kwargs": {
200
- * "reasoning_content": "...",
201
- * },
202
- * "response_metadata": {
203
- * "finishReason": null
204
- * },
205
- * "tool_calls": [],
206
- * "tool_call_chunks": [],
207
- * "invalid_tool_calls": []
208
- * }
209
- * AIMessageChunk {
210
- * "content": "",
211
- * "additional_kwargs": {
212
- * "reasoning_content": "...",
213
- * },
214
- * "response_metadata": {
215
- * "finishReason": "stop"
216
- * },
217
- * "tool_calls": [],
218
- * "tool_call_chunks": [],
219
- * "invalid_tool_calls": []
220
- * }
221
- * ```
222
- * </details>
223
- *
224
- * <br />
225
- *
226
- * <details>
227
- * <summary><strong>Aggregate Streamed Chunks</strong></summary>
228
- *
229
- * ```typescript
230
- * import { AIMessageChunk } from '@langchain/core/messages';
231
- * import { concat } from '@langchain/core/utils/stream';
232
- *
233
- * const stream = await llm.stream(input);
234
- * let full: AIMessageChunk | undefined;
235
- * for await (const chunk of stream) {
236
- * full = !full ? chunk : concat(full, chunk);
237
- * }
238
- * console.log(full);
239
- * ```
240
- *
241
- * ```txt
242
- * AIMessageChunk {
243
- * "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.",
244
- * "additional_kwargs": {
245
- * "reasoning_content": "...",
246
- * },
247
- * "response_metadata": {
248
- * "finishReason": "stop"
249
- * },
250
- * "tool_calls": [],
251
- * "tool_call_chunks": [],
252
- * "invalid_tool_calls": []
253
- * }
254
- * ```
255
- * </details>
256
- *
257
- * <br />
258
- *
259
- * <details>
260
- * <summary><strong>Bind tools</strong></summary>
261
- *
262
- * ```typescript
263
- * import { z } from 'zod';
264
- *
265
- * const llmForToolCalling = new ChatDeepSeek({
266
- * model: "deepseek-chat",
267
- * temperature: 0,
268
- * // other params...
269
- * });
270
- *
271
- * const GetWeather = {
272
- * name: "GetWeather",
273
- * description: "Get the current weather in a given location",
274
- * schema: z.object({
275
- * location: z.string().describe("The city and state, e.g. San Francisco, CA")
276
- * }),
277
- * }
278
- *
279
- * const GetPopulation = {
280
- * name: "GetPopulation",
281
- * description: "Get the current population in a given location",
282
- * schema: z.object({
283
- * location: z.string().describe("The city and state, e.g. San Francisco, CA")
284
- * }),
285
- * }
286
- *
287
- * const llmWithTools = llmForToolCalling.bindTools([GetWeather, GetPopulation]);
288
- * const aiMsg = await llmWithTools.invoke(
289
- * "Which city is hotter today and which is bigger: LA or NY?"
290
- * );
291
- * console.log(aiMsg.tool_calls);
292
- * ```
293
- *
294
- * ```txt
295
- * [
296
- * {
297
- * name: 'GetWeather',
298
- * args: { location: 'Los Angeles, CA' },
299
- * type: 'tool_call',
300
- * id: 'call_cd34'
301
- * },
302
- * {
303
- * name: 'GetWeather',
304
- * args: { location: 'New York, NY' },
305
- * type: 'tool_call',
306
- * id: 'call_68rf'
307
- * },
308
- * {
309
- * name: 'GetPopulation',
310
- * args: { location: 'Los Angeles, CA' },
311
- * type: 'tool_call',
312
- * id: 'call_f81z'
313
- * },
314
- * {
315
- * name: 'GetPopulation',
316
- * args: { location: 'New York, NY' },
317
- * type: 'tool_call',
318
- * id: 'call_8byt'
319
- * }
320
- * ]
321
- * ```
322
- * </details>
323
- *
324
- * <br />
325
- *
326
- * <details>
327
- * <summary><strong>Structured Output</strong></summary>
328
- *
329
- * ```typescript
330
- * import { z } from 'zod';
331
- *
332
- * const Joke = z.object({
333
- * setup: z.string().describe("The setup of the joke"),
334
- * punchline: z.string().describe("The punchline to the joke"),
335
- * rating: z.number().optional().describe("How funny the joke is, from 1 to 10")
336
- * }).describe('Joke to tell user.');
337
- *
338
- * const structuredLlm = llmForToolCalling.withStructuredOutput(Joke, { name: "Joke" });
339
- * const jokeResult = await structuredLlm.invoke("Tell me a joke about cats");
340
- * console.log(jokeResult);
341
- * ```
342
- *
343
- * ```txt
344
- * {
345
- * setup: "Why don't cats play poker in the wild?",
346
- * punchline: 'Because there are too many cheetahs.'
347
- * }
348
- * ```
349
- * </details>
350
- *
351
- * <br />
352
- */
353
- export class ChatDeepSeek extends ChatOpenAI {
354
- static lc_name() {
355
- return "ChatDeepSeek";
356
- }
357
- _llmType() {
358
- return "deepseek";
359
- }
360
- get lc_secrets() {
361
- return {
362
- apiKey: "DEEPSEEK_API_KEY",
363
- };
364
- }
365
- constructor(fields) {
366
- const apiKey = fields?.apiKey || getEnvironmentVariable("DEEPSEEK_API_KEY");
367
- if (!apiKey) {
368
- throw new Error(`Deepseek API key not found. Please set the DEEPSEEK_API_KEY environment variable or pass the key into "apiKey" field.`);
369
- }
370
- super({
371
- ...fields,
372
- apiKey,
373
- configuration: {
374
- baseURL: "https://api.deepseek.com",
375
- ...fields?.configuration,
376
- },
377
- });
378
- Object.defineProperty(this, "lc_serializable", {
379
- enumerable: true,
380
- configurable: true,
381
- writable: true,
382
- value: true
383
- });
384
- Object.defineProperty(this, "lc_namespace", {
385
- enumerable: true,
386
- configurable: true,
387
- writable: true,
388
- value: ["langchain", "chat_models", "deepseek"]
389
- });
390
- }
391
- _convertOpenAIDeltaToBaseMessageChunk(
392
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
393
- delta, rawResponse, defaultRole) {
394
- const messageChunk = super._convertOpenAIDeltaToBaseMessageChunk(delta, rawResponse, defaultRole);
395
- messageChunk.additional_kwargs.reasoning_content = delta.reasoning_content;
396
- return messageChunk;
397
- }
398
- _convertOpenAIChatCompletionMessageToBaseMessage(message, rawResponse) {
399
- const langChainMessage = super._convertOpenAIChatCompletionMessageToBaseMessage(message, rawResponse);
400
- langChainMessage.additional_kwargs.reasoning_content =
401
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
402
- message.reasoning_content;
403
- return langChainMessage;
404
- }
405
- withStructuredOutput(outputSchema, config) {
406
- const ensuredConfig = { ...config };
407
- // Deepseek does not support json schema yet
408
- if (ensuredConfig?.method === undefined) {
409
- ensuredConfig.method = "functionCalling";
410
- }
411
- return super.withStructuredOutput(outputSchema, ensuredConfig);
412
- }
413
- }
6
+ * Deepseek chat model integration.
7
+ *
8
+ * The Deepseek API is compatible to the OpenAI API with some limitations.
9
+ *
10
+ * Setup:
11
+ * Install `@langchain/deepseek` and set an environment variable named `DEEPSEEK_API_KEY`.
12
+ *
13
+ * ```bash
14
+ * npm install @langchain/deepseek
15
+ * export DEEPSEEK_API_KEY="your-api-key"
16
+ * ```
17
+ *
18
+ * ## [Constructor args](https://api.js.langchain.com/classes/_langchain_deepseek.ChatDeepSeek.html#constructor)
19
+ *
20
+ * ## [Runtime args](https://api.js.langchain.com/interfaces/_langchain_deepseek.ChatDeepSeekCallOptions.html)
21
+ *
22
+ * Runtime args can be passed as the second argument to any of the base runnable methods `.invoke`. `.stream`, `.batch`, etc.
23
+ * They can also be passed via `.withConfig`, or the second arg in `.bindTools`, like shown in the examples below:
24
+ *
25
+ * ```typescript
26
+ * // When calling `.withConfig`, call options should be passed via the first argument
27
+ * const llmWithArgsBound = llm.withConfig({
28
+ * stop: ["\n"],
29
+ * tools: [...],
30
+ * });
31
+ *
32
+ * // When calling `.bindTools`, call options should be passed via the second argument
33
+ * const llmWithTools = llm.bindTools(
34
+ * [...],
35
+ * {
36
+ * tool_choice: "auto",
37
+ * }
38
+ * );
39
+ * ```
40
+ *
41
+ * ## Examples
42
+ *
43
+ * <details open>
44
+ * <summary><strong>Instantiate</strong></summary>
45
+ *
46
+ * ```typescript
47
+ * import { ChatDeepSeek } from '@langchain/deepseek';
48
+ *
49
+ * const llm = new ChatDeepSeek({
50
+ * model: "deepseek-reasoner",
51
+ * temperature: 0,
52
+ * // other params...
53
+ * });
54
+ * ```
55
+ * </details>
56
+ *
57
+ * <br />
58
+ *
59
+ * <details>
60
+ * <summary><strong>Invoking</strong></summary>
61
+ *
62
+ * ```typescript
63
+ * const input = `Translate "I love programming" into French.`;
64
+ *
65
+ * // Models also accept a list of chat messages or a formatted prompt
66
+ * const result = await llm.invoke(input);
67
+ * console.log(result);
68
+ * ```
69
+ *
70
+ * ```txt
71
+ * AIMessage {
72
+ * "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.",
73
+ * "additional_kwargs": {
74
+ * "reasoning_content": "...",
75
+ * },
76
+ * "response_metadata": {
77
+ * "tokenUsage": {
78
+ * "completionTokens": 82,
79
+ * "promptTokens": 20,
80
+ * "totalTokens": 102
81
+ * },
82
+ * "finish_reason": "stop"
83
+ * },
84
+ * "tool_calls": [],
85
+ * "invalid_tool_calls": []
86
+ * }
87
+ * ```
88
+ * </details>
89
+ *
90
+ * <br />
91
+ *
92
+ * <details>
93
+ * <summary><strong>Streaming Chunks</strong></summary>
94
+ *
95
+ * ```typescript
96
+ * for await (const chunk of await llm.stream(input)) {
97
+ * console.log(chunk);
98
+ * }
99
+ * ```
100
+ *
101
+ * ```txt
102
+ * AIMessageChunk {
103
+ * "content": "",
104
+ * "additional_kwargs": {
105
+ * "reasoning_content": "...",
106
+ * },
107
+ * "response_metadata": {
108
+ * "finishReason": null
109
+ * },
110
+ * "tool_calls": [],
111
+ * "tool_call_chunks": [],
112
+ * "invalid_tool_calls": []
113
+ * }
114
+ * AIMessageChunk {
115
+ * "content": "The",
116
+ * "additional_kwargs": {
117
+ * "reasoning_content": "...",
118
+ * },
119
+ * "response_metadata": {
120
+ * "finishReason": null
121
+ * },
122
+ * "tool_calls": [],
123
+ * "tool_call_chunks": [],
124
+ * "invalid_tool_calls": []
125
+ * }
126
+ * AIMessageChunk {
127
+ * "content": " French",
128
+ * "additional_kwargs": {
129
+ * "reasoning_content": "...",
130
+ * },
131
+ * "response_metadata": {
132
+ * "finishReason": null
133
+ * },
134
+ * "tool_calls": [],
135
+ * "tool_call_chunks": [],
136
+ * "invalid_tool_calls": []
137
+ * }
138
+ * AIMessageChunk {
139
+ * "content": " translation",
140
+ * "additional_kwargs": {
141
+ * "reasoning_content": "...",
142
+ * },
143
+ * "response_metadata": {
144
+ * "finishReason": null
145
+ * },
146
+ * "tool_calls": [],
147
+ * "tool_call_chunks": [],
148
+ * "invalid_tool_calls": []
149
+ * }
150
+ * AIMessageChunk {
151
+ * "content": " of",
152
+ * "additional_kwargs": {
153
+ * "reasoning_content": "...",
154
+ * },
155
+ * "response_metadata": {
156
+ * "finishReason": null
157
+ * },
158
+ * "tool_calls": [],
159
+ * "tool_call_chunks": [],
160
+ * "invalid_tool_calls": []
161
+ * }
162
+ * AIMessageChunk {
163
+ * "content": " \"",
164
+ * "additional_kwargs": {
165
+ * "reasoning_content": "...",
166
+ * },
167
+ * "response_metadata": {
168
+ * "finishReason": null
169
+ * },
170
+ * "tool_calls": [],
171
+ * "tool_call_chunks": [],
172
+ * "invalid_tool_calls": []
173
+ * }
174
+ * AIMessageChunk {
175
+ * "content": "I",
176
+ * "additional_kwargs": {
177
+ * "reasoning_content": "...",
178
+ * },
179
+ * "response_metadata": {
180
+ * "finishReason": null
181
+ * },
182
+ * "tool_calls": [],
183
+ * "tool_call_chunks": [],
184
+ * "invalid_tool_calls": []
185
+ * }
186
+ * AIMessageChunk {
187
+ * "content": " love",
188
+ * "additional_kwargs": {
189
+ * "reasoning_content": "...",
190
+ * },
191
+ * "response_metadata": {
192
+ * "finishReason": null
193
+ * },
194
+ * "tool_calls": [],
195
+ * "tool_call_chunks": [],
196
+ * "invalid_tool_calls": []
197
+ * }
198
+ * ...
199
+ * AIMessageChunk {
200
+ * "content": ".",
201
+ * "additional_kwargs": {
202
+ * "reasoning_content": "...",
203
+ * },
204
+ * "response_metadata": {
205
+ * "finishReason": null
206
+ * },
207
+ * "tool_calls": [],
208
+ * "tool_call_chunks": [],
209
+ * "invalid_tool_calls": []
210
+ * }
211
+ * AIMessageChunk {
212
+ * "content": "",
213
+ * "additional_kwargs": {
214
+ * "reasoning_content": "...",
215
+ * },
216
+ * "response_metadata": {
217
+ * "finishReason": "stop"
218
+ * },
219
+ * "tool_calls": [],
220
+ * "tool_call_chunks": [],
221
+ * "invalid_tool_calls": []
222
+ * }
223
+ * ```
224
+ * </details>
225
+ *
226
+ * <br />
227
+ *
228
+ * <details>
229
+ * <summary><strong>Aggregate Streamed Chunks</strong></summary>
230
+ *
231
+ * ```typescript
232
+ * import { AIMessageChunk } from '@langchain/core/messages';
233
+ * import { concat } from '@langchain/core/utils/stream';
234
+ *
235
+ * const stream = await llm.stream(input);
236
+ * let full: AIMessageChunk | undefined;
237
+ * for await (const chunk of stream) {
238
+ * full = !full ? chunk : concat(full, chunk);
239
+ * }
240
+ * console.log(full);
241
+ * ```
242
+ *
243
+ * ```txt
244
+ * AIMessageChunk {
245
+ * "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.",
246
+ * "additional_kwargs": {
247
+ * "reasoning_content": "...",
248
+ * },
249
+ * "response_metadata": {
250
+ * "finishReason": "stop"
251
+ * },
252
+ * "tool_calls": [],
253
+ * "tool_call_chunks": [],
254
+ * "invalid_tool_calls": []
255
+ * }
256
+ * ```
257
+ * </details>
258
+ *
259
+ * <br />
260
+ *
261
+ * <details>
262
+ * <summary><strong>Bind tools</strong></summary>
263
+ *
264
+ * ```typescript
265
+ * import { z } from 'zod';
266
+ *
267
+ * const llmForToolCalling = new ChatDeepSeek({
268
+ * model: "deepseek-chat",
269
+ * temperature: 0,
270
+ * // other params...
271
+ * });
272
+ *
273
+ * const GetWeather = {
274
+ * name: "GetWeather",
275
+ * description: "Get the current weather in a given location",
276
+ * schema: z.object({
277
+ * location: z.string().describe("The city and state, e.g. San Francisco, CA")
278
+ * }),
279
+ * }
280
+ *
281
+ * const GetPopulation = {
282
+ * name: "GetPopulation",
283
+ * description: "Get the current population in a given location",
284
+ * schema: z.object({
285
+ * location: z.string().describe("The city and state, e.g. San Francisco, CA")
286
+ * }),
287
+ * }
288
+ *
289
+ * const llmWithTools = llmForToolCalling.bindTools([GetWeather, GetPopulation]);
290
+ * const aiMsg = await llmWithTools.invoke(
291
+ * "Which city is hotter today and which is bigger: LA or NY?"
292
+ * );
293
+ * console.log(aiMsg.tool_calls);
294
+ * ```
295
+ *
296
+ * ```txt
297
+ * [
298
+ * {
299
+ * name: 'GetWeather',
300
+ * args: { location: 'Los Angeles, CA' },
301
+ * type: 'tool_call',
302
+ * id: 'call_cd34'
303
+ * },
304
+ * {
305
+ * name: 'GetWeather',
306
+ * args: { location: 'New York, NY' },
307
+ * type: 'tool_call',
308
+ * id: 'call_68rf'
309
+ * },
310
+ * {
311
+ * name: 'GetPopulation',
312
+ * args: { location: 'Los Angeles, CA' },
313
+ * type: 'tool_call',
314
+ * id: 'call_f81z'
315
+ * },
316
+ * {
317
+ * name: 'GetPopulation',
318
+ * args: { location: 'New York, NY' },
319
+ * type: 'tool_call',
320
+ * id: 'call_8byt'
321
+ * }
322
+ * ]
323
+ * ```
324
+ * </details>
325
+ *
326
+ * <br />
327
+ *
328
+ * <details>
329
+ * <summary><strong>Structured Output</strong></summary>
330
+ *
331
+ * ```typescript
332
+ * import { z } from 'zod';
333
+ *
334
+ * const Joke = z.object({
335
+ * setup: z.string().describe("The setup of the joke"),
336
+ * punchline: z.string().describe("The punchline to the joke"),
337
+ * rating: z.number().optional().describe("How funny the joke is, from 1 to 10")
338
+ * }).describe('Joke to tell user.');
339
+ *
340
+ * const structuredLlm = llmForToolCalling.withStructuredOutput(Joke, { name: "Joke" });
341
+ * const jokeResult = await structuredLlm.invoke("Tell me a joke about cats");
342
+ * console.log(jokeResult);
343
+ * ```
344
+ *
345
+ * ```txt
346
+ * {
347
+ * setup: "Why don't cats play poker in the wild?",
348
+ * punchline: 'Because there are too many cheetahs.'
349
+ * }
350
+ * ```
351
+ * </details>
352
+ *
353
+ * <br />
354
+ */
355
+ var ChatDeepSeek = class extends ChatOpenAICompletions {
356
+ static lc_name() {
357
+ return "ChatDeepSeek";
358
+ }
359
+ _llmType() {
360
+ return "deepseek";
361
+ }
362
+ get lc_secrets() {
363
+ return { apiKey: "DEEPSEEK_API_KEY" };
364
+ }
365
+ lc_serializable = true;
366
+ lc_namespace = [
367
+ "langchain",
368
+ "chat_models",
369
+ "deepseek"
370
+ ];
371
+ constructor(fields) {
372
+ const apiKey = fields?.apiKey || getEnvironmentVariable("DEEPSEEK_API_KEY");
373
+ if (!apiKey) throw new Error(`Deepseek API key not found. Please set the DEEPSEEK_API_KEY environment variable or pass the key into "apiKey" field.`);
374
+ super({
375
+ ...fields,
376
+ apiKey,
377
+ configuration: {
378
+ baseURL: "https://api.deepseek.com",
379
+ ...fields?.configuration
380
+ }
381
+ });
382
+ }
383
+ _convertCompletionsDeltaToBaseMessageChunk(delta, rawResponse, defaultRole) {
384
+ const messageChunk = super._convertCompletionsDeltaToBaseMessageChunk(delta, rawResponse, defaultRole);
385
+ messageChunk.additional_kwargs.reasoning_content = delta.reasoning_content;
386
+ return messageChunk;
387
+ }
388
+ _convertCompletionsMessageToBaseMessage(message, rawResponse) {
389
+ const langChainMessage = super._convertCompletionsMessageToBaseMessage(message, rawResponse);
390
+ langChainMessage.additional_kwargs.reasoning_content = message.reasoning_content;
391
+ return langChainMessage;
392
+ }
393
+ withStructuredOutput(outputSchema, config) {
394
+ const ensuredConfig = { ...config };
395
+ if (ensuredConfig?.method === void 0) ensuredConfig.method = "functionCalling";
396
+ return super.withStructuredOutput(outputSchema, ensuredConfig);
397
+ }
398
+ };
399
+
400
+ //#endregion
401
+ export { ChatDeepSeek };
402
+ //# sourceMappingURL=chat_models.js.map