ExLLM.Providers.Anthropic (ex_llm v0.8.1)

View Source

Anthropic Claude API adapter for ExLLM.

Configuration

This adapter requires an Anthropic API key and optionally a base URL.

Using Environment Variables

# Set environment variables
export ANTHROPIC_API_KEY="your-api-key"
export ANTHROPIC_MODEL="claude-3-5-sonnet-20241022"  # optional

# Use with default environment provider
ExLLM.Providers.Anthropic.chat(messages, config_provider: ExLLM.Infrastructure.ConfigProvider.Env)

Using Static Configuration

config = %{
  anthropic: %{
    api_key: "your-api-key",
    model: "claude-3-5-sonnet-20241022",
    base_url: "https://api.anthropic.com/v1"  # optional
  }
}
{:ok, provider} = ExLLM.Infrastructure.ConfigProvider.Static.start_link(config)
ExLLM.Providers.Anthropic.chat(messages, config_provider: provider)

Example Usage

messages = [
  %{role: "user", content: "Hello, how are you?"}
]

# Simple chat
{:ok, response} = ExLLM.Providers.Anthropic.chat(messages)
IO.puts(response.content)

# Streaming chat
{:ok, stream} = ExLLM.Providers.Anthropic.stream_chat(messages)
for chunk <- stream do
  if chunk.content, do: IO.write(chunk.content)
end

Summary

Functions

Generate embeddings for text (not yet supported by Anthropic).

Functions

embeddings(inputs, options \\ [])

@spec embeddings(
  [String.t()],
  keyword()
) :: {:error, term()}

Generate embeddings for text (not yet supported by Anthropic).

This function is a placeholder as Anthropic doesn't currently offer an embeddings API. It will return an error indicating lack of support.