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 =
[ /\Aclaude-3-7-(?:sonnet|haiku|opus)(?:-\d{8}|-latest)?\z/, /\Aclaude-3-5-(?:sonnet|haiku|opus)(?:-\d{8}|-latest)?\z/, /\Aclaude-3-(?:sonnet|haiku|opus)(?:-\d{8}|-latest)?\z/, /\Aclaude-2(?:\.\d)?\z/, /\Aclaude-instant-(?:\d\.\d)?\z/ ].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
19 20 21 |
# File 'lib/lammy/claude.rb', line 19 def initialize(settings) @settings = settings end |
Instance Attribute Details
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
17 18 19 |
# File 'lib/lammy/claude.rb', line 17 def settings @settings end |
Instance Method Details
#chat(user_message, system_message = nil, stream = nil) ⇒ Object
Generate a response with support for structured output
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/lammy/claude.rb', line 24 def chat(, = nil, stream = nil) response = client.( parameters: { system: , model: settings[:model] || Lammy.configuration.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 |