19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/llm_gateway/adapters/openai/chat_completions/output_mapper.rb', line 19
def self.map_choices(choices)
return [] unless choices
message_mapper = BidirectionalMessageMapper.new(LlmGateway::DIRECTION_OUT)
choices.map do |choice|
message = choice[:message] || {}
content_item = message_mapper.map_content(message[:content])
tool_calls = message[:tool_calls] ? message[:tool_calls].map { |tool_call| message_mapper.map_content(tool_call) } : []
content_array = []
content_array << content_item if LlmGateway::Utils.present?(content_item[:text])
content_array += tool_calls
{ role: message[:role], content: content_array }
end
end
|