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", } );
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 = llm.bindTools([GetWeather, GetPopulation]); constaiMsg = awaitllmWithTools.invoke( "Which city is hotter today and which is bigger: LA or NY? Respond with JSON and use tools." ); 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 = llm.withStructuredOutput(Joke, { name:"Joke" }); constjokeResult = awaitstructuredLlm.invoke("Tell me a joke about cats"); console.log(jokeResult);
{
setup: 'Why did the cat join a band',
punchline: 'Because it wanted to be the purr-cussionist'
}
TogetherAI chat model integration.
The TogetherAI API is compatible to the OpenAI API with some limitations. View the full API ref at:
Link
Setup: Install
@langchain/community
and set an environment variable namedTOGETHER_AI_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
Usage Metadata
Response Metadata