lib/gen_ai/language/google_palm.rb in gen-ai-0.3.0 vs lib/gen_ai/language/google_palm.rb in gen-ai-0.3.1
- old
+ new
@@ -53,11 +53,11 @@
private
def build_chat_options(message, context, history, examples, options)
{
model: options.delete(:model) || CHAT_COMPLETION_MODEL,
- messages: history.append({ author: DEFAULT_ROLE, content: message }),
+ messages: history.append(build_message(message, history)),
examples: compose_examples(examples),
context: context
}.merge(options)
end
@@ -83,9 +83,17 @@
def array_wrap(object)
return [] if object.nil?
object.respond_to?(:to_ary) ? object.to_ary || [object] : [object]
+ end
+
+ def build_message(message, history)
+ if message.is_a?(String)
+ { author: history.dig(0, :role) || DEFAULT_ROLE, content: message }
+ else
+ message
+ end
end
def extract_embeddings(responses)
responses.map { |response| response.dig('embedding', 'value') }
end