Skip to content

instructor-rb

Structured extraction in Ruby, powered by llms, designed for simplicity, transparency, and control.


Twitter Follow Twitter Follow Documentation GitHub issues Discord

Dive into the world of Ruby-based structured extraction, by OpenAI's function calling API, Ruby schema validation with type hinting. Instructor stands out for its simplicity, transparency, and user-centric design. Whether you're a seasoned developer or just starting out, you'll find Instructor's approach intuitive and steerable.

Check us out in Python, Elixir, PHP and Ruby.

If you want to port Instructor to another language, please reach out to us on Twitter we'd love to help you get started!

Usage

To check out all the tips and tricks to prompt and extract data, check out the documentation.

Installation is as simple as:

gem install intructor-rb
require 'instructor-rb'

OpenAI.configure do |config|
    config.access_token = ENV.fetch("OPENAI_ACCESS_TOKEN")
    config.organization_id = ENV.fetch("OPENAI_ORGANIZATION_ID") # Optional.
end

class UserDetail
  include EasyTalk::Model

  define_schema do
    property :name, String
    property :age, Integer
  end
end

client = Instructor.from_openai(OpenAI::Client).new

user = client.chat(
parameters: {
    model: 'gpt-3.5-turbo',
    messages: [{ role: 'user', content: 'Extract Jason is 25 years old' }]
},
response_model: UserDetail
)

user.name
# => "Jason"
user.age
# => 25

Why use Instructor?

The question of using Instructor is fundamentally a question of why to use zod.

  1. Powered by OpenAI — Instructor is powered by OpenAI's function calling API. This means you can use the same API for both prompting and extraction.

  2. Ruby Schema Validation — Instructor uses Ruby schema validation with type hinting. This means you can validate your data before using it.

More Examples

If you'd like to see more check out our cookbook.

Contributing

If you want to help out, checkout some of the issues marked as good-first-issue or help-wanted. Found here. They could be anything from code improvements, a guest blog post, or a new cook book.

License

This project is licensed under the terms of the MIT License.