Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 42 additions & 17 deletions lib/ruby_llm/providers/gemini/chat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,29 +89,54 @@ def parse_completion_response(response)
def convert_schema_to_gemini(schema) # rubocop:disable Metrics/PerceivedComplexity
return nil unless schema

result = case schema[:type]
when 'object'
properties = schema[:properties]&.transform_values { |prop| convert_schema_to_gemini(prop) } || {}
object_result = {
type: 'OBJECT',
properties: properties,
required: schema[:required] || []
}
object_result[:propertyOrdering] = schema[:propertyOrdering] if schema[:propertyOrdering]
object_result[:nullable] = schema[:nullable] if schema.key?(:nullable)
object_result
when 'array'
{
type: 'ARRAY',
items: schema[:items] ? convert_schema_to_gemini(schema[:items]) : { type: 'STRING' }
}
when 'number'
{ type: 'NUMBER' }
when 'integer'
{ type: 'INTEGER' }
when 'boolean'
{ type: 'BOOLEAN' }
else
{ type: 'STRING' }
end

result[:description] = schema[:description] if schema[:description]

case schema[:type]
when 'object'
{
type: 'OBJECT',
properties: schema[:properties]&.transform_values { |prop| convert_schema_to_gemini(prop) } || {},
required: schema[:required] || []
}
when 'array'
{
type: 'ARRAY',
items: schema[:items] ? convert_schema_to_gemini(schema[:items]) : { type: 'STRING' }
}
when 'string'
result = { type: 'STRING' }
result[:enum] = schema[:enum] if schema[:enum]
result
result[:format] = schema[:format] if schema[:format]
result[:nullable] = schema[:nullable] if schema.key?(:nullable)
when 'number', 'integer'
{ type: 'NUMBER' }
result[:format] = schema[:format] if schema[:format]
result[:minimum] = schema[:minimum] if schema[:minimum]
result[:maximum] = schema[:maximum] if schema[:maximum]
result[:enum] = schema[:enum] if schema[:enum]
result[:nullable] = schema[:nullable] if schema.key?(:nullable)
when 'array'
result[:minItems] = schema[:minItems] if schema[:minItems]
result[:maxItems] = schema[:maxItems] if schema[:maxItems]
result[:nullable] = schema[:nullable] if schema.key?(:nullable)
when 'boolean'
{ type: 'BOOLEAN' }
else
{ type: 'STRING' }
result[:nullable] = schema[:nullable] if schema.key?(:nullable)
end

result
end

def extract_content(data)
Expand Down