Skip to content

Support Complex Parameter Schemas #124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jayelkaake
Copy link

Summary

Adds the ability to define more complex param schemas, while retaining the existing simple methods.

This new format is also forward-compatible once LLMs start supporting more JSON schema structures (and at the pace they are moving that might not be too long from now).

Bumped version to 1.3 since this is kind of a major feature.

Examples

# Existing structure still works and now is called 'shorthand' syntax:
param :latitude, desc: "Latitude (e.g., 52.5200)"

# But now you can treat the params as plain schema definitions. It no longer uses object params EXCEPT for `required` key:
param :unit, type: :string, enum: %w[f c], description: "Unit (e.g., celsius, fahrenheit)", required: false

# It now supports object params
param :location, type: :object, desc: "Country and city.", required: false, properties: {
  country: { type: :string, description: "Full name of the country." },
  city: { type: :string, description: "Full name of the city." }
}

# And also supports array params:
param :location, type: :array, desc: "Latitude and longitude", items: { type: :number, description: "Float value" }

How I tested

I tested all the supported LLM APIs directly.

Shout-outs

Copy link
Contributor

@tpaulshippy tpaulshippy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well tested and documented. Compatible with my fork - appreciate it!

@kieranklaassen
Copy link
Contributor

Nice one! I like it. The only issue is I really need support for Gemini myself, so I cannot use this one yet in production. I'm happy to close mine or merge any elements. I'll let @crmne know what he wants. My goal is to use RubyLLM for all production tasks, and I need structured outputs for Claude, Gemini, and OpenAI. Using the prompt method works very well.

@jayelkaake
Copy link
Author

@kieranklaassen sounds great.

Yeah let's wait to hear from @crmne first then I can merge your code for Gemini support into my PR since that one is hardest to support if he decides to go that direction.

@tpaulshippy
Copy link
Contributor

Are you guys commenting on the wrong PR or is it just me?

@jayelkaake
Copy link
Author

@tpaulshippy not just you - comments went to wrong PR.

Those 2 comments should be on @kieranklaassen 's PR for structured output

…g the existing simple methods + bump version to 1.3 since this is kind of a major feature.
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.

3 participants