Class: SkillBench::Clients::Providers::Anthropic

Inherits:
BaseClient
  • Object
show all
Defined in:
lib/skill_bench/clients/providers/anthropic.rb

Overview

Anthropic Claude-specific LLM client. Uses the Messages API endpoint with Claude models.

Constant Summary collapse

VERSION =
'2023-06-01'

Instance Attribute Summary

Attributes inherited from BaseClient

#api_key, #messages, #model, #options, #system_prompt, #tools

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseClient

call, #call, #initialize

Constructor Details

This class inherits a constructor from SkillBench::Clients::BaseClient

Class Method Details

.translate_assistant_message(msg) ⇒ Hash

Translates assistant message with tool calls to Anthropic format.

Parameters:

  • msg (Hash)

    The assistant message.

Returns:

  • (Hash)

    Translated message for Anthropic.



166
167
168
169
170
171
172
173
174
175
176
# File 'lib/skill_bench/clients/providers/anthropic.rb', line 166

def translate_assistant_message(msg)
  content = []
  text = msg[:content] || msg['content']
  content << { type: 'text', text: text } if text && !text.empty?

  (msg[:tool_calls] || msg['tool_calls'])&.each do |tool_call|
    content << build_tool_use_block(tool_call)
  end

  { role: 'assistant', content: content }
end

.translate_tool_message(msg) ⇒ Hash

Translates tool result message to Anthropic format.

Parameters:

  • msg (Hash)

    The tool result message.

Returns:

  • (Hash)

    Translated message for Anthropic.



182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/skill_bench/clients/providers/anthropic.rb', line 182

def translate_tool_message(msg)
  {
    role: 'user',
    content: [
      {
        type: 'tool_result',
        tool_use_id: msg[:tool_call_id] || msg['tool_call_id'],
        content: msg[:content] || msg['content']
      }
    ]
  }
end

.translate_tools(tools) ⇒ Array<Hash>

Translates standard tool definitions to Anthropic tool format.

Parameters:

  • tools (Array<Hash>)

    List of tool definitions.

Returns:

  • (Array<Hash>)

    Translated tools for Anthropic.



152
153
154
155
156
157
158
159
160
# File 'lib/skill_bench/clients/providers/anthropic.rb', line 152

def translate_tools(tools)
  tools.map do |tool|
    {
      name: tool.dig(:function, :name) || tool.dig('function', 'name'),
      description: tool.dig(:function, :description) || tool.dig('function', 'description'),
      input_schema: tool.dig(:function, :parameters) || tool.dig('function', 'parameters')
    }
  end
end

Instance Method Details

#provider_nameSymbol

Returns the provider identifier.

Returns:

  • (Symbol)


19
20
21
# File 'lib/skill_bench/clients/providers/anthropic.rb', line 19

def provider_name
  :anthropic
end