Skip to content

Conversation

@0x1eef
Copy link
Member

@0x1eef 0x1eef commented Nov 17, 2025

About

Add support for LLM::Schema subclasses

Example

schema.rb

##
# schema.rb
class Schema < LLM::Schema
  property :name, String, "The person's name", required: true
  property :age, Integer, "The person's age", required: true
  property :friends, Array[String,Integer], "The name or IDs of friends", optional: true
  # ...
end

main.rb

##
# main.rb
llm = LLM.openai(key: ENV["KEY"])
bot = LLM::Bot.new(llm, schema: Schema.object)
prompt = bot.build_prompt do
  it.system "The user's name is Robert, their age is 29 and their friends are 7 and Moses"
  it.user "Tell me about myself"
end
print bot.chat(prompt).content!, "\n"

Add support for LLM::Schema subclasses

```ruby
class Schema < LLM::Schema
  property :name, String, "The person's name", required: true
  property :age, Integer, "The person's age", required: true
  property :friends, Array[String,Integer], "The name or IDs of friends", optional: true
  # ...
end

llm = LLM.openai(key: ENV["KEY"])
bot = LLM::Bot.new(llm, schema: Schema.object)
prompt = bot.build_prompt do
  it.system "The user's name is Robert, their age is 29 and their friends are 7 and Moses"
  it.user "Tell me about myself"
end
bot.chat(prompt)
```
@0x1eef 0x1eef merged commit 3a300c7 into main Nov 17, 2025
3 checks passed
@0x1eef 0x1eef deleted the schema_as_class branch November 17, 2025 05:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants