Class: LlmGateway::Adapters::OpenAI::Responses::OutputMapper

Inherits:
Object
  • Object
show all
Defined in:
lib/llm_gateway/adapters/openai/responses/output_mapper.rb

Class Method Summary collapse

Class Method Details

.map(data) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/llm_gateway/adapters/openai/responses/output_mapper.rb', line 11

def self.map(data)
  {
    id: data[:id],
    model: data[:model],
    usage: data[:usage],
    choices: map_choices(data[:output])
  }
end

.map_choices(choices) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/llm_gateway/adapters/openai/responses/output_mapper.rb', line 22

def self.map_choices(choices)
  return [] unless choices
  message_mapper = BidirectionalMessageMapper.new(LlmGateway::DIRECTION_OUT)
  choices.map do |choice|
    content = if choice[:id].start_with?("fc_")
      {
        id: choice[:id],
        role: choice[:role] || "assistant", # tool call doesnt have a role apparently
        content: [ message_mapper.map_content(choice) ].flatten
      }
    else
     content = message_mapper.map_content(choice)
     id = content.delete(:id)
     {
       id: choice[:id] || id,
       role: choice[:role],
       content: [ content ].flatten
     }
    end
  end
end