Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 4390e83

Browse files
committed
Gemini is now working as well
1 parent 85717bc commit 4390e83

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

lib/completions/dialects/chat_gpt.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,10 @@ def user_msg(msg)
130130

131131
def no_array_if_only_text(content_array)
132132
if content_array.size == 1 && content_array.first[:type] == "text"
133-
return content_array.first[:text]
133+
content_array.first[:text]
134+
else
135+
content_array
134136
end
135-
content_array
136137
end
137138

138139
def image_node(details)

lib/completions/dialects/gemini.rb

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -106,28 +106,29 @@ def model_msg(msg)
106106
end
107107

108108
def user_msg(msg)
109-
if beta_api?
110-
# support new format with multiple parts
111-
result = { role: "user", parts: [{ text: msg[:content] }] }
112-
return result unless vision_support?
109+
content_array = []
110+
content_array << "#{msg[:id]}: " if msg[:id]
111+
112+
content_array << msg[:content]
113+
content_array.flatten!
114+
115+
content_array =
116+
to_encoded_content_array(
117+
content: content_array,
118+
image_encoder: ->(details) { image_node(details) },
119+
text_encoder: ->(text) { { text: text } },
120+
allow_vision: vision_support? && beta_api?,
121+
)
113122

114-
upload_parts = uploaded_parts(msg)
115-
result[:parts].concat(upload_parts) if upload_parts.present?
116-
result
123+
if beta_api?
124+
{ role: "user", parts: content_array }
117125
else
118-
{ role: "user", parts: { text: msg[:content] } }
126+
{ role: "user", parts: content_array.first }
119127
end
120128
end
121129

122-
def uploaded_parts(message)
123-
encoded_uploads = prompt.encoded_uploads(message)
124-
result = []
125-
if encoded_uploads.present?
126-
encoded_uploads.each do |details|
127-
result << { inlineData: { mimeType: details[:mime_type], data: details[:base64] } }
128-
end
129-
end
130-
result
130+
def image_node(details)
131+
{ inlineData: { mimeType: details[:mime_type], data: details[:base64] } }
131132
end
132133

133134
def tool_call_msg(msg)

0 commit comments

Comments
 (0)