Class: Anthropic::Client
- Inherits:
-
Object
- Object
- Anthropic::Client
- Includes:
- HTTP
- Defined in:
- lib/anthropic/client.rb
Constant Summary collapse
- CONFIG_KEYS =
%i[ access_token anthropic_version api_version uri_base request_timeout extra_headers ].freeze
Instance Method Summary collapse
-
#complete(parameters: {}) ⇒ Object
deprecated
Deprecated.
(but still works while Anthropic API responds to it)
-
#initialize(config = {}, &faraday_middleware) ⇒ Client
constructor
A new instance of Client.
-
#messages(parameters: {}) ⇒ Object
Anthropic API Parameters as of 2024-05-07: @see docs.anthropic.com/claude/reference/messages_post.
Methods included from HTTP
#delete, #get, #json_post, #multipart_post
Methods included from HTTPHeaders
Constructor Details
#initialize(config = {}, &faraday_middleware) ⇒ Client
Returns a new instance of Client.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/anthropic/client.rb', line 14 def initialize(config = {}, &faraday_middleware) CONFIG_KEYS.each do |key| # Set instance variables like api_type & access_token. Fall back to global config # if not present. instance_variable_set( "@#{key}", config[key].nil? ? Anthropic.configuration.send(key) : config[key] ) end @faraday_middleware = faraday_middleware end |
Instance Method Details
#complete(parameters: {}) ⇒ Object
Deprecated.
(but still works while Anthropic API responds to it)
27 28 29 30 |
# File 'lib/anthropic/client.rb', line 27 def complete(parameters: {}) parameters[:prompt] = wrap_prompt(prompt: parameters[:prompt]) json_post(path: "/complete", parameters: parameters) end |
#messages(parameters: {}) ⇒ Object
Anthropic API Parameters as of 2024-05-07:
@see https://docs.anthropic.com/claude/reference/messages_post
"id" => "msg_013xVudG9xjSvLGwPKMeVXzG",
"type" => "message",
"role" => "assistant",
"content" => [{"type" => "text", "text" => "The sky has no distinct"],
"model" => "claude-2.1",
"stop_reason" => "max_tokens",
"stop_sequence" => nil,
"usage" => => 15, "output_tokens" => 5
}
66 67 68 |
# File 'lib/anthropic/client.rb', line 66 def (parameters: {}) json_post(path: "/messages", parameters: parameters) end |