View Source LangChain.ChatModels.ChatAnthropic (LangChain v0.2.0)
Module for interacting with Anthropic models.
Parses and validates inputs for making requests to Anthropic's messages API.
Converts responses into more specialized LangChain
data structures.
Summary
Functions
Calls the Anthropic API passing the ChatAnthropic struct with configuration, plus either a simple message or the list of messages to act as the prompt.
Convert a LangChain structure to the expected map of data for the OpenAI API.
Return the params formatted for an API request.
Setup a ChatAnthropic client configuration.
Setup a ChatAnthropic client configuration and return it or raise an error if invalid.
After all the messages have been converted using for_api/1
, this combines
multiple sequential tool response messages. The Anthropic API is very strict
about user, assistant, user, assistant sequenced messages.
Types
Functions
Calls the Anthropic API passing the ChatAnthropic struct with configuration, plus either a simple message or the list of messages to act as the prompt.
Optionally pass in a callback function that can be executed as data is received from the API.
NOTE: This function can be used directly, but the primary interface
should be through LangChain.Chains.LLMChain
. The ChatAnthropic
module is more focused on
translating the LangChain
data structures to and from the Anthropic API.
Another benefit of using LangChain.Chains.LLMChain
is that it combines the
storage of messages, adding functions, adding custom context that should be
passed to functions, and automatically applying LangChain.MessageDelta
structs as they are are received, then converting those to the full
LangChain.Message
once fully complete.
@spec for_api( LangChain.Message.t() | LangChain.Message.ContentPart.t() | LangChain.Function.t() ) :: %{required(String.t()) => any()} | no_return()
Convert a LangChain structure to the expected map of data for the OpenAI API.
@spec for_api(t(), message :: [map()], LangChain.ChatModels.ChatModel.tools()) :: %{ required(atom()) => any() }
Return the params formatted for an API request.
@spec new(attrs :: map()) :: {:ok, t()} | {:error, Ecto.Changeset.t()}
Setup a ChatAnthropic client configuration.
Setup a ChatAnthropic client configuration and return it or raise an error if invalid.
After all the messages have been converted using for_api/1
, this combines
multiple sequential tool response messages. The Anthropic API is very strict
about user, assistant, user, assistant sequenced messages.