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, }, } );
Description
This function initializes a ChatModel based on the provided model name and provider.
It supports various model providers and allows for runtime configuration of model parameters.
Security Note: Setting configurableFields to "any" means fields like api_key, base_url, etc.
can be altered at runtime, potentially redirecting model requests to a different service/user.
Make sure that if you're accepting untrusted configurations, you enumerate the
configurableFields explicitly.
The function will attempt to infer the model provider from the model name if not specified.
Certain model name prefixes are associated with specific providers:
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".
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.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:
Description
This function initializes a ChatModel based on the provided model name and provider. It supports various model providers and allows for runtime configuration of model parameters.
Security Note: Setting
configurableFields
to "any" means fields like api_key, base_url, etc. can be altered at runtime, potentially redirecting model requests to a different service/user. Make sure that if you're accepting untrusted configurations, you enumerate theconfigurableFields
explicitly.The function will attempt to infer the model provider from the model name if not specified. Certain model name prefixes are associated with specific providers:
Since
0.2.11
Version
0.2.11