Class: LLM::Anthropic
- Includes:
- Format
- Defined in:
- lib/llm/providers/anthropic.rb,
lib/llm/providers/anthropic/format.rb,
lib/llm/providers/anthropic/error_handler.rb,
lib/llm/providers/anthropic/response_parser.rb
Overview
The Anthropic class implements a provider for [Anthropic](www.anthropic.com)
Defined Under Namespace
Modules: Format, ResponseParser Classes: ErrorHandler
Constant Summary collapse
- HOST =
"api.anthropic.com"- DEFAULT_PARAMS =
{max_tokens: 1024, model: "claude-3-5-sonnet-20240620"}.freeze
Instance Method Summary collapse
- #complete(prompt, role = :user, **params) ⇒ LLM::Response::Completion
- #embed(input, **params) ⇒ LLM::Response::Embedding
-
#initialize(secret) ⇒ Anthropic
constructor
A new instance of Anthropic.
Methods included from Format
Methods inherited from Provider
Methods included from HTTPClient
Constructor Details
Instance Method Details
#complete(prompt, role = :user, **params) ⇒ LLM::Response::Completion
38 39 40 41 42 43 44 45 46 |
# File 'lib/llm/providers/anthropic.rb', line 38 def complete(prompt, role = :user, **params) req = Net::HTTP::Post.new ["/v1", "messages"].join("/") = [*(params.delete(:messages) || []), Message.new(role, prompt)] params = DEFAULT_PARAMS.merge(params) body = {messages: format()}.merge!(params) req = preflight(req, body) res = request(@http, req) Response::Completion.new(res).extend(response_parser) end |
#embed(input, **params) ⇒ LLM::Response::Embedding
25 26 27 28 29 30 31 |
# File 'lib/llm/providers/anthropic.rb', line 25 def (input, **params) req = Net::HTTP::Post.new ["api.voyageai.com/v1", "embeddings"].join("/") body = {input:, model: "voyage-2"}.merge!(params) req = preflight(req, body) res = request(@http, req) Response::Embedding.new(res).extend(response_parser) end |