diff --git a/lib/ruby_llm/providers/gemini/chat.rb b/lib/ruby_llm/providers/gemini/chat.rb index 65b0fc41c..fc7f8c799 100644 --- a/lib/ruby_llm/providers/gemini/chat.rb +++ b/lib/ruby_llm/providers/gemini/chat.rb @@ -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)