Class: Lammy::Claude
- Inherits:
-
Object
- Object
- Lammy::Claude
- Defined in:
- lib/lammy/claude.rb
Overview
Use the Claude API’s Ruby library
Constant Summary collapse
- MODELS =
%w[ claude-3-5-sonnet-latest claude-3-5-haiku-latest claude-3-opus-latest claude-3-5-sonnet-20240620 claude-3-5-haiku-20241022 claude-3-opus-20240229 claude-3-sonnet-20240229 claude-3-haiku-20240307 claude-2.1 claude-2.0 claude-instant-1.2 ].freeze
Instance Attribute Summary collapse
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
Instance Method Summary collapse
-
#chat(user_message, system_message = nil, stream = nil) ⇒ Object
Generate a response with support for structured output.
-
#initialize(settings) ⇒ Claude
constructor
A new instance of Claude.
Constructor Details
#initialize(settings) ⇒ Claude
Returns a new instance of Claude.
18 19 20 |
# File 'lib/lammy/claude.rb', line 18 def initialize(settings) @settings = settings end |
Instance Attribute Details
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
16 17 18 |
# File 'lib/lammy/claude.rb', line 16 def settings @settings end |
Instance Method Details
#chat(user_message, system_message = nil, stream = nil) ⇒ Object
Generate a response with support for structured output
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/lammy/claude.rb', line 23 def chat(, = nil, stream = nil) response = client.( parameters: { system: , model: settings[:model], max_tokens: settings[:max_tokens] || 4096, stream: stream ? ->(chunk) { stream.call(stream_content(chunk)) } : nil, messages: .is_a?(Array) ? : [vision(L.user())] }.compact ) stream || response.dig('content', 0, 'text') end |