Class: LlmGateway::Adapters::Anthropic::InputMapper
- Inherits:
-
Object
- Object
- LlmGateway::Adapters::Anthropic::InputMapper
- Defined in:
- lib/llm_gateway/adapters/anthropic/input_mapper.rb
Class Method Summary collapse
Class Method Details
.map(data) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/llm_gateway/adapters/anthropic/input_mapper.rb', line 9 def self.map(data) { messages: (data[:messages]), tools: data[:tools], system: map_system(data[:system]) } end |
.map_messages(messages) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/llm_gateway/adapters/anthropic/input_mapper.rb', line 19 def self.() return unless = BidirectionalMessageMapper.new(LlmGateway::DIRECTION_IN) .map do |msg| msg = msg.merge(role: "user") if msg[:role] == "developer" content = if msg[:content].is_a?(Array) msg[:content].map do |content| .map_content(content) end else [ .map_content(msg[:content]) ] end { role: msg[:role], content: content } end end |
.map_system(system) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/llm_gateway/adapters/anthropic/input_mapper.rb', line 42 def self.map_system(system) if !system || system.empty? nil elsif system.length == 1 && system.first[:role] == "system" # If we have a single system message, convert to Claude format mapped = { type: "text", text: system.first[:content] } mapped[:cache_control] = system.first[:cache_control] if system.first[:cache_control] [ mapped ] else # For multiple messages or non-standard format, pass through system end end |