View Source InstructorLite.Adapters.Anthropic (instructor_lite v0.3.0)
Anthropic adapter.
This adapter is implemented using the Messages API and function calling.
Params
params
argument should be shaped as a Create message request body.
Example
InstructorLite.instruct(%{
messages: [%{role: "user", content: "John is 25yo"}],
model: "claude-3-5-sonnet-20240620",
metadata: %{user_id: "3125"}
},
response_model: %{name: :string, age: :integer},
adapter: InstructorLite.Adapters.Anthropic,
adapter_context: [api_key: Application.fetch_env!(:instructor_lite, :anthropic_key)]
)
{:ok, %{name: "John", age: 25}}
Summary
Functions
Updates params
with prompt based on json_schema
and notes
.
Parse API response.
Updates params
with prompt for retrying a request.
Make request to Anthropic API
Functions
Updates params
with prompt based on json_schema
and notes
.
Also specifies default claude-3-5-sonnet-20240620
model and 1024 max_tokens
if not provided by a user.
Parse API response.
Can return:
{:ok, parsed_object}
on success.{:error, :unexpected_response, response}
if response is of unexpected shape.
Updates params
with prompt for retrying a request.
The error is represented as an erroneous tool_result
.
Make request to Anthropic API
Options
:api_key
(String.t/0
) - Required. Anthropic API key:http_client
(atom/0
) - Any module that followsReq.post/2
interface The default value isReq
.:http_options
(keyword/0
) - Options passed tohttp_client.post/2
The default value is[receive_timeout: 60000]
.:url
(String.t/0
) - API endpoint to use for sending requests The default value is"https://api.anthropic.com/v1/messages"
.:version
(String.t/0
) - Anthropic API version The default value is"2023-06-01"
.