Module: IntelliAgent::Anthropic

Defined in:
lib/intelli_agent/anthropic.rb

Constant Summary collapse

BASIC_MODEL =

ENV.fetch(‘Anthropic_BASIC_MODEL’)

'claude-3-haiku-20240307'
ADVANCED_MODEL =

ENV.fetch(‘Anthropic_ADVANCED_MODEL’)

'claude-3-5-sonnet-20240620'

Class Method Summary collapse

Class Method Details

.chat(system:, messages:, model: :basic, max_tokens: 1000) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/intelli_agent/anthropic.rb', line 24

def self.chat(system:, messages:, model: :basic, max_tokens: 1000)
  model = select_model(model)
  
  parameters = { model:, max_tokens:, system:, messages: }

  response = Anthropic::Client.new.messages(parameters:)
  response.dig('content', 0, 'text').strip
end

.select_model(model) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/intelli_agent/anthropic.rb', line 33

def self.select_model(model)
  case model
  when :basic
    BASIC_MODEL
  when :advanced
    ADVANCED_MODEL
  else
    model
  end
end

.single_chat(system:, user:, model: :basic, max_tokens: 1000) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/intelli_agent/anthropic.rb', line 14

def self.single_chat(system:, user:, model: :basic, max_tokens: 1000)
  model = select_model(model)

  parameters = { model:, system:, max_tokens:,
                 messages: [ { role: 'user', content: user } ] }

  response = Anthropic::Client.new.messages(parameters:)
  response.dig('content', 0, 'text').strip
end

.single_prompt(prompt:, model: :basic, max_tokens: 1000) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/intelli_agent/anthropic.rb', line 5

def self.single_prompt(prompt:, model: :basic, max_tokens: 1000)
  model = select_model(model)

  parameters = { model:, max_tokens:, messages: [{ role: 'user', content: prompt }] }

  response = Anthropic::Client.new.messages(parameters:)
  response.dig('content', 0, 'text').strip
end