Class: Lluminary::Providers::Anthropic
- Defined in:
- lib/lluminary/providers/anthropic.rb
Overview
Provider for Anthropic’s models. Implements the Base provider interface for Anthropic’s API.
Constant Summary collapse
- NAME =
:anthropic- DEFAULT_MODEL =
Models::Anthropic::Claude35Sonnet
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #call(prompt, _task) ⇒ Object
-
#initialize(**config_overrides) ⇒ Anthropic
constructor
A new instance of Anthropic.
- #model ⇒ Object
- #models ⇒ Object
Constructor Details
#initialize(**config_overrides) ⇒ Anthropic
Returns a new instance of Anthropic.
17 18 19 20 21 |
# File 'lib/lluminary/providers/anthropic.rb', line 17 def initialize(**config_overrides) super @config = { model: DEFAULT_MODEL }.merge(config) @client = ::Anthropic::Client.new(api_key: config[:api_key]) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
15 16 17 |
# File 'lib/lluminary/providers/anthropic.rb', line 15 def client @client end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
15 16 17 |
# File 'lib/lluminary/providers/anthropic.rb', line 15 def config @config end |
Instance Method Details
#call(prompt, _task) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/lluminary/providers/anthropic.rb', line 23 def call(prompt, _task) = client..create( max_tokens: 1024, # TODO: make this configurable messages: [{ role: "user", content: prompt }], model: model.class::NAME ) content = .content.first.text { raw: content, parsed: begin JSON.parse(content) if content rescue JSON::ParserError nil end } end |
#model ⇒ Object
44 45 46 |
# File 'lib/lluminary/providers/anthropic.rb', line 44 def model @model ||= config[:model].new end |
#models ⇒ Object
48 49 50 51 |
# File 'lib/lluminary/providers/anthropic.rb', line 48 def models response = @client.models.list response.data.map { |model| model.id } end |