Class: LlmGateway::Adapters::OpenAi::Responses::InputMapper

Inherits:
ChatCompletions::InputMapper show all
Defined in:
lib/llm_gateway/adapters/open_ai/responses/input_mapper.rb

Class Method Summary collapse

Methods inherited from ChatCompletions::InputMapper

map

Class Method Details

.map_messages(messages) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/llm_gateway/adapters/open_ai/responses/input_mapper.rb', line 28

def self.map_messages(messages)
  return messages unless messages
  mapper = message_mapper

  # First map messages like Claude
  messages.map do |msg|
    if msg[:id]
      msg = msg.merge(role: "assistant")
      msg.slice(:id)
    else
      content = if msg[:content].is_a?(Array)
          msg[:content].map do |content|
            mapper.map_content(content)
          end
      elsif msg[:id]
        mapper.map_content(msg)
      else
        [ mapper.map_content(msg[:content]) ]
      end
      if msg.dig(:content).is_a?(Array) && msg.dig(:content, 0, :type) == "tool_result"
        content
      else
        {
          role: msg[:role],
          content: content
        }
      end
    end
  end
end

.map_tools(tools) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/llm_gateway/adapters/open_ai/responses/input_mapper.rb', line 15

def self.map_tools(tools)
  return tools unless tools

  tools.map do |tool|
    {
      type: "function",
      name: tool[:name],
      description: tool[:description],
      parameters: tool[:input_schema]
    }
  end
end

.message_mapperObject



11
12
13
# File 'lib/llm_gateway/adapters/open_ai/responses/input_mapper.rb', line 11

def self.message_mapper
  BidirectionalMessageMapper.new(LlmGateway::DIRECTION_IN)
end