View Source Anthropic (anthropic_community v0.1.0)
Provides an unofficial Elixir wrapper for the Anthropic API, facilitating access to the Claude LLM model. This module handles configuration, request preparation, and communication with the API.
Summary
Functions
Adds a assistant message to the request.
Adds a message to the request with a specified role.
Adds a system message to the request.
Adds a user message to the request.
Initializes a new Anthropic.Config struct with the given options, merging them with the default configuration.
Sends the current request to the Anthropic API and awaits the next message in the conversation.
Functions
Adds a assistant message to the request.
Parameters
request: TheAnthropic.Messages.Requeststruct to which the assistant message will be added.message: The content of the assistant message, must be a binary string.
Returns
- The updated
Anthropic.Messages.Requeststruct with the assistant message added.
Adds a message to the request with a specified role.
Parameters
request: TheAnthropic.Messages.Requeststruct to which the message will be added.role: The role of the message (e.g.,:useror:assistant).message: The content of the message, can be a binary string, or a list of binary strings that will be treated as different messages.
Returns
- The updated
Anthropic.Messages.Requeststruct with the new message added.
Adds a system message to the request.
Parameters
request: The currentAnthropic.Messages.Requeststruct to which the system message will be added.message: The system message to add, must be a binary string.
Returns
- The updated
Anthropic.Messages.Requeststruct with the system message added.
Errors
- Raises
ArgumentErrorif the message is not a binary string.
Adds a user message to the request.
Parameters
request: TheAnthropic.Messages.Requeststruct to which the user message will be added.message: The content of the user message, must be a binary string.
Returns
- The updated
Anthropic.Messages.Requeststruct with the user message added.
Initializes a new Anthropic.Config struct with the given options, merging them with the default configuration.
Parameters
opts: (Optional) A keyword list of options to override the default configuration settings.
Returns
- A new
Anthropic.Messages.Requeststruct populated with the merged configuration options.
Sends the current request to the Anthropic API and awaits the next message in the conversation.
This function encapsulates the process of sending the prepared request to the Anthropic API, parsing the response, and preparing the next step of the conversation based on the API's response.
Parameters
request: TheAnthropic.Messages.Requeststruct that contains the current state of the conversation.http_client_opts: (Optional) A list of options for the HTTP client used to make the request. These options are passed directly to the HTTP client.
Returns
- On success, returns a tuple
{:ok, response_content, updated_request}whereresponse_contentis the content of the response from the API, andupdated_requestis the updated request struct including the response message. - On failure, returns a tuple
{:error, response, request}whereresponsecontains error information provided by the API or HTTP client.
This function is the main mechanism through which conversations are advanced, by sending user or assistant messages to the API and incorporating the API's responses into the ongoing conversation.