Class: GenAI::Language::Anthropic
- Includes:
- Api::Format::Anthropic
- Defined in:
- lib/gen_ai/language/anthropic.rb
Constant Summary collapse
- BASE_API_URL =
'https://api.anthropic.com'
- ANTHROPIC_VERSION =
'2023-06-01'
- ANTHROPIC_BETA =
'messages-2023-12-15'
- COMPLETION_MODEL =
'claude-2.1'
- DEFAULT_MAX_TOKENS =
1024
Constants inherited from Base
Instance Method Summary collapse
- #chat(messages, options = {}) ⇒ Object
- #complete(prompt, options = {}) ⇒ Object
-
#initialize(token:, options: {}) ⇒ Anthropic
constructor
A new instance of Anthropic.
Methods included from Api::Format::Anthropic
#extract_completions, #format_messages
Methods inherited from Base
Methods included from Dependency
Constructor Details
#initialize(token:, options: {}) ⇒ Anthropic
Returns a new instance of Anthropic.
16 17 18 19 |
# File 'lib/gen_ai/language/anthropic.rb', line 16 def initialize(token:, options: {}) @token = token build_client(token) end |
Instance Method Details
#chat(messages, options = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/gen_ai/language/anthropic.rb', line 31 def chat(, = {}) response = client.post '/v1/messages', { messages: (), model: .delete(:model) || COMPLETION_MODEL, max_tokens: .delete(:max_tokens) || DEFAULT_MAX_TOKENS }.merge() build_result(model: COMPLETION_MODEL, raw: response, parsed: extract_completions(response)) end |
#complete(prompt, options = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/gen_ai/language/anthropic.rb', line 21 def complete(prompt, = {}) response = client.post '/v1/complete', { prompt: "\n\nHuman: #{prompt}\n\nAssistant:", model: .delete(:model) || COMPLETION_MODEL, max_tokens_to_sample: .delete(:max_tokens_to_sample) || DEFAULT_MAX_TOKENS }.merge() build_result(model: COMPLETION_MODEL, raw: response, parsed: extract_completions(response)) end |