Sha256: 7bdd30849d64a400d02394c295059f3d2d6c271d0e3bff9b6d958992d7b41727
Contents?: true
Size: 662 Bytes
Versions: 3
Compression:
Stored size: 662 Bytes
Contents
# frozen_string_literal: true module GenAI module Api module Format module Gemini def format_messages(messages) messages.map { |message| transform_message(message) } end def transform_message(message) { role: role_for(message), parts: [text: message[:content]] } end def extract_completions(response) response['candidates'].map { |candidate| candidate.dig('content', 'parts', 0, 'text') } end private def role_for(message) message[:role] == 'user' ? self.class::USER_ROLE : self.class::ASSISTANT_ROLE end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
gen-ai-0.4.0.alpha.3 | lib/gen_ai/api/format/gemini.rb |
gen-ai-0.4.0.alpha.2 | lib/gen_ai/api/format/gemini.rb |
gen-ai-0.4.0.alpha.1 | lib/gen_ai/api/format/gemini.rb |