Sha256: 85c48c77c0007a81659f46b765455c0eb12dc10d7d4422d65a8fb4d2a3a1b2f8
Contents?: true
Size: 826 Bytes
Versions: 4
Compression:
Stored size: 826 Bytes
Contents
# frozen_string_literal: true module GenAI class Chat class Gemini < Base include GenAI::Api::Format::Gemini private def build_history(messages, context, examples) history = format_messages(messages.drop(1)) history.prepend({ role: USER_ROLE, parts: [{text: build_first_message(context, examples, messages.first)}] }) history end def build_first_message(context, examples, message) chunks = [] chunks << context if context chunks << examples.map { |example| "#{example[:role]}: #{example[:content]}" }.join("\n") if examples.any? chunks << message[:content] if message chunks.join("\n") end def append_to_message(message) @history.last[:parts][0][:text] << "\n" << message end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
gen-ai-0.4.3 | lib/gen_ai/chat/gemini.rb |
gen-ai-0.4.2 | lib/gen_ai/chat/gemini.rb |
gen-ai-0.4.1 | lib/gen_ai/chat/gemini.rb |
gen-ai-0.4.0 | lib/gen_ai/chat/gemini.rb |