module L::Schema

def self.formatted?(content)

def self.formatted?(content)
  content.is_a?(Hash) && content.key?(:role) && content.key?(:content)
end

def assistant(content)

def assistant(content)
  return content if L::Schema.formatted?(content)
  { role: :assistant, content: content }
end

def system(content)

def system(content)
  return content if L::Schema.formatted?(content)
  { role: :system, content: content }
end

def to_a(object)

helper methods to help you define your JSON Schema easily.
omitting a required key, or hallucinating an invalid enum value. This is a set of
that adhere to your supplied JSON Schema, so you don't need to worry about the model
Structured Outputs is a feature that ensures the model will always generate responses
def to_a(object)
  {
    'type' => 'object',
    'properties' => {
      'items' => {
        'type' => 'array', 'items' => to_h(object)
      }
    },
    'required' => ['items']
  }
end

def to_h(object)

def to_h(object)
  {
    'type' => 'object',
    'properties' => object.inject({}) { |h, (k, v)| h.merge(k.to_s => v.is_a?(Symbol) ? { 'type' => v.to_s } : v) },
    'required' => object.keys
  }
end

def user(content, image: nil)

def user(content, image: nil)
  return content if L::Schema.formatted?(content)
  { role: :user, content: content, _image: image }.compact
end