Giter Club home page Giter Club logo

instructor-rb's Introduction

instructor-rb

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


Twitter Follow Twitter Follow Documentation GitHub issues Discord

Instructor-rb is a Ruby library that makes it a breeze to work with structured outputs from large language models (LLMs). Built on top of EasyTalk, it provides a simple, transparent, and user-friendly API to manage validation, retries, and streaming responses. Get ready to supercharge your LLM workflows!

Getting Started

  1. Install Instructor-rb at the command prompt if you haven't yet:

    $ gem install instructor-rb
  2. In your Ruby project, require the gem:

    require 'instructor'
  3. At the beginning of your script, initialize and patch the OpenAI client:

    client = Instructor.patch(OpenAI::Client)

Usage

export your OpenAI API key:

export OPENAI_API_KEY=sk-...

Then use Instructor by defining your schema in Ruby using the define_schema block and EasyTalk's schema definition syntax. Here's an example in:

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

ℹ️ 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!

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 processes and define unique error messages.

  3. Tested and Trusted — Its reliability is proven by extensive real-world application.

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

instructor-rb's People

Contributors

ellipsis-dev[bot] avatar jxnl avatar sergiobayona avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

sergiobayona

instructor-rb's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.