Runtime args can be passed as the second argument to any of the base runnable methods .invoke. .stream, .batch, etc.
They can also be passed via .withConfig, or the second arg in .bindTools, like shown in the examples below:
// When calling `.withConfig`, call options should be passed via the first argument constllmWithArgsBound = llm.withConfig({ stop: ["\n"], tools: [...], });
// When calling `.bindTools`, call options should be passed via the second argument constllmWithTools = llm.bindTools( [...], { tool_choice:"auto", } );
constllm = newChatDeepSeek({ model:"deepseek-reasoner", temperature:0, // other params... });
Invoking
constinput = `Translate "I love programming" into French.`;
// Models also accept a list of chat messages or a formatted prompt constresult = awaitllm.invoke(input); console.log(result);
AIMessage {
"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.",
"additional_kwargs": {
"reasoning_content": "...",
},
"response_metadata": {
"tokenUsage": {
"completionTokens": 82,
"promptTokens": 20,
"totalTokens": 102
},
"finish_reason": "stop"
},
"tool_calls": [],
"invalid_tool_calls": []
}
AIMessageChunk {
"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.",
"additional_kwargs": {
"reasoning_content": "...",
},
"response_metadata": {
"finishReason": "stop"
},
"tool_calls": [],
"tool_call_chunks": [],
"invalid_tool_calls": []
}
Bind tools
import { z } from'zod';
constllmForToolCalling = newChatDeepSeek({ model:"deepseek-chat", temperature:0, // other params... });
constGetWeather = { name:"GetWeather", description:"Get the current weather in a given location", schema:z.object({ location:z.string().describe("The city and state, e.g. San Francisco, CA") }), }
constGetPopulation = { name:"GetPopulation", description:"Get the current population in a given location", schema:z.object({ location:z.string().describe("The city and state, e.g. San Francisco, CA") }), }
constllmWithTools = llmForToolCalling.bindTools([GetWeather, GetPopulation]); constaiMsg = awaitllmWithTools.invoke( "Which city is hotter today and which is bigger: LA or NY?" ); console.log(aiMsg.tool_calls);
constJoke = z.object({ setup:z.string().describe("The setup of the joke"), punchline:z.string().describe("The punchline to the joke"), rating:z.number().optional().describe("How funny the joke is, from 1 to 10") }).describe('Joke to tell user.');
conststructuredLlm = llmForToolCalling.withStructuredOutput(Joke, { name:"Joke" }); constjokeResult = awaitstructuredLlm.invoke("Tell me a joke about cats"); console.log(jokeResult);
{
setup: "Why don't cats play poker in the wild?",
punchline: 'Because there are too many cheetahs.'
}
Deepseek chat model integration.
The Deepseek API is compatible to the OpenAI API with some limitations.
Setup: Install
@langchain/deepseek
and set an environment variable namedDEEPSEEK_API_KEY
.Constructor args
Runtime args
Runtime args can be passed as the second argument to any of the base runnable methods
.invoke
..stream
,.batch
, etc. They can also be passed via.withConfig
, or the second arg in.bindTools
, like shown in the examples below:Examples
Instantiate
Invoking
Streaming Chunks
Aggregate Streamed Chunks
Bind tools
Structured Output