Module: L::Schema

Included in:
L
Defined in:
lib/lammy/schema.rb

Instance Method Summary collapse

Instance Method Details

#assistant(content) ⇒ Object



13
14
15
# File 'lib/lammy/schema.rb', line 13

def assistant(content)
  { role: :assistant, content: content }
end

#system(content) ⇒ Object



5
6
7
# File 'lib/lammy/schema.rb', line 5

def system(content)
  { role: :system, content: content }
end

#to_a(object) ⇒ Object

Structured Outputs is a feature that ensures the model will always generate responses that adhere to your supplied JSON Schema, so you don’t need to worry about the model omitting a required key, or hallucinating an invalid enum value. This is a set of helper methods to help you define your JSON Schema easily.



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/lammy/schema.rb', line 21

def to_a(object)
  {
    'type' => 'object',
    'properties' => {
      'items' => {
        'type' => 'array', 'items' => to_h(object)
      }
    },
    'required' => ['items'],
    'additionalProperties' => false
  }
end

#to_h(object) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/lammy/schema.rb', line 34

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

#user(content) ⇒ Object



9
10
11
# File 'lib/lammy/schema.rb', line 9

def user(content)
  { role: :user, content: content }
end