Initialize a ChatModel from the model name and provider.
Must have the integration package corresponding to the model provider installed.
Template: RunInput
The input type for the model.
Template: CallOptions
Call options for the model.
Param: model
The name of the model, e.g. "gpt-4", "claude-3-opus-20240229".
Can be prefixed with the model provider, e.g. "openai:gpt-4", "anthropic:claude-3-opus-20240229".
constgetWeatherTool = tool( (input) => { // Do something with the input returnJSON.stringify(input); }, { schema:z .object({ location:z .string() .describe("The city and state, e.g. San Francisco, CA"), }) .describe("Get the current weather in a given location"), name:"GetWeather", description:"Get the current weather in a given location", } );
constgetPopulationTool = tool( (input) => { // Do something with the input returnJSON.stringify(input); }, { schema:z .object({ location:z .string() .describe("The city and state, e.g. San Francisco, CA"), }) .describe("Get the current population in a given location"), name:"GetPopulation", description:"Get the current population in a given location", } );
constconfigurableToolResult = awaitconfigurableModelWithTools.invoke( "Which city is hotter today and which is bigger: LA or NY?", { configurable: { apiKey:process.env.OPENAI_API_KEY, }, } );
constconfigurableToolResult2 = awaitconfigurableModelWithTools.invoke( "Which city is hotter today and which is bigger: LA or NY?", { configurable: { model:"claude-3-5-sonnet-20240620", apiKey:process.env.ANTHROPIC_API_KEY, }, } );
Initialize a ChatModel from the model name and provider. Must have the integration package corresponding to the model provider installed.
Template: RunInput
The input type for the model.
Template: CallOptions
Call options for the model.
Param: model
The name of the model, e.g. "gpt-4", "claude-3-opus-20240229". Can be prefixed with the model provider, e.g. "openai:gpt-4", "anthropic:claude-3-opus-20240229".
Param: fields
Additional configuration options.
Param: fields.modelProvider
The model provider. Supported values include:
Param: fields.configurableFields
Which model parameters are configurable:
Param: fields.configPrefix
Prefix for configurable fields at runtime.
Param: fields.profile
Overrides the profiling information for the model. If not provided, the profile will be inferred from the inner model instance.
Param: fields.params
Additional keyword args to pass to the ChatModel constructor.
Returns
A class which extends BaseChatModel.
Throws
If modelProvider cannot be inferred or isn't supported.
Throws
If the model provider integration package is not installed.
Example: Initialize non-configurable models
Example: Create a partially configurable model with no default model
Example: Create a fully configurable model with a default model and a config prefix
Example: Bind tools to a configurable model:
Example: Initialize a model with a custom profile