0.01
The project is in a healthy, maintained state
Explore the power of LLM structured extraction in Ruby with the Instructor gem.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 3.10
~> 13.1
~> 3.0
~> 1.21
~> 6.0
~> 3.13

Runtime

 Project Readme

instructor-rb

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


Twitter Follow Documentation GitHub issues Discord

Dive into the world of Ruby-based structured extraction, by OpenAI's function calling API and ActiveRecord, ruby-first schema validation with type inference. 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.

ℹī¸ Tip: Support in other languages

Check out ports to other languages below:

- [Python](https://www.github.com/jxnl/instructor)
- [TS/JS](https://github.com/instructor-ai/instructor-js/)
- [Ruby](https://github.com/instructor-ai/instructor-rb)
- [Elixir](https://github.com/thmsmlr/instructor_ex/)

If you want to port Instructor to another language, please reach out to us on [Twitter](https://twitter.com/jxnlco) we'd love to help you get started!

Usage

export your OpenAI API key:

export OPENAI_API_KEY=sk-...

Then use Instructor to extract structured data from text in Ruby:

require 'instructor'

class UserDetail
  include EasyTalk::Model

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

client = Instructor.patch(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?

  1. OpenAI Integration — Integrates seamlessly with OpenAI's API, facilitating efficient data management and manipulation.

  2. Customizable — It offers significant flexibility. Users can tailor validation, and express complex relationships between models.

More Examples

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

Installing Instructor is a breeze.

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.

Checkout the contribution guide for details on how to set things up, testing, changesets and guidelines.

License

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

TODO

  • Add patch
    • Mode.FUNCTIONS
    • Mode.TOOLS
    • Mode.MD_JSON
    • Mode.JSON
  • Add response_model
  • Support async
  • Support stream=True, Partial[T] and iterable[T]
  • Support Streaming
  • Optional/Maybe types
  • Add Tutorials, include in docs
    • Text Classification
    • Search Queries
    • Query Decomposition
    • Citations
    • Knowledge Graph
    • Self Critique
    • Image Extracting Tables
    • Moderation
    • Entity Resolution
    • Action Item and Dependency Mapping
  • Logging for Distillation / Finetuning
  • Add llm_validator