Class: Net::Llm::Anthropic
- Inherits:
-
Object
- Object
- Net::Llm::Anthropic
- Defined in:
- lib/net/llm/anthropic.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#http ⇒ Object
readonly
Returns the value of attribute http.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
-
#initialize(api_key:, model: "claude-3-5-sonnet-20241022", http: Net::Llm.http) ⇒ Anthropic
constructor
A new instance of Anthropic.
- #messages(messages, system: nil, max_tokens: 1024, tools: nil, &block) ⇒ Object
Constructor Details
#initialize(api_key:, model: "claude-3-5-sonnet-20241022", http: Net::Llm.http) ⇒ Anthropic
Returns a new instance of Anthropic.
8 9 10 11 12 |
# File 'lib/net/llm/anthropic.rb', line 8 def initialize(api_key:, model: "claude-3-5-sonnet-20241022", http: Net::Llm.http) @api_key = api_key @model = model @http = http end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
6 7 8 |
# File 'lib/net/llm/anthropic.rb', line 6 def api_key @api_key end |
#http ⇒ Object (readonly)
Returns the value of attribute http.
6 7 8 |
# File 'lib/net/llm/anthropic.rb', line 6 def http @http end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
6 7 8 |
# File 'lib/net/llm/anthropic.rb', line 6 def model @model end |
Instance Method Details
#messages(messages, system: nil, max_tokens: 1024, tools: nil, &block) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/net/llm/anthropic.rb', line 14 def (, system: nil, max_tokens: 1024, tools: nil, &block) url = "https://api.anthropic.com/v1/messages" payload = build_payload(, system, max_tokens, tools, block_given?) if block_given? stream_request(url, payload, &block) else post_request(url, payload) end end |