@langchain/deepseek 1.0.15 → 1.0.17-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/dist/chat_models.cjs +1 -1
- package/dist/chat_models.cjs.map +1 -1
- package/dist/chat_models.d.cts +4 -3
- package/dist/chat_models.d.cts.map +1 -1
- package/dist/chat_models.d.ts +4 -3
- package/dist/chat_models.d.ts.map +1 -1
- package/dist/chat_models.js +1 -1
- package/dist/chat_models.js.map +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @langchain/deepseek
|
|
2
2
|
|
|
3
|
+
## 1.0.16
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#10206](https://github.com/langchain-ai/langchainjs/pull/10206) [`c4bfe24`](https://github.com/langchain-ai/langchainjs/commit/c4bfe2428f2616b6fc94d8b78c5a770d38f22733) Thanks [@colifran](https://github.com/colifran)! - feat(deepseek): 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.0.15
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/dist/chat_models.cjs
CHANGED
|
@@ -386,7 +386,7 @@ var ChatDeepSeek = class extends _langchain_openai.ChatOpenAICompletions {
|
|
|
386
386
|
...fields.configuration
|
|
387
387
|
}
|
|
388
388
|
});
|
|
389
|
-
this._addVersion("@langchain/deepseek", "1.0.
|
|
389
|
+
this._addVersion("@langchain/deepseek", "1.0.17-dev-1773345797648");
|
|
390
390
|
}
|
|
391
391
|
_convertCompletionsDeltaToBaseMessageChunk(delta, rawResponse, defaultRole) {
|
|
392
392
|
const messageChunk = super._convertCompletionsDeltaToBaseMessageChunk(delta, rawResponse, defaultRole);
|
package/dist/chat_models.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat_models.cjs","names":["ChatOpenAICompletions","ChatGenerationChunk","AIMessageChunk","PROFILES"],"sources":["../src/chat_models.ts"],"sourcesContent":["import {\n BaseLanguageModelInput,\n StructuredOutputMethodOptions,\n} from \"@langchain/core/language_models/base\";\nimport { ModelProfile } from \"@langchain/core/language_models/profile\";\nimport { BaseMessage, AIMessageChunk } 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 ChatOpenAICallOptions,\n ChatOpenAICompletions,\n ChatOpenAIFields,\n OpenAIClient,\n} from \"@langchain/openai\";\nimport { ChatGenerationChunk } from \"@langchain/core/outputs\";\nimport { CallbackManagerForLLMRun } from \"@langchain/core/callbacks/manager\";\nimport PROFILES from \"./profiles.js\";\n\nexport interface ChatDeepSeekCallOptions extends ChatOpenAICallOptions {\n headers?: Record<string, string>;\n}\n\nexport interface ChatDeepSeekInput extends ChatOpenAIFields {\n /**\n * The Deepseek API key to use for requests.\n * @default process.env.DEEPSEEK_API_KEY\n */\n apiKey?: string;\n /**\n * The name of the model to use.\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 */\n temperature?: number;\n /**\n * The maximum number of tokens that the model can process in a single response.\n * This limits ensures computational efficiency and resource management.\n */\n maxTokens?: number;\n}\n\n/**\n * Deepseek chat model integration.\n *\n * The Deepseek API is compatible to the OpenAI API with some limitations.\n *\n * Setup:\n * Install `@langchain/deepseek` and set an environment variable named `DEEPSEEK_API_KEY`.\n *\n * ```bash\n * npm install @langchain/deepseek\n * export DEEPSEEK_API_KEY=\"your-api-key\"\n * ```\n *\n * ## [Constructor args](https://api.js.langchain.com/classes/_langchain_deepseek.ChatDeepSeek.html#constructor)\n *\n * ## [Runtime args](https://api.js.langchain.com/interfaces/_langchain_deepseek.ChatDeepSeekCallOptions.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 { ChatDeepSeek } from '@langchain/deepseek';\n *\n * const llm = new ChatDeepSeek({\n * model: \"deepseek-reasoner\",\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 ChatDeepSeek({\n * model: \"deepseek-chat\",\n * temperature: 0,\n * // other params...\n * });\n *\n * const GetWeather = {\n * name: \"GetWeather\",\n * description: \"Get the current weather in a given location\",\n * schema: z.object({\n * location: z.string().describe(\"The city and state, e.g. San Francisco, CA\")\n * }),\n * }\n *\n * const GetPopulation = {\n * name: \"GetPopulation\",\n * description: \"Get the current population in a given location\",\n * schema: z.object({\n * location: z.string().describe(\"The city and state, e.g. San Francisco, CA\")\n * }),\n * }\n *\n * const llmWithTools = llmForToolCalling.bindTools([GetWeather, GetPopulation]);\n * const aiMsg = await llmWithTools.invoke(\n * \"Which city is hotter today and which is bigger: LA or NY?\"\n * );\n * console.log(aiMsg.tool_calls);\n * ```\n *\n * ```txt\n * [\n * {\n * name: 'GetWeather',\n * args: { location: 'Los Angeles, CA' },\n * type: 'tool_call',\n * id: 'call_cd34'\n * },\n * {\n * name: 'GetWeather',\n * args: { location: 'New York, NY' },\n * type: 'tool_call',\n * id: 'call_68rf'\n * },\n * {\n * name: 'GetPopulation',\n * args: { location: 'Los Angeles, CA' },\n * type: 'tool_call',\n * id: 'call_f81z'\n * },\n * {\n * name: 'GetPopulation',\n * args: { location: 'New York, NY' },\n * type: 'tool_call',\n * id: 'call_8byt'\n * }\n * ]\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Structured Output</strong></summary>\n *\n * ```typescript\n * import { z } from 'zod';\n *\n * const Joke = z.object({\n * setup: z.string().describe(\"The setup of the joke\"),\n * punchline: z.string().describe(\"The punchline to the joke\"),\n * rating: z.number().optional().describe(\"How funny the joke is, from 1 to 10\")\n * }).describe('Joke to tell user.');\n *\n * const structuredLlm = llmForToolCalling.withStructuredOutput(Joke, { name: \"Joke\" });\n * const jokeResult = await structuredLlm.invoke(\"Tell me a joke about cats\");\n * console.log(jokeResult);\n * ```\n *\n * ```txt\n * {\n * setup: \"Why don't cats play poker in the wild?\",\n * punchline: 'Because there are too many cheetahs.'\n * }\n * ```\n * </details>\n *\n * <br />\n */\nexport class ChatDeepSeek extends ChatOpenAICompletions<ChatDeepSeekCallOptions> {\n static lc_name() {\n return \"ChatDeepSeek\";\n }\n\n _llmType() {\n return \"deepseek\";\n }\n\n get lc_secrets(): { [key: string]: string } | undefined {\n return {\n apiKey: \"DEEPSEEK_API_KEY\",\n };\n }\n\n lc_serializable = true;\n\n lc_namespace = [\"langchain\", \"chat_models\", \"deepseek\"];\n\n constructor(model: string, fields?: Omit<ChatDeepSeekInput, \"model\">);\n constructor(fields?: Partial<ChatDeepSeekInput>);\n constructor(\n modelOrFields?: string | Partial<ChatDeepSeekInput>,\n fieldsArg?: Omit<ChatDeepSeekInput, \"model\">\n ) {\n const fields =\n typeof modelOrFields === \"string\"\n ? { ...(fieldsArg ?? {}), model: modelOrFields }\n : (modelOrFields ?? {});\n const apiKey = fields.apiKey || getEnvironmentVariable(\"DEEPSEEK_API_KEY\");\n if (!apiKey) {\n throw new Error(\n `Deepseek API key not found. Please set the DEEPSEEK_API_KEY environment variable or pass the key into \"apiKey\" field.`\n );\n }\n\n super({\n ...fields,\n apiKey,\n configuration: {\n baseURL: \"https://api.deepseek.com\",\n ...fields.configuration,\n },\n });\n this._addVersion(\"@langchain/deepseek\", __PKG_VERSION__);\n }\n\n protected override _convertCompletionsDeltaToBaseMessageChunk(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n delta: Record<string, any>,\n rawResponse: OpenAIClient.ChatCompletionChunk,\n defaultRole?:\n | \"function\"\n | \"user\"\n | \"system\"\n | \"developer\"\n | \"assistant\"\n | \"tool\"\n ) {\n const messageChunk = super._convertCompletionsDeltaToBaseMessageChunk(\n delta,\n rawResponse,\n defaultRole\n );\n messageChunk.additional_kwargs.reasoning_content = delta.reasoning_content;\n // Override model_provider for DeepSeek-specific block translation\n messageChunk.response_metadata = {\n ...messageChunk.response_metadata,\n model_provider: \"deepseek\",\n };\n return messageChunk;\n }\n\n async *_streamResponseChunks(\n messages: BaseMessage[],\n options: this[\"ParsedCallOptions\"],\n runManager?: CallbackManagerForLLMRun\n ): AsyncGenerator<ChatGenerationChunk> {\n const stream = super._streamResponseChunks(messages, options, runManager);\n\n // State for parsing <think> tags\n let tokensBuffer = \"\";\n let isThinking = false;\n\n for await (const chunk of stream) {\n if (options.signal?.aborted) {\n return;\n }\n // If the model already provided reasoning_content natively, just yield it\n if (chunk.message.additional_kwargs.reasoning_content) {\n yield chunk;\n continue;\n }\n\n const text = chunk.text;\n if (!text) {\n yield chunk;\n continue;\n }\n\n // Append text to buffer to handle split tags\n tokensBuffer += text;\n\n // Check for <think> start tag\n if (!isThinking && tokensBuffer.includes(\"<think>\")) {\n isThinking = true;\n const thinkIndex = tokensBuffer.indexOf(\"<think>\");\n const beforeThink = tokensBuffer.substring(0, thinkIndex);\n const afterThink = tokensBuffer.substring(\n thinkIndex + \"<think>\".length\n );\n\n // We consumed up to <think>, so buffer becomes what's after\n tokensBuffer = afterThink || \"\"; // might be empty or part of thought\n\n if (beforeThink) {\n // Send the content before the tag\n const newChunk = new ChatGenerationChunk({\n message: new AIMessageChunk({\n content: beforeThink,\n additional_kwargs: chunk.message.additional_kwargs,\n response_metadata: chunk.message.response_metadata,\n tool_calls: chunk.message.tool_calls,\n tool_call_chunks: chunk.message.tool_call_chunks,\n id: chunk.message.id,\n }),\n text: beforeThink,\n generationInfo: chunk.generationInfo,\n });\n yield newChunk;\n }\n }\n\n // Check for </think> end tag\n if (isThinking && tokensBuffer.includes(\"</think>\")) {\n isThinking = false;\n const thinkEndIndex = tokensBuffer.indexOf(\"</think>\");\n const thoughtContent = tokensBuffer.substring(0, thinkEndIndex);\n const afterThink = tokensBuffer.substring(\n thinkEndIndex + \"</think>\".length\n );\n\n // Yield the reasoning content\n const reasoningChunk = new ChatGenerationChunk({\n message: new AIMessageChunk({\n content: \"\",\n additional_kwargs: {\n ...chunk.message.additional_kwargs,\n reasoning_content: thoughtContent,\n },\n response_metadata: chunk.message.response_metadata,\n tool_calls: chunk.message.tool_calls,\n tool_call_chunks: chunk.message.tool_call_chunks,\n id: chunk.message.id,\n }),\n text: \"\",\n generationInfo: chunk.generationInfo,\n });\n yield reasoningChunk;\n\n // Reset buffer to what's after </think>\n tokensBuffer = afterThink || \"\";\n\n // Yield the rest as normal content if any\n if (tokensBuffer) {\n const contentChunk = new ChatGenerationChunk({\n message: new AIMessageChunk({\n content: tokensBuffer,\n additional_kwargs: chunk.message.additional_kwargs,\n response_metadata: chunk.message.response_metadata,\n tool_calls: chunk.message.tool_calls,\n tool_call_chunks: chunk.message.tool_call_chunks,\n id: chunk.message.id,\n }),\n text: tokensBuffer,\n generationInfo: chunk.generationInfo,\n });\n yield contentChunk;\n tokensBuffer = \"\"; // consumed\n }\n } else if (isThinking) {\n // We are inside thinking block.\n // Check partial </think> match\n const possibleEndTag = \"</think>\";\n let splitIndex = -1;\n\n // Check if buffer ends with a prefix of </think> - Greedy check (longest first)\n for (let i = possibleEndTag.length - 1; i >= 1; i--) {\n if (tokensBuffer.endsWith(possibleEndTag.substring(0, i))) {\n splitIndex = tokensBuffer.length - i;\n break;\n }\n }\n\n if (splitIndex !== -1) {\n const safeToYield = tokensBuffer.substring(0, splitIndex);\n if (safeToYield) {\n const reasoningChunk = new ChatGenerationChunk({\n message: new AIMessageChunk({\n content: \"\",\n additional_kwargs: {\n ...chunk.message.additional_kwargs,\n reasoning_content: safeToYield,\n },\n response_metadata: chunk.message.response_metadata,\n tool_calls: chunk.message.tool_calls,\n tool_call_chunks: chunk.message.tool_call_chunks,\n id: chunk.message.id,\n }),\n text: \"\",\n generationInfo: chunk.generationInfo,\n });\n yield reasoningChunk;\n }\n tokensBuffer = tokensBuffer.substring(splitIndex); // keep partial tag\n } else {\n // content is safe to yield as reasoning\n if (tokensBuffer) {\n const reasoningChunk = new ChatGenerationChunk({\n message: new AIMessageChunk({\n content: \"\",\n additional_kwargs: {\n ...chunk.message.additional_kwargs,\n reasoning_content: tokensBuffer,\n },\n response_metadata: chunk.message.response_metadata,\n tool_calls: chunk.message.tool_calls,\n tool_call_chunks: chunk.message.tool_call_chunks,\n id: chunk.message.id,\n }),\n text: \"\",\n generationInfo: chunk.generationInfo,\n });\n yield reasoningChunk;\n tokensBuffer = \"\";\n }\n }\n } else {\n // NOT thinking.\n // Check partial start tag \"<think>\" - Greedy check (longest first)\n const possibleStartTag = \"<think>\";\n let splitIndex = -1;\n for (let i = possibleStartTag.length - 1; i >= 1; i--) {\n if (tokensBuffer.endsWith(possibleStartTag.substring(0, i))) {\n splitIndex = tokensBuffer.length - i;\n break;\n }\n }\n\n if (splitIndex !== -1) {\n // Yield safe content\n const safeToYield = tokensBuffer.substring(0, splitIndex);\n if (safeToYield) {\n const contentChunk = new ChatGenerationChunk({\n message: new AIMessageChunk({\n content: safeToYield,\n additional_kwargs: chunk.message.additional_kwargs,\n response_metadata: chunk.message.response_metadata,\n tool_calls: chunk.message.tool_calls,\n tool_call_chunks: chunk.message.tool_call_chunks,\n id: chunk.message.id,\n }),\n text: safeToYield,\n generationInfo: chunk.generationInfo,\n });\n yield contentChunk;\n }\n tokensBuffer = tokensBuffer.substring(splitIndex); // keep partial tag\n } else {\n // Yield all\n if (tokensBuffer) {\n const contentChunk = new ChatGenerationChunk({\n message: new AIMessageChunk({\n content: tokensBuffer,\n additional_kwargs: chunk.message.additional_kwargs,\n response_metadata: chunk.message.response_metadata,\n tool_calls: chunk.message.tool_calls,\n tool_call_chunks: chunk.message.tool_call_chunks,\n id: chunk.message.id,\n }),\n text: tokensBuffer,\n generationInfo: chunk.generationInfo,\n });\n yield contentChunk;\n tokensBuffer = \"\";\n }\n }\n }\n }\n\n // Flush remaining buffer at end of stream\n if (tokensBuffer) {\n // If we were thinking, it's unclosed thought.\n if (isThinking) {\n const reasoningChunk = new ChatGenerationChunk({\n message: new AIMessageChunk({\n content: \"\",\n additional_kwargs: { reasoning_content: tokensBuffer },\n }),\n text: \"\",\n });\n yield reasoningChunk;\n } else {\n const contentChunk = new ChatGenerationChunk({\n message: new AIMessageChunk({\n content: tokensBuffer,\n }),\n text: tokensBuffer,\n });\n yield contentChunk;\n }\n }\n }\n\n protected override _convertCompletionsMessageToBaseMessage(\n message: OpenAIClient.ChatCompletionMessage,\n rawResponse: OpenAIClient.ChatCompletion\n ) {\n const langChainMessage = super._convertCompletionsMessageToBaseMessage(\n message,\n rawResponse\n );\n langChainMessage.additional_kwargs.reasoning_content =\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (message as any).reasoning_content;\n // Override model_provider for DeepSeek-specific block translation\n langChainMessage.response_metadata = {\n ...langChainMessage.response_metadata,\n model_provider: \"deepseek\",\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 ChatDeepSeek({ model: \"deepseek-chat\" });\n * const profile = model.profile;\n * console.log(profile.maxInputTokens); // 128000\n * console.log(profile.imageInputs); // false\n * ```\n */\n get profile(): ModelProfile {\n return PROFILES[this.model] ?? {};\n }\n\n 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 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 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 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 // Deepseek does not support json schema yet\n if (ensuredConfig?.method === undefined) {\n ensuredConfig.method = \"functionCalling\";\n }\n return super.withStructuredOutput<RunOutput>(outputSchema, ensuredConfig);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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F,MAAM;MACN,gBAAgB,MAAM;MACvB,CAAC;AAGJ,oBAAe,aAAa,UAAU,WAAW;eAG7C,cAAc;AAahB,WAZqB,IAAID,4CAAoB;MAC3C,SAAS,IAAIC,wCAAe;OAC1B,SAAS;OACT,mBAAmB,MAAM,QAAQ;OACjC,mBAAmB,MAAM,QAAQ;OACjC,YAAY,MAAM,QAAQ;OAC1B,kBAAkB,MAAM,QAAQ;OAChC,IAAI,MAAM,QAAQ;OACnB,CAAC;MACF,MAAM;MACN,gBAAgB,MAAM;MACvB,CAAC;AAEF,oBAAe;;;;AAOvB,MAAI,aAEF,KAAI,WAQF,OAPuB,IAAID,4CAAoB;GAC7C,SAAS,IAAIC,wCAAe;IAC1B,SAAS;IACT,mBAAmB,EAAE,mBAAmB,cAAc;IACvD,CAAC;GACF,MAAM;GACP,CAAC;MASF,OANqB,IAAID,4CAAoB;GAC3C,SAAS,IAAIC,wCAAe,EAC1B,SAAS,cACV,CAAC;GACF,MAAM;GACP,CAAC;;CAMR,AAAmB,wCACjB,SACA,aACA;EACA,MAAM,mBAAmB,MAAM,wCAC7B,SACA,YACD;AACD,mBAAiB,kBAAkB,oBAEhC,QAAgB;AAEnB,mBAAiB,oBAAoB;GACnC,GAAG,iBAAiB;GACpB,gBAAgB;GACjB;AACD,SAAO;;;;;;;;;;;;;;;;;;;CAoBT,IAAI,UAAwB;AAC1B,SAAOC,yBAAS,KAAK,UAAU,EAAE;;CAsCnC,qBAIE,cAIA,QAMI;EACJ,MAAM,gBAAgB,EAAE,GAAG,QAAQ;AAEnC,MAAI,eAAe,WAAW,OAC5B,eAAc,SAAS;AAEzB,SAAO,MAAM,qBAAgC,cAAc,cAAc"}
|
|
1
|
+
{"version":3,"file":"chat_models.cjs","names":["ChatOpenAICompletions","ChatGenerationChunk","AIMessageChunk","PROFILES"],"sources":["../src/chat_models.ts"],"sourcesContent":["import {\n BaseLanguageModelInput,\n StructuredOutputMethodOptions,\n} from \"@langchain/core/language_models/base\";\nimport { ModelProfile } from \"@langchain/core/language_models/profile\";\nimport { BaseMessage, AIMessageChunk } 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 ChatOpenAICallOptions,\n ChatOpenAICompletions,\n ChatOpenAIFields,\n OpenAIClient,\n} from \"@langchain/openai\";\nimport { ChatGenerationChunk } from \"@langchain/core/outputs\";\nimport { CallbackManagerForLLMRun } from \"@langchain/core/callbacks/manager\";\nimport PROFILES from \"./profiles.js\";\nimport { SerializableSchema } from \"@langchain/core/utils/standard_schema\";\n\nexport interface ChatDeepSeekCallOptions extends ChatOpenAICallOptions {\n headers?: Record<string, string>;\n}\n\nexport interface ChatDeepSeekInput extends ChatOpenAIFields {\n /**\n * The Deepseek API key to use for requests.\n * @default process.env.DEEPSEEK_API_KEY\n */\n apiKey?: string;\n /**\n * The name of the model to use.\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 */\n temperature?: number;\n /**\n * The maximum number of tokens that the model can process in a single response.\n * This limits ensures computational efficiency and resource management.\n */\n maxTokens?: number;\n}\n\n/**\n * Deepseek chat model integration.\n *\n * The Deepseek API is compatible to the OpenAI API with some limitations.\n *\n * Setup:\n * Install `@langchain/deepseek` and set an environment variable named `DEEPSEEK_API_KEY`.\n *\n * ```bash\n * npm install @langchain/deepseek\n * export DEEPSEEK_API_KEY=\"your-api-key\"\n * ```\n *\n * ## [Constructor args](https://api.js.langchain.com/classes/_langchain_deepseek.ChatDeepSeek.html#constructor)\n *\n * ## [Runtime args](https://api.js.langchain.com/interfaces/_langchain_deepseek.ChatDeepSeekCallOptions.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 { ChatDeepSeek } from '@langchain/deepseek';\n *\n * const llm = new ChatDeepSeek({\n * model: \"deepseek-reasoner\",\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 ChatDeepSeek({\n * model: \"deepseek-chat\",\n * temperature: 0,\n * // other params...\n * });\n *\n * const GetWeather = {\n * name: \"GetWeather\",\n * description: \"Get the current weather in a given location\",\n * schema: z.object({\n * location: z.string().describe(\"The city and state, e.g. San Francisco, CA\")\n * }),\n * }\n *\n * const GetPopulation = {\n * name: \"GetPopulation\",\n * description: \"Get the current population in a given location\",\n * schema: z.object({\n * location: z.string().describe(\"The city and state, e.g. San Francisco, CA\")\n * }),\n * }\n *\n * const llmWithTools = llmForToolCalling.bindTools([GetWeather, GetPopulation]);\n * const aiMsg = await llmWithTools.invoke(\n * \"Which city is hotter today and which is bigger: LA or NY?\"\n * );\n * console.log(aiMsg.tool_calls);\n * ```\n *\n * ```txt\n * [\n * {\n * name: 'GetWeather',\n * args: { location: 'Los Angeles, CA' },\n * type: 'tool_call',\n * id: 'call_cd34'\n * },\n * {\n * name: 'GetWeather',\n * args: { location: 'New York, NY' },\n * type: 'tool_call',\n * id: 'call_68rf'\n * },\n * {\n * name: 'GetPopulation',\n * args: { location: 'Los Angeles, CA' },\n * type: 'tool_call',\n * id: 'call_f81z'\n * },\n * {\n * name: 'GetPopulation',\n * args: { location: 'New York, NY' },\n * type: 'tool_call',\n * id: 'call_8byt'\n * }\n * ]\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Structured Output</strong></summary>\n *\n * ```typescript\n * import { z } from 'zod';\n *\n * const Joke = z.object({\n * setup: z.string().describe(\"The setup of the joke\"),\n * punchline: z.string().describe(\"The punchline to the joke\"),\n * rating: z.number().optional().describe(\"How funny the joke is, from 1 to 10\")\n * }).describe('Joke to tell user.');\n *\n * const structuredLlm = llmForToolCalling.withStructuredOutput(Joke, { name: \"Joke\" });\n * const jokeResult = await structuredLlm.invoke(\"Tell me a joke about cats\");\n * console.log(jokeResult);\n * ```\n *\n * ```txt\n * {\n * setup: \"Why don't cats play poker in the wild?\",\n * punchline: 'Because there are too many cheetahs.'\n * }\n * ```\n * </details>\n *\n * <br />\n */\nexport class ChatDeepSeek extends ChatOpenAICompletions<ChatDeepSeekCallOptions> {\n static lc_name() {\n return \"ChatDeepSeek\";\n }\n\n _llmType() {\n return \"deepseek\";\n }\n\n get lc_secrets(): { [key: string]: string } | undefined {\n return {\n apiKey: \"DEEPSEEK_API_KEY\",\n };\n }\n\n lc_serializable = true;\n\n lc_namespace = [\"langchain\", \"chat_models\", \"deepseek\"];\n\n constructor(model: string, fields?: Omit<ChatDeepSeekInput, \"model\">);\n constructor(fields?: Partial<ChatDeepSeekInput>);\n constructor(\n modelOrFields?: string | Partial<ChatDeepSeekInput>,\n fieldsArg?: Omit<ChatDeepSeekInput, \"model\">\n ) {\n const fields =\n typeof modelOrFields === \"string\"\n ? { ...(fieldsArg ?? {}), model: modelOrFields }\n : (modelOrFields ?? {});\n const apiKey = fields.apiKey || getEnvironmentVariable(\"DEEPSEEK_API_KEY\");\n if (!apiKey) {\n throw new Error(\n `Deepseek API key not found. Please set the DEEPSEEK_API_KEY environment variable or pass the key into \"apiKey\" field.`\n );\n }\n\n super({\n ...fields,\n apiKey,\n configuration: {\n baseURL: \"https://api.deepseek.com\",\n ...fields.configuration,\n },\n });\n this._addVersion(\"@langchain/deepseek\", __PKG_VERSION__);\n }\n\n protected override _convertCompletionsDeltaToBaseMessageChunk(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n delta: Record<string, any>,\n rawResponse: OpenAIClient.ChatCompletionChunk,\n defaultRole?:\n | \"function\"\n | \"user\"\n | \"system\"\n | \"developer\"\n | \"assistant\"\n | \"tool\"\n ) {\n const messageChunk = super._convertCompletionsDeltaToBaseMessageChunk(\n delta,\n rawResponse,\n defaultRole\n );\n messageChunk.additional_kwargs.reasoning_content = delta.reasoning_content;\n // Override model_provider for DeepSeek-specific block translation\n messageChunk.response_metadata = {\n ...messageChunk.response_metadata,\n model_provider: \"deepseek\",\n };\n return messageChunk;\n }\n\n async *_streamResponseChunks(\n messages: BaseMessage[],\n options: this[\"ParsedCallOptions\"],\n runManager?: CallbackManagerForLLMRun\n ): AsyncGenerator<ChatGenerationChunk> {\n const stream = super._streamResponseChunks(messages, options, runManager);\n\n // State for parsing <think> tags\n let tokensBuffer = \"\";\n let isThinking = false;\n\n for await (const chunk of stream) {\n if (options.signal?.aborted) {\n return;\n }\n // If the model already provided reasoning_content natively, just yield it\n if (chunk.message.additional_kwargs.reasoning_content) {\n yield chunk;\n continue;\n }\n\n const text = chunk.text;\n if (!text) {\n yield chunk;\n continue;\n }\n\n // Append text to buffer to handle split tags\n tokensBuffer += text;\n\n // Check for <think> start tag\n if (!isThinking && tokensBuffer.includes(\"<think>\")) {\n isThinking = true;\n const thinkIndex = tokensBuffer.indexOf(\"<think>\");\n const beforeThink = tokensBuffer.substring(0, thinkIndex);\n const afterThink = tokensBuffer.substring(\n thinkIndex + \"<think>\".length\n );\n\n // We consumed up to <think>, so buffer becomes what's after\n tokensBuffer = afterThink || \"\"; // might be empty or part of thought\n\n if (beforeThink) {\n // Send the content before the tag\n const newChunk = new ChatGenerationChunk({\n message: new AIMessageChunk({\n content: beforeThink,\n additional_kwargs: chunk.message.additional_kwargs,\n response_metadata: chunk.message.response_metadata,\n tool_calls: chunk.message.tool_calls,\n tool_call_chunks: chunk.message.tool_call_chunks,\n id: chunk.message.id,\n }),\n text: beforeThink,\n generationInfo: chunk.generationInfo,\n });\n yield newChunk;\n }\n }\n\n // Check for </think> end tag\n if (isThinking && tokensBuffer.includes(\"</think>\")) {\n isThinking = false;\n const thinkEndIndex = tokensBuffer.indexOf(\"</think>\");\n const thoughtContent = tokensBuffer.substring(0, thinkEndIndex);\n const afterThink = tokensBuffer.substring(\n thinkEndIndex + \"</think>\".length\n );\n\n // Yield the reasoning content\n const reasoningChunk = new ChatGenerationChunk({\n message: new AIMessageChunk({\n content: \"\",\n additional_kwargs: {\n ...chunk.message.additional_kwargs,\n reasoning_content: thoughtContent,\n },\n response_metadata: chunk.message.response_metadata,\n tool_calls: chunk.message.tool_calls,\n tool_call_chunks: chunk.message.tool_call_chunks,\n id: chunk.message.id,\n }),\n text: \"\",\n generationInfo: chunk.generationInfo,\n });\n yield reasoningChunk;\n\n // Reset buffer to what's after </think>\n tokensBuffer = afterThink || \"\";\n\n // Yield the rest as normal content if any\n if (tokensBuffer) {\n const contentChunk = new ChatGenerationChunk({\n message: new AIMessageChunk({\n content: tokensBuffer,\n additional_kwargs: chunk.message.additional_kwargs,\n response_metadata: chunk.message.response_metadata,\n tool_calls: chunk.message.tool_calls,\n tool_call_chunks: chunk.message.tool_call_chunks,\n id: chunk.message.id,\n }),\n text: tokensBuffer,\n generationInfo: chunk.generationInfo,\n });\n yield contentChunk;\n tokensBuffer = \"\"; // consumed\n }\n } else if (isThinking) {\n // We are inside thinking block.\n // Check partial </think> match\n const possibleEndTag = \"</think>\";\n let splitIndex = -1;\n\n // Check if buffer ends with a prefix of </think> - Greedy check (longest first)\n for (let i = possibleEndTag.length - 1; i >= 1; i--) {\n if (tokensBuffer.endsWith(possibleEndTag.substring(0, i))) {\n splitIndex = tokensBuffer.length - i;\n break;\n }\n }\n\n if (splitIndex !== -1) {\n const safeToYield = tokensBuffer.substring(0, splitIndex);\n if (safeToYield) {\n const reasoningChunk = new ChatGenerationChunk({\n message: new AIMessageChunk({\n content: \"\",\n additional_kwargs: {\n ...chunk.message.additional_kwargs,\n reasoning_content: safeToYield,\n },\n response_metadata: chunk.message.response_metadata,\n tool_calls: chunk.message.tool_calls,\n tool_call_chunks: chunk.message.tool_call_chunks,\n id: chunk.message.id,\n }),\n text: \"\",\n generationInfo: chunk.generationInfo,\n });\n yield reasoningChunk;\n }\n tokensBuffer = tokensBuffer.substring(splitIndex); // keep partial tag\n } else {\n // content is safe to yield as reasoning\n if (tokensBuffer) {\n const reasoningChunk = new ChatGenerationChunk({\n message: new AIMessageChunk({\n content: \"\",\n additional_kwargs: {\n ...chunk.message.additional_kwargs,\n reasoning_content: tokensBuffer,\n },\n response_metadata: chunk.message.response_metadata,\n tool_calls: chunk.message.tool_calls,\n tool_call_chunks: chunk.message.tool_call_chunks,\n id: chunk.message.id,\n }),\n text: \"\",\n generationInfo: chunk.generationInfo,\n });\n yield reasoningChunk;\n tokensBuffer = \"\";\n }\n }\n } else {\n // NOT thinking.\n // Check partial start tag \"<think>\" - Greedy check (longest first)\n const possibleStartTag = \"<think>\";\n let splitIndex = -1;\n for (let i = possibleStartTag.length - 1; i >= 1; i--) {\n if (tokensBuffer.endsWith(possibleStartTag.substring(0, i))) {\n splitIndex = tokensBuffer.length - i;\n break;\n }\n }\n\n if (splitIndex !== -1) {\n // Yield safe content\n const safeToYield = tokensBuffer.substring(0, splitIndex);\n if (safeToYield) {\n const contentChunk = new ChatGenerationChunk({\n message: new AIMessageChunk({\n content: safeToYield,\n additional_kwargs: chunk.message.additional_kwargs,\n response_metadata: chunk.message.response_metadata,\n tool_calls: chunk.message.tool_calls,\n tool_call_chunks: chunk.message.tool_call_chunks,\n id: chunk.message.id,\n }),\n text: safeToYield,\n generationInfo: chunk.generationInfo,\n });\n yield contentChunk;\n }\n tokensBuffer = tokensBuffer.substring(splitIndex); // keep partial tag\n } else {\n // Yield all\n if (tokensBuffer) {\n const contentChunk = new ChatGenerationChunk({\n message: new AIMessageChunk({\n content: tokensBuffer,\n additional_kwargs: chunk.message.additional_kwargs,\n response_metadata: chunk.message.response_metadata,\n tool_calls: chunk.message.tool_calls,\n tool_call_chunks: chunk.message.tool_call_chunks,\n id: chunk.message.id,\n }),\n text: tokensBuffer,\n generationInfo: chunk.generationInfo,\n });\n yield contentChunk;\n tokensBuffer = \"\";\n }\n }\n }\n }\n\n // Flush remaining buffer at end of stream\n if (tokensBuffer) {\n // If we were thinking, it's unclosed thought.\n if (isThinking) {\n const reasoningChunk = new ChatGenerationChunk({\n message: new AIMessageChunk({\n content: \"\",\n additional_kwargs: { reasoning_content: tokensBuffer },\n }),\n text: \"\",\n });\n yield reasoningChunk;\n } else {\n const contentChunk = new ChatGenerationChunk({\n message: new AIMessageChunk({\n content: tokensBuffer,\n }),\n text: tokensBuffer,\n });\n yield contentChunk;\n }\n }\n }\n\n protected override _convertCompletionsMessageToBaseMessage(\n message: OpenAIClient.ChatCompletionMessage,\n rawResponse: OpenAIClient.ChatCompletion\n ) {\n const langChainMessage = super._convertCompletionsMessageToBaseMessage(\n message,\n rawResponse\n );\n langChainMessage.additional_kwargs.reasoning_content =\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (message as any).reasoning_content;\n // Override model_provider for DeepSeek-specific block translation\n langChainMessage.response_metadata = {\n ...langChainMessage.response_metadata,\n model_provider: \"deepseek\",\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 ChatDeepSeek({ model: \"deepseek-chat\" });\n * const profile = model.profile;\n * console.log(profile.maxInputTokens); // 128000\n * console.log(profile.imageInputs); // false\n * ```\n */\n get profile(): ModelProfile {\n return PROFILES[this.model] ?? {};\n }\n\n 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 | SerializableSchema<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 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 | SerializableSchema<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 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 | SerializableSchema<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 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 | SerializableSchema<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 // Deepseek does not support json schema yet\n if (ensuredConfig?.method === undefined) {\n ensuredConfig.method = \"functionCalling\";\n }\n return super.withStructuredOutput<RunOutput>(outputSchema, ensuredConfig);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0ZA,IAAa,eAAb,cAAkCA,wCAA+C;CAC/E,OAAO,UAAU;AACf,SAAO;;CAGT,WAAW;AACT,SAAO;;CAGT,IAAI,aAAoD;AACtD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OACT,mBAAmB,MAAM,QAAQ;OACjC,mBAAmB,MAAM,QAAQ;OACjC,YAAY,MAAM,QAAQ;OAC1B,kBAAkB,MAAM,QAAQ;OAChC,IAAI,MAAM,QAAQ;OACnB,CAAC;MACF,MAAM;MACN,gBAAgB,MAAM;MACvB,CAAC;AAEF,oBAAe;;;;AAOvB,MAAI,aAEF,KAAI,WAQF,OAPuB,IAAID,4CAAoB;GAC7C,SAAS,IAAIC,wCAAe;IAC1B,SAAS;IACT,mBAAmB,EAAE,mBAAmB,cAAc;IACvD,CAAC;GACF,MAAM;GACP,CAAC;MASF,OANqB,IAAID,4CAAoB;GAC3C,SAAS,IAAIC,wCAAe,EAC1B,SAAS,cACV,CAAC;GACF,MAAM;GACP,CAAC;;CAMR,AAAmB,wCACjB,SACA,aACA;EACA,MAAM,mBAAmB,MAAM,wCAC7B,SACA,YACD;AACD,mBAAiB,kBAAkB,oBAEhC,QAAgB;AAEnB,mBAAiB,oBAAoB;GACnC,GAAG,iBAAiB;GACpB,gBAAgB;GACjB;AACD,SAAO;;;;;;;;;;;;;;;;;;;CAoBT,IAAI,UAAwB;AAC1B,SAAOC,yBAAS,KAAK,UAAU,EAAE;;CAyCnC,qBAIE,cAKA,QAMI;EACJ,MAAM,gBAAgB,EAAE,GAAG,QAAQ;AAEnC,MAAI,eAAe,WAAW,OAC5B,eAAc,SAAS;AAEzB,SAAO,MAAM,qBAAgC,cAAc,cAAc"}
|
package/dist/chat_models.d.cts
CHANGED
|
@@ -7,6 +7,7 @@ import { InteropZodType } from "@langchain/core/utils/types";
|
|
|
7
7
|
import { ChatOpenAICallOptions, ChatOpenAICompletions, ChatOpenAIFields, OpenAIClient } from "@langchain/openai";
|
|
8
8
|
import { ChatGenerationChunk } from "@langchain/core/outputs";
|
|
9
9
|
import { CallbackManagerForLLMRun } from "@langchain/core/callbacks/manager";
|
|
10
|
+
import { SerializableSchema } from "@langchain/core/utils/standard_schema";
|
|
10
11
|
|
|
11
12
|
//#region src/chat_models.d.ts
|
|
12
13
|
interface ChatDeepSeekCallOptions extends ChatOpenAICallOptions {
|
|
@@ -428,12 +429,12 @@ declare class ChatDeepSeek extends ChatOpenAICompletions<ChatDeepSeekCallOptions
|
|
|
428
429
|
* ```
|
|
429
430
|
*/
|
|
430
431
|
get profile(): ModelProfile;
|
|
431
|
-
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;
|
|
432
|
-
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {
|
|
432
|
+
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | SerializableSchema<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;
|
|
433
|
+
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | SerializableSchema<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {
|
|
433
434
|
raw: BaseMessage;
|
|
434
435
|
parsed: RunOutput;
|
|
435
436
|
}>;
|
|
436
|
-
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<boolean>): Runnable<BaseLanguageModelInput, RunOutput> | Runnable<BaseLanguageModelInput, {
|
|
437
|
+
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | SerializableSchema<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<boolean>): Runnable<BaseLanguageModelInput, RunOutput> | Runnable<BaseLanguageModelInput, {
|
|
437
438
|
raw: BaseMessage;
|
|
438
439
|
parsed: RunOutput;
|
|
439
440
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat_models.d.cts","names":[],"sources":["../src/chat_models.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"chat_models.d.cts","names":[],"sources":["../src/chat_models.ts"],"mappings":";;;;;;;;;;;;UAoBiB,uBAAA,SAAgC,qBAAA;EAC/C,OAAA,GAAU,MAAA;AAAA;AAAA,UAGK,iBAAA,SAA0B,gBAAA;EAJF;;;;EASvC,MAAA;EARU;;;EAYV,KAAA;EATiC;;;;;EAejC,IAAA,GAAO,KAAA;EAfkD;;;;EAoBzD,aAAA,GAAgB,KAAA;EALT;;;EASP,SAAA;EAIA;;;EAAA,WAAA;EAsWW;;;;EAjWX,SAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAiWW,YAAA,SAAqB,qBAAA,CAAsB,uBAAA;EAAA,OAC/C,OAAA,CAAA;EAIP,QAAA,CAAA;EAAA,IAII,UAAA,CAAA;IAAA,CAAiB,GAAA;EAAA;EAMrB,eAAA;EAEA,YAAA;EAEA,WAAA,CAAY,KAAA,UAAe,MAAA,GAAS,IAAA,CAAK,iBAAA;EACzC,WAAA,CAAY,MAAA,GAAS,OAAA,CAAQ,iBAAA;EAAA,UA2BV,0CAAA,CAEjB,KAAA,EAAO,MAAA,eACP,WAAA,EAAa,YAAA,C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profile";
|
|
|
7
7
|
import { Runnable } from "@langchain/core/runnables";
|
|
8
8
|
import { InteropZodType } from "@langchain/core/utils/types";
|
|
9
9
|
import { CallbackManagerForLLMRun } from "@langchain/core/callbacks/manager";
|
|
10
|
+
import { SerializableSchema } from "@langchain/core/utils/standard_schema";
|
|
10
11
|
|
|
11
12
|
//#region src/chat_models.d.ts
|
|
12
13
|
interface ChatDeepSeekCallOptions extends ChatOpenAICallOptions {
|
|
@@ -428,12 +429,12 @@ declare class ChatDeepSeek extends ChatOpenAICompletions<ChatDeepSeekCallOptions
|
|
|
428
429
|
* ```
|
|
429
430
|
*/
|
|
430
431
|
get profile(): ModelProfile;
|
|
431
|
-
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;
|
|
432
|
-
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {
|
|
432
|
+
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | SerializableSchema<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;
|
|
433
|
+
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | SerializableSchema<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {
|
|
433
434
|
raw: BaseMessage;
|
|
434
435
|
parsed: RunOutput;
|
|
435
436
|
}>;
|
|
436
|
-
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<boolean>): Runnable<BaseLanguageModelInput, RunOutput> | Runnable<BaseLanguageModelInput, {
|
|
437
|
+
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | SerializableSchema<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<boolean>): Runnable<BaseLanguageModelInput, RunOutput> | Runnable<BaseLanguageModelInput, {
|
|
437
438
|
raw: BaseMessage;
|
|
438
439
|
parsed: RunOutput;
|
|
439
440
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat_models.d.ts","names":[],"sources":["../src/chat_models.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"chat_models.d.ts","names":[],"sources":["../src/chat_models.ts"],"mappings":";;;;;;;;;;;;UAoBiB,uBAAA,SAAgC,qBAAA;EAC/C,OAAA,GAAU,MAAA;AAAA;AAAA,UAGK,iBAAA,SAA0B,gBAAA;EAJF;;;;EASvC,MAAA;EARU;;;EAYV,KAAA;EATiC;;;;;EAejC,IAAA,GAAO,KAAA;EAfkD;;;;EAoBzD,aAAA,GAAgB,KAAA;EALT;;;EASP,SAAA;EAIA;;;EAAA,WAAA;EAsWW;;;;EAjWX,SAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAiWW,YAAA,SAAqB,qBAAA,CAAsB,uBAAA;EAAA,OAC/C,OAAA,CAAA;EAIP,QAAA,CAAA;EAAA,IAII,UAAA,CAAA;IAAA,CAA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AAA,GAAS,6BAAA,YAEP,QAAA,CAAS,sBAAA,EAAwB,SAAA,IACjC,QAAA,CAAS,sBAAA;IAA0B,GAAA,EAAK,WAAA;IAAa,MAAA,EAAQ,SAAA;EAAA;AAAA"}
|
package/dist/chat_models.js
CHANGED
|
@@ -386,7 +386,7 @@ var ChatDeepSeek = class extends ChatOpenAICompletions {
|
|
|
386
386
|
...fields.configuration
|
|
387
387
|
}
|
|
388
388
|
});
|
|
389
|
-
this._addVersion("@langchain/deepseek", "1.0.
|
|
389
|
+
this._addVersion("@langchain/deepseek", "1.0.17-dev-1773345797648");
|
|
390
390
|
}
|
|
391
391
|
_convertCompletionsDeltaToBaseMessageChunk(delta, rawResponse, defaultRole) {
|
|
392
392
|
const messageChunk = super._convertCompletionsDeltaToBaseMessageChunk(delta, rawResponse, defaultRole);
|
package/dist/chat_models.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat_models.js","names":[],"sources":["../src/chat_models.ts"],"sourcesContent":["import {\n BaseLanguageModelInput,\n StructuredOutputMethodOptions,\n} from \"@langchain/core/language_models/base\";\nimport { ModelProfile } from \"@langchain/core/language_models/profile\";\nimport { BaseMessage, AIMessageChunk } 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 ChatOpenAICallOptions,\n ChatOpenAICompletions,\n ChatOpenAIFields,\n OpenAIClient,\n} from \"@langchain/openai\";\nimport { ChatGenerationChunk } from \"@langchain/core/outputs\";\nimport { CallbackManagerForLLMRun } from \"@langchain/core/callbacks/manager\";\nimport PROFILES from \"./profiles.js\";\n\nexport interface ChatDeepSeekCallOptions extends ChatOpenAICallOptions {\n headers?: Record<string, string>;\n}\n\nexport interface ChatDeepSeekInput extends ChatOpenAIFields {\n /**\n * The Deepseek API key to use for requests.\n * @default process.env.DEEPSEEK_API_KEY\n */\n apiKey?: string;\n /**\n * The name of the model to use.\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 */\n temperature?: number;\n /**\n * The maximum number of tokens that the model can process in a single response.\n * This limits ensures computational efficiency and resource management.\n */\n maxTokens?: number;\n}\n\n/**\n * Deepseek chat model integration.\n *\n * The Deepseek API is compatible to the OpenAI API with some limitations.\n *\n * Setup:\n * Install `@langchain/deepseek` and set an environment variable named `DEEPSEEK_API_KEY`.\n *\n * ```bash\n * npm install @langchain/deepseek\n * export DEEPSEEK_API_KEY=\"your-api-key\"\n * ```\n *\n * ## [Constructor args](https://api.js.langchain.com/classes/_langchain_deepseek.ChatDeepSeek.html#constructor)\n *\n * ## [Runtime args](https://api.js.langchain.com/interfaces/_langchain_deepseek.ChatDeepSeekCallOptions.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 { ChatDeepSeek } from '@langchain/deepseek';\n *\n * const llm = new ChatDeepSeek({\n * model: \"deepseek-reasoner\",\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 ChatDeepSeek({\n * model: \"deepseek-chat\",\n * temperature: 0,\n * // other params...\n * });\n *\n * const GetWeather = {\n * name: \"GetWeather\",\n * description: \"Get the current weather in a given location\",\n * schema: z.object({\n * location: z.string().describe(\"The city and state, e.g. San Francisco, CA\")\n * }),\n * }\n *\n * const GetPopulation = {\n * name: \"GetPopulation\",\n * description: \"Get the current population in a given location\",\n * schema: z.object({\n * location: z.string().describe(\"The city and state, e.g. San Francisco, CA\")\n * }),\n * }\n *\n * const llmWithTools = llmForToolCalling.bindTools([GetWeather, GetPopulation]);\n * const aiMsg = await llmWithTools.invoke(\n * \"Which city is hotter today and which is bigger: LA or NY?\"\n * );\n * console.log(aiMsg.tool_calls);\n * ```\n *\n * ```txt\n * [\n * {\n * name: 'GetWeather',\n * args: { location: 'Los Angeles, CA' },\n * type: 'tool_call',\n * id: 'call_cd34'\n * },\n * {\n * name: 'GetWeather',\n * args: { location: 'New York, NY' },\n * type: 'tool_call',\n * id: 'call_68rf'\n * },\n * {\n * name: 'GetPopulation',\n * args: { location: 'Los Angeles, CA' },\n * type: 'tool_call',\n * id: 'call_f81z'\n * },\n * {\n * name: 'GetPopulation',\n * args: { location: 'New York, NY' },\n * type: 'tool_call',\n * id: 'call_8byt'\n * }\n * ]\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Structured Output</strong></summary>\n *\n * ```typescript\n * import { z } from 'zod';\n *\n * const Joke = z.object({\n * setup: z.string().describe(\"The setup of the joke\"),\n * punchline: z.string().describe(\"The punchline to the joke\"),\n * rating: z.number().optional().describe(\"How funny the joke is, from 1 to 10\")\n * }).describe('Joke to tell user.');\n *\n * const structuredLlm = llmForToolCalling.withStructuredOutput(Joke, { name: \"Joke\" });\n * const jokeResult = await structuredLlm.invoke(\"Tell me a joke about cats\");\n * console.log(jokeResult);\n * ```\n *\n * ```txt\n * {\n * setup: \"Why don't cats play poker in the wild?\",\n * punchline: 'Because there are too many cheetahs.'\n * }\n * ```\n * </details>\n *\n * <br />\n */\nexport class ChatDeepSeek extends ChatOpenAICompletions<ChatDeepSeekCallOptions> {\n static lc_name() {\n return \"ChatDeepSeek\";\n }\n\n _llmType() {\n return \"deepseek\";\n }\n\n get lc_secrets(): { [key: string]: string } | undefined {\n return {\n apiKey: \"DEEPSEEK_API_KEY\",\n };\n }\n\n lc_serializable = true;\n\n lc_namespace = [\"langchain\", \"chat_models\", \"deepseek\"];\n\n constructor(model: string, fields?: Omit<ChatDeepSeekInput, \"model\">);\n constructor(fields?: Partial<ChatDeepSeekInput>);\n constructor(\n modelOrFields?: string | Partial<ChatDeepSeekInput>,\n fieldsArg?: Omit<ChatDeepSeekInput, \"model\">\n ) {\n const fields =\n typeof modelOrFields === \"string\"\n ? { ...(fieldsArg ?? {}), model: modelOrFields }\n : (modelOrFields ?? {});\n const apiKey = fields.apiKey || getEnvironmentVariable(\"DEEPSEEK_API_KEY\");\n if (!apiKey) {\n throw new Error(\n `Deepseek API key not found. Please set the DEEPSEEK_API_KEY environment variable or pass the key into \"apiKey\" field.`\n );\n }\n\n super({\n ...fields,\n apiKey,\n configuration: {\n baseURL: \"https://api.deepseek.com\",\n ...fields.configuration,\n },\n });\n this._addVersion(\"@langchain/deepseek\", __PKG_VERSION__);\n }\n\n protected override _convertCompletionsDeltaToBaseMessageChunk(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n delta: Record<string, any>,\n rawResponse: OpenAIClient.ChatCompletionChunk,\n defaultRole?:\n | \"function\"\n | \"user\"\n | \"system\"\n | \"developer\"\n | \"assistant\"\n | \"tool\"\n ) {\n const messageChunk = super._convertCompletionsDeltaToBaseMessageChunk(\n delta,\n rawResponse,\n defaultRole\n );\n messageChunk.additional_kwargs.reasoning_content = delta.reasoning_content;\n // Override model_provider for DeepSeek-specific block translation\n messageChunk.response_metadata = {\n ...messageChunk.response_metadata,\n model_provider: \"deepseek\",\n };\n return messageChunk;\n }\n\n async *_streamResponseChunks(\n messages: BaseMessage[],\n options: this[\"ParsedCallOptions\"],\n runManager?: CallbackManagerForLLMRun\n ): AsyncGenerator<ChatGenerationChunk> {\n const stream = super._streamResponseChunks(messages, options, runManager);\n\n // State for parsing <think> tags\n let tokensBuffer = \"\";\n let isThinking = false;\n\n for await (const chunk of stream) {\n if (options.signal?.aborted) {\n return;\n }\n // If the model already provided reasoning_content natively, just yield it\n if (chunk.message.additional_kwargs.reasoning_content) {\n yield chunk;\n continue;\n }\n\n const text = chunk.text;\n if (!text) {\n yield chunk;\n continue;\n }\n\n // Append text to buffer to handle split tags\n tokensBuffer += text;\n\n // Check for <think> start tag\n if (!isThinking && tokensBuffer.includes(\"<think>\")) {\n isThinking = true;\n const thinkIndex = tokensBuffer.indexOf(\"<think>\");\n const beforeThink = tokensBuffer.substring(0, thinkIndex);\n const afterThink = tokensBuffer.substring(\n thinkIndex + \"<think>\".length\n );\n\n // We consumed up to <think>, so buffer becomes what's after\n tokensBuffer = afterThink || \"\"; // might be empty or part of thought\n\n if (beforeThink) {\n // Send the content before the tag\n const newChunk = new ChatGenerationChunk({\n message: new AIMessageChunk({\n content: beforeThink,\n additional_kwargs: chunk.message.additional_kwargs,\n response_metadata: chunk.message.response_metadata,\n tool_calls: chunk.message.tool_calls,\n tool_call_chunks: chunk.message.tool_call_chunks,\n id: chunk.message.id,\n }),\n text: beforeThink,\n generationInfo: chunk.generationInfo,\n });\n yield newChunk;\n }\n }\n\n // Check for </think> end tag\n if (isThinking && tokensBuffer.includes(\"</think>\")) {\n isThinking = false;\n const thinkEndIndex = tokensBuffer.indexOf(\"</think>\");\n const thoughtContent = tokensBuffer.substring(0, thinkEndIndex);\n const afterThink = tokensBuffer.substring(\n thinkEndIndex + \"</think>\".length\n );\n\n // Yield the reasoning content\n const reasoningChunk = new ChatGenerationChunk({\n message: new AIMessageChunk({\n content: \"\",\n additional_kwargs: {\n ...chunk.message.additional_kwargs,\n reasoning_content: thoughtContent,\n },\n response_metadata: chunk.message.response_metadata,\n tool_calls: chunk.message.tool_calls,\n tool_call_chunks: chunk.message.tool_call_chunks,\n id: chunk.message.id,\n }),\n text: \"\",\n generationInfo: chunk.generationInfo,\n });\n yield reasoningChunk;\n\n // Reset buffer to what's after </think>\n tokensBuffer = afterThink || \"\";\n\n // Yield the rest as normal content if any\n if (tokensBuffer) {\n const contentChunk = new ChatGenerationChunk({\n message: new AIMessageChunk({\n content: tokensBuffer,\n additional_kwargs: chunk.message.additional_kwargs,\n response_metadata: chunk.message.response_metadata,\n tool_calls: chunk.message.tool_calls,\n tool_call_chunks: chunk.message.tool_call_chunks,\n id: chunk.message.id,\n }),\n text: tokensBuffer,\n generationInfo: chunk.generationInfo,\n });\n yield contentChunk;\n tokensBuffer = \"\"; // consumed\n }\n } else if (isThinking) {\n // We are inside thinking block.\n // Check partial </think> match\n const possibleEndTag = \"</think>\";\n let splitIndex = -1;\n\n // Check if buffer ends with a prefix of </think> - Greedy check (longest first)\n for (let i = possibleEndTag.length - 1; i >= 1; i--) {\n if (tokensBuffer.endsWith(possibleEndTag.substring(0, i))) {\n splitIndex = tokensBuffer.length - i;\n break;\n }\n }\n\n if (splitIndex !== -1) {\n const safeToYield = tokensBuffer.substring(0, splitIndex);\n if (safeToYield) {\n const reasoningChunk = new ChatGenerationChunk({\n message: new AIMessageChunk({\n content: \"\",\n additional_kwargs: {\n ...chunk.message.additional_kwargs,\n reasoning_content: safeToYield,\n },\n response_metadata: chunk.message.response_metadata,\n tool_calls: chunk.message.tool_calls,\n tool_call_chunks: chunk.message.tool_call_chunks,\n id: chunk.message.id,\n }),\n text: \"\",\n generationInfo: chunk.generationInfo,\n });\n yield reasoningChunk;\n }\n tokensBuffer = tokensBuffer.substring(splitIndex); // keep partial tag\n } else {\n // content is safe to yield as reasoning\n if (tokensBuffer) {\n const reasoningChunk = new ChatGenerationChunk({\n message: new AIMessageChunk({\n content: \"\",\n additional_kwargs: {\n ...chunk.message.additional_kwargs,\n reasoning_content: tokensBuffer,\n },\n response_metadata: chunk.message.response_metadata,\n tool_calls: chunk.message.tool_calls,\n tool_call_chunks: chunk.message.tool_call_chunks,\n id: chunk.message.id,\n }),\n text: \"\",\n generationInfo: chunk.generationInfo,\n });\n yield reasoningChunk;\n tokensBuffer = \"\";\n }\n }\n } else {\n // NOT thinking.\n // Check partial start tag \"<think>\" - Greedy check (longest first)\n const possibleStartTag = \"<think>\";\n let splitIndex = -1;\n for (let i = possibleStartTag.length - 1; i >= 1; i--) {\n if (tokensBuffer.endsWith(possibleStartTag.substring(0, i))) {\n splitIndex = tokensBuffer.length - i;\n break;\n }\n }\n\n if (splitIndex !== -1) {\n // Yield safe content\n const safeToYield = tokensBuffer.substring(0, splitIndex);\n if (safeToYield) {\n const contentChunk = new ChatGenerationChunk({\n message: new AIMessageChunk({\n content: safeToYield,\n additional_kwargs: chunk.message.additional_kwargs,\n response_metadata: chunk.message.response_metadata,\n tool_calls: chunk.message.tool_calls,\n tool_call_chunks: chunk.message.tool_call_chunks,\n id: chunk.message.id,\n }),\n text: safeToYield,\n generationInfo: chunk.generationInfo,\n });\n yield contentChunk;\n }\n tokensBuffer = tokensBuffer.substring(splitIndex); // keep partial tag\n } else {\n // Yield all\n if (tokensBuffer) {\n const contentChunk = new ChatGenerationChunk({\n message: new AIMessageChunk({\n content: tokensBuffer,\n additional_kwargs: chunk.message.additional_kwargs,\n response_metadata: chunk.message.response_metadata,\n tool_calls: chunk.message.tool_calls,\n tool_call_chunks: chunk.message.tool_call_chunks,\n id: chunk.message.id,\n }),\n text: tokensBuffer,\n generationInfo: chunk.generationInfo,\n });\n yield contentChunk;\n tokensBuffer = \"\";\n }\n }\n }\n }\n\n // Flush remaining buffer at end of stream\n if (tokensBuffer) {\n // If we were thinking, it's unclosed thought.\n if (isThinking) {\n const reasoningChunk = new ChatGenerationChunk({\n message: new AIMessageChunk({\n content: \"\",\n additional_kwargs: { reasoning_content: tokensBuffer },\n }),\n text: \"\",\n });\n yield reasoningChunk;\n } else {\n const contentChunk = new ChatGenerationChunk({\n message: new AIMessageChunk({\n content: tokensBuffer,\n }),\n text: tokensBuffer,\n });\n yield contentChunk;\n }\n }\n }\n\n protected override _convertCompletionsMessageToBaseMessage(\n message: OpenAIClient.ChatCompletionMessage,\n rawResponse: OpenAIClient.ChatCompletion\n ) {\n const langChainMessage = super._convertCompletionsMessageToBaseMessage(\n message,\n rawResponse\n );\n langChainMessage.additional_kwargs.reasoning_content =\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (message as any).reasoning_content;\n // Override model_provider for DeepSeek-specific block translation\n langChainMessage.response_metadata = {\n ...langChainMessage.response_metadata,\n model_provider: \"deepseek\",\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 ChatDeepSeek({ model: \"deepseek-chat\" });\n * const profile = model.profile;\n * console.log(profile.maxInputTokens); // 128000\n * console.log(profile.imageInputs); // false\n * ```\n */\n get profile(): ModelProfile {\n return PROFILES[this.model] ?? {};\n }\n\n 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 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 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 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 // Deepseek does not support json schema yet\n if (ensuredConfig?.method === undefined) {\n ensuredConfig.method = \"functionCalling\";\n }\n return super.withStructuredOutput<RunOutput>(output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;CAoBT,IAAI,UAAwB;AAC1B,SAAO,SAAS,KAAK,UAAU,EAAE;;CAsCnC,qBAIE,cAIA,QAMI;EACJ,MAAM,gBAAgB,EAAE,GAAG,QAAQ;AAEnC,MAAI,eAAe,WAAW,OAC5B,eAAc,SAAS;AAEzB,SAAO,MAAM,qBAAgC,cAAc,cAAc"}
|
|
1
|
+
{"version":3,"file":"chat_models.js","names":[],"sources":["../src/chat_models.ts"],"sourcesContent":["import {\n BaseLanguageModelInput,\n StructuredOutputMethodOptions,\n} from \"@langchain/core/language_models/base\";\nimport { ModelProfile } from \"@langchain/core/language_models/profile\";\nimport { BaseMessage, AIMessageChunk } 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 ChatOpenAICallOptions,\n ChatOpenAICompletions,\n ChatOpenAIFields,\n OpenAIClient,\n} from \"@langchain/openai\";\nimport { ChatGenerationChunk } from \"@langchain/core/outputs\";\nimport { CallbackManagerForLLMRun } from \"@langchain/core/callbacks/manager\";\nimport PROFILES from \"./profiles.js\";\nimport { SerializableSchema } from \"@langchain/core/utils/standard_schema\";\n\nexport interface ChatDeepSeekCallOptions extends ChatOpenAICallOptions {\n headers?: Record<string, string>;\n}\n\nexport interface ChatDeepSeekInput extends ChatOpenAIFields {\n /**\n * The Deepseek API key to use for requests.\n * @default process.env.DEEPSEEK_API_KEY\n */\n apiKey?: string;\n /**\n * The name of the model to use.\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 */\n temperature?: number;\n /**\n * The maximum number of tokens that the model can process in a single response.\n * This limits ensures computational efficiency and resource management.\n */\n maxTokens?: number;\n}\n\n/**\n * Deepseek chat model integration.\n *\n * The Deepseek API is compatible to the OpenAI API with some limitations.\n *\n * Setup:\n * Install `@langchain/deepseek` and set an environment variable named `DEEPSEEK_API_KEY`.\n *\n * ```bash\n * npm install @langchain/deepseek\n * export DEEPSEEK_API_KEY=\"your-api-key\"\n * ```\n *\n * ## [Constructor args](https://api.js.langchain.com/classes/_langchain_deepseek.ChatDeepSeek.html#constructor)\n *\n * ## [Runtime args](https://api.js.langchain.com/interfaces/_langchain_deepseek.ChatDeepSeekCallOptions.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 { ChatDeepSeek } from '@langchain/deepseek';\n *\n * const llm = new ChatDeepSeek({\n * model: \"deepseek-reasoner\",\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 * \"reasoning_content\": \"...\",\n * },\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 ChatDeepSeek({\n * model: \"deepseek-chat\",\n * temperature: 0,\n * // other params...\n * });\n *\n * const GetWeather = {\n * name: \"GetWeather\",\n * description: \"Get the current weather in a given location\",\n * schema: z.object({\n * location: z.string().describe(\"The city and state, e.g. San Francisco, CA\")\n * }),\n * }\n *\n * const GetPopulation = {\n * name: \"GetPopulation\",\n * description: \"Get the current population in a given location\",\n * schema: z.object({\n * location: z.string().describe(\"The city and state, e.g. San Francisco, CA\")\n * }),\n * }\n *\n * const llmWithTools = llmForToolCalling.bindTools([GetWeather, GetPopulation]);\n * const aiMsg = await llmWithTools.invoke(\n * \"Which city is hotter today and which is bigger: LA or NY?\"\n * );\n * console.log(aiMsg.tool_calls);\n * ```\n *\n * ```txt\n * [\n * {\n * name: 'GetWeather',\n * args: { location: 'Los Angeles, CA' },\n * type: 'tool_call',\n * id: 'call_cd34'\n * },\n * {\n * name: 'GetWeather',\n * args: { location: 'New York, NY' },\n * type: 'tool_call',\n * id: 'call_68rf'\n * },\n * {\n * name: 'GetPopulation',\n * args: { location: 'Los Angeles, CA' },\n * type: 'tool_call',\n * id: 'call_f81z'\n * },\n * {\n * name: 'GetPopulation',\n * args: { location: 'New York, NY' },\n * type: 'tool_call',\n * id: 'call_8byt'\n * }\n * ]\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Structured Output</strong></summary>\n *\n * ```typescript\n * import { z } from 'zod';\n *\n * const Joke = z.object({\n * setup: z.string().describe(\"The setup of the joke\"),\n * punchline: z.string().describe(\"The punchline to the joke\"),\n * rating: z.number().optional().describe(\"How funny the joke is, from 1 to 10\")\n * }).describe('Joke to tell user.');\n *\n * const structuredLlm = llmForToolCalling.withStructuredOutput(Joke, { name: \"Joke\" });\n * const jokeResult = await structuredLlm.invoke(\"Tell me a joke about cats\");\n * console.log(jokeResult);\n * ```\n *\n * ```txt\n * {\n * setup: \"Why don't cats play poker in the wild?\",\n * punchline: 'Because there are too many cheetahs.'\n * }\n * ```\n * </details>\n *\n * <br />\n */\nexport class ChatDeepSeek extends ChatOpenAICompletions<ChatDeepSeekCallOptions> {\n static lc_name() {\n return \"ChatDeepSeek\";\n }\n\n _llmType() {\n return \"deepseek\";\n }\n\n get lc_secrets(): { [key: string]: string } | undefined {\n return {\n apiKey: \"DEEPSEEK_API_KEY\",\n };\n }\n\n lc_serializable = true;\n\n lc_namespace = [\"langchain\", \"chat_models\", \"deepseek\"];\n\n constructor(model: string, fields?: Omit<ChatDeepSeekInput, \"model\">);\n constructor(fields?: Partial<ChatDeepSeekInput>);\n constructor(\n modelOrFields?: string | Partial<ChatDeepSeekInput>,\n fieldsArg?: Omit<ChatDeepSeekInput, \"model\">\n ) {\n const fields =\n typeof modelOrFields === \"string\"\n ? { ...(fieldsArg ?? {}), model: modelOrFields }\n : (modelOrFields ?? {});\n const apiKey = fields.apiKey || getEnvironmentVariable(\"DEEPSEEK_API_KEY\");\n if (!apiKey) {\n throw new Error(\n `Deepseek API key not found. Please set the DEEPSEEK_API_KEY environment variable or pass the key into \"apiKey\" field.`\n );\n }\n\n super({\n ...fields,\n apiKey,\n configuration: {\n baseURL: \"https://api.deepseek.com\",\n ...fields.configuration,\n },\n });\n this._addVersion(\"@langchain/deepseek\", __PKG_VERSION__);\n }\n\n protected override _convertCompletionsDeltaToBaseMessageChunk(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n delta: Record<string, any>,\n rawResponse: OpenAIClient.ChatCompletionChunk,\n defaultRole?:\n | \"function\"\n | \"user\"\n | \"system\"\n | \"developer\"\n | \"assistant\"\n | \"tool\"\n ) {\n const messageChunk = super._convertCompletionsDeltaToBaseMessageChunk(\n delta,\n rawResponse,\n defaultRole\n );\n messageChunk.additional_kwargs.reasoning_content = delta.reasoning_content;\n // Override model_provider for DeepSeek-specific block translation\n messageChunk.response_metadata = {\n ...messageChunk.response_metadata,\n model_provider: \"deepseek\",\n };\n return messageChunk;\n }\n\n async *_streamResponseChunks(\n messages: BaseMessage[],\n options: this[\"ParsedCallOptions\"],\n runManager?: CallbackManagerForLLMRun\n ): AsyncGenerator<ChatGenerationChunk> {\n const stream = super._streamResponseChunks(messages, options, runManager);\n\n // State for parsing <think> tags\n let tokensBuffer = \"\";\n let isThinking = false;\n\n for await (const chunk of stream) {\n if (options.signal?.aborted) {\n return;\n }\n // If the model already provided reasoning_content natively, just yield it\n if (chunk.message.additional_kwargs.reasoning_content) {\n yield chunk;\n continue;\n }\n\n const text = chunk.text;\n if (!text) {\n yield chunk;\n continue;\n }\n\n // Append text to buffer to handle split tags\n tokensBuffer += text;\n\n // Check for <think> start tag\n if (!isThinking && tokensBuffer.includes(\"<think>\")) {\n isThinking = true;\n const thinkIndex = tokensBuffer.indexOf(\"<think>\");\n const beforeThink = tokensBuffer.substring(0, thinkIndex);\n const afterThink = tokensBuffer.substring(\n thinkIndex + \"<think>\".length\n );\n\n // We consumed up to <think>, so buffer becomes what's after\n tokensBuffer = afterThink || \"\"; // might be empty or part of thought\n\n if (beforeThink) {\n // Send the content before the tag\n const newChunk = new ChatGenerationChunk({\n message: new AIMessageChunk({\n content: beforeThink,\n additional_kwargs: chunk.message.additional_kwargs,\n response_metadata: chunk.message.response_metadata,\n tool_calls: chunk.message.tool_calls,\n tool_call_chunks: chunk.message.tool_call_chunks,\n id: chunk.message.id,\n }),\n text: beforeThink,\n generationInfo: chunk.generationInfo,\n });\n yield newChunk;\n }\n }\n\n // Check for </think> end tag\n if (isThinking && tokensBuffer.includes(\"</think>\")) {\n isThinking = false;\n const thinkEndIndex = tokensBuffer.indexOf(\"</think>\");\n const thoughtContent = tokensBuffer.substring(0, thinkEndIndex);\n const afterThink = tokensBuffer.substring(\n thinkEndIndex + \"</think>\".length\n );\n\n // Yield the reasoning content\n const reasoningChunk = new ChatGenerationChunk({\n message: new AIMessageChunk({\n content: \"\",\n additional_kwargs: {\n ...chunk.message.additional_kwargs,\n reasoning_content: thoughtContent,\n },\n response_metadata: chunk.message.response_metadata,\n tool_calls: chunk.message.tool_calls,\n tool_call_chunks: chunk.message.tool_call_chunks,\n id: chunk.message.id,\n }),\n text: \"\",\n generationInfo: chunk.generationInfo,\n });\n yield reasoningChunk;\n\n // Reset buffer to what's after </think>\n tokensBuffer = afterThink || \"\";\n\n // Yield the rest as normal content if any\n if (tokensBuffer) {\n const contentChunk = new ChatGenerationChunk({\n message: new AIMessageChunk({\n content: tokensBuffer,\n additional_kwargs: chunk.message.additional_kwargs,\n response_metadata: chunk.message.response_metadata,\n tool_calls: chunk.message.tool_calls,\n tool_call_chunks: chunk.message.tool_call_chunks,\n id: chunk.message.id,\n }),\n text: tokensBuffer,\n generationInfo: chunk.generationInfo,\n });\n yield contentChunk;\n tokensBuffer = \"\"; // consumed\n }\n } else if (isThinking) {\n // We are inside thinking block.\n // Check partial </think> match\n const possibleEndTag = \"</think>\";\n let splitIndex = -1;\n\n // Check if buffer ends with a prefix of </think> - Greedy check (longest first)\n for (let i = possibleEndTag.length - 1; i >= 1; i--) {\n if (tokensBuffer.endsWith(possibleEndTag.substring(0, i))) {\n splitIndex = tokensBuffer.length - i;\n break;\n }\n }\n\n if (splitIndex !== -1) {\n const safeToYield = tokensBuffer.substring(0, splitIndex);\n if (safeToYield) {\n const reasoningChunk = new ChatGenerationChunk({\n message: new AIMessageChunk({\n content: \"\",\n additional_kwargs: {\n ...chunk.message.additional_kwargs,\n reasoning_content: safeToYield,\n },\n response_metadata: chunk.message.response_metadata,\n tool_calls: chunk.message.tool_calls,\n tool_call_chunks: chunk.message.tool_call_chunks,\n id: chunk.message.id,\n }),\n text: \"\",\n generationInfo: chunk.generationInfo,\n });\n yield reasoningChunk;\n }\n tokensBuffer = tokensBuffer.substring(splitIndex); // keep partial tag\n } else {\n // content is safe to yield as reasoning\n if (tokensBuffer) {\n const reasoningChunk = new ChatGenerationChunk({\n message: new AIMessageChunk({\n content: \"\",\n additional_kwargs: {\n ...chunk.message.additional_kwargs,\n reasoning_content: tokensBuffer,\n },\n response_metadata: chunk.message.response_metadata,\n tool_calls: chunk.message.tool_calls,\n tool_call_chunks: chunk.message.tool_call_chunks,\n id: chunk.message.id,\n }),\n text: \"\",\n generationInfo: chunk.generationInfo,\n });\n yield reasoningChunk;\n tokensBuffer = \"\";\n }\n }\n } else {\n // NOT thinking.\n // Check partial start tag \"<think>\" - Greedy check (longest first)\n const possibleStartTag = \"<think>\";\n let splitIndex = -1;\n for (let i = possibleStartTag.length - 1; i >= 1; i--) {\n if (tokensBuffer.endsWith(possibleStartTag.substring(0, i))) {\n splitIndex = tokensBuffer.length - i;\n break;\n }\n }\n\n if (splitIndex !== -1) {\n // Yield safe content\n const safeToYield = tokensBuffer.substring(0, splitIndex);\n if (safeToYield) {\n const contentChunk = new ChatGenerationChunk({\n message: new AIMessageChunk({\n content: safeToYield,\n additional_kwargs: chunk.message.additional_kwargs,\n response_metadata: chunk.message.response_metadata,\n tool_calls: chunk.message.tool_calls,\n tool_call_chunks: chunk.message.tool_call_chunks,\n id: chunk.message.id,\n }),\n text: safeToYield,\n generationInfo: chunk.generationInfo,\n });\n yield contentChunk;\n }\n tokensBuffer = tokensBuffer.substring(splitIndex); // keep partial tag\n } else {\n // Yield all\n if (tokensBuffer) {\n const contentChunk = new ChatGenerationChunk({\n message: new AIMessageChunk({\n content: tokensBuffer,\n additional_kwargs: chunk.message.additional_kwargs,\n response_metadata: chunk.message.response_metadata,\n tool_calls: chunk.message.tool_calls,\n tool_call_chunks: chunk.message.tool_call_chunks,\n id: chunk.message.id,\n }),\n text: tokensBuffer,\n generationInfo: chunk.generationInfo,\n });\n yield contentChunk;\n tokensBuffer = \"\";\n }\n }\n }\n }\n\n // Flush remaining buffer at end of stream\n if (tokensBuffer) {\n // If we were thinking, it's unclosed thought.\n if (isThinking) {\n const reasoningChunk = new ChatGenerationChunk({\n message: new AIMessageChunk({\n content: \"\",\n additional_kwargs: { reasoning_content: tokensBuffer },\n }),\n text: \"\",\n });\n yield reasoningChunk;\n } else {\n const contentChunk = new ChatGenerationChunk({\n message: new AIMessageChunk({\n content: tokensBuffer,\n }),\n text: tokensBuffer,\n });\n yield contentChunk;\n }\n }\n }\n\n protected override _convertCompletionsMessageToBaseMessage(\n message: OpenAIClient.ChatCompletionMessage,\n rawResponse: OpenAIClient.ChatCompletion\n ) {\n const langChainMessage = super._convertCompletionsMessageToBaseMessage(\n message,\n rawResponse\n );\n langChainMessage.additional_kwargs.reasoning_content =\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (message as any).reasoning_content;\n // Override model_provider for DeepSeek-specific block translation\n langChainMessage.response_metadata = {\n ...langChainMessage.response_metadata,\n model_provider: \"deepseek\",\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 ChatDeepSeek({ model: \"deepseek-chat\" });\n * const profile = model.profile;\n * console.log(profile.maxInputTokens); // 128000\n * console.log(profile.imageInputs); // false\n * ```\n */\n get profile(): ModelProfile {\n return PROFILES[this.model] ?? {};\n }\n\n 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 | SerializableSchema<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 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 | SerializableSchema<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 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 | SerializableSchema<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 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 | SerializableSchema<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 // Deepseek does not support json schema yet\n if (ensuredConfig?.method === undefined) {\n ensuredConfig.method = \"functionCalling\";\n }\n return super.withStructuredOutput<RunOutput>(outputSchema, ensuredConfig);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/deepseek",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.17-dev-1773345797648",
|
|
4
4
|
"description": "Deepseek integration for LangChain.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "LangChain",
|
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
},
|
|
15
15
|
"homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-deepseek",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@langchain/openai": "1.2.
|
|
17
|
+
"@langchain/openai": "1.2.13-dev-1773345797648"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"@langchain/core": "
|
|
20
|
+
"@langchain/core": "1.1.32-dev-1773345797648"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@tsconfig/recommended": "^1.0.3",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
"prettier": "^3.5.0",
|
|
29
29
|
"typescript": "~5.8.3",
|
|
30
30
|
"vitest": "^3.2.4",
|
|
31
|
-
"@langchain/
|
|
31
|
+
"@langchain/eslint": "0.1.1",
|
|
32
32
|
"@langchain/standard-tests": "0.0.23",
|
|
33
|
-
"@langchain/
|
|
34
|
-
"@langchain/
|
|
33
|
+
"@langchain/core": "^1.1.32-dev-1773345797648",
|
|
34
|
+
"@langchain/tsconfig": "0.0.1"
|
|
35
35
|
},
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"access": "public"
|