Class: RailsConsoleAi::Providers::Anthropic
- Inherits:
-
Base
- Object
- Base
- RailsConsoleAi::Providers::Anthropic
show all
- Defined in:
- lib/rails_console_ai/providers/anthropic.rb
Constant Summary
collapse
- API_URL =
'https://api.anthropic.com'.freeze
Instance Attribute Summary
Attributes inherited from Base
#config
Instance Method Summary
collapse
Methods inherited from Base
#initialize
Instance Method Details
#chat(messages, system_prompt: nil) ⇒ Object
6
7
8
9
|
# File 'lib/rails_console_ai/providers/anthropic.rb', line 6
def chat(messages, system_prompt: nil)
result = call_api(messages, system_prompt: system_prompt)
result
end
|
11
12
13
|
# File 'lib/rails_console_ai/providers/anthropic.rb', line 11
def chat_with_tools(messages, tools:, system_prompt: nil)
call_api(messages, system_prompt: system_prompt, tools: tools)
end
|
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/rails_console_ai/providers/anthropic.rb', line 15
def format_assistant_message(result)
content_blocks = []
content_blocks << { 'type' => 'text', 'text' => result.text } if result.text && !result.text.empty?
(result.tool_calls || []).each do |tc|
content_blocks << {
'type' => 'tool_use',
'id' => tc[:id],
'name' => tc[:name],
'input' => tc[:arguments]
}
end
{ role: 'assistant', content: content_blocks }
end
|
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/rails_console_ai/providers/anthropic.rb', line 30
def format_tool_result(tool_call_id, result_string)
{
role: 'user',
content: [
{
'type' => 'tool_result',
'tool_use_id' => tool_call_id,
'content' => result_string.to_s
}
]
}
end
|