Giter VIP home page Giter VIP logo

Comments (7)

jxnl avatar jxnl commented on June 17, 2024 1

For sure! Are you on Twitter dm me @jxnlco

from ruby-openai.

kaiwren avatar kaiwren commented on June 17, 2024

Somewhat tangentially - I personally tend to favour encapsulating the API call inside a factory method on a PORO domain class that then builds an instance from the response. I then use ActiveModel::Validations for validations on that instance. Something like:

user = User.extract_from('Jason is 25 years old')
if user.valid?
  puts user.name, user.age
else
  puts user.errors.full_messages.join("\n") user.valid?
end

from ruby-openai.

jxnl avatar jxnl commented on June 17, 2024

Somewhat tangentially - I personally tend to favour encapsulating the API call inside a factory method on a PORO domain class that then builds an instance from the response. I then use ActiveModel::Validations for validations on that instance. Something like:

user = User.extract_from('Jason is 25 years old')
if user.valid?
  puts user.name, user.age
else
  puts user.errors.full_messages.join("\n") user.valid?
end

ok, you should check out marvin i think they have the cleanest version of that.

I think its importnat to give the users constrol of the whole messages array.

from ruby-openai.

sergiobayona avatar sergiobayona commented on June 17, 2024

@jxnl seems like ruby-openai would be able to support it with some patching. Although I wouldn't use dry-validation. I would use ActiveModel.

Something else to consider is that these libs don't output json schema so that'd need to be added... I think.

btw fantastic work you're doing with Instructor. I'm following closely. Here's how it might look like in Ruby:

class UserDetail
  include ActiveModel::Attributes

  attribute :name, :string
  attribute :age, :integer
end

client = OpenAI::Client.new

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

RSpec.describe "Attribute Assignment" do
  it "assigns a value to an attribute" do
    expect(user).to be_instance_of(UserDetail)
    expect(user.name).to eq("Jason")
    expect(user.age).to eq(25)
  end
end

from ruby-openai.

jxnl avatar jxnl commented on June 17, 2024

I think that would be awesome. good go everyone.

@jxnl seems like ruby-openai would be able to support it with some patching. Although I wouldn't use dry-validation. I would use ActiveModel.

Something else to consider is that these libs don't output json schema so that'd need to be added... I think.

btw fantastic work you're doing with Instructor. I'm following closely. Here's how it might look like in Ruby:

class UserDetail
  include ActiveModel::Attributes

  attribute :name, :string
  attribute :age, :integer
end

client = OpenAI::Client.new

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

RSpec.describe "Attribute Assignment" do
  it "assigns a value to an attribute" do
    expect(user).to be_instance_of(UserDetail)
    expect(user.name).to eq("Jason")
    expect(user.age).to eq(25)
  end
end

That would be awesome. I'm not much of a Ruby developer, but I think it could benefit a lot of folks. We've had a lot of progress on the JavaScript side.

from ruby-openai.

sergiobayona avatar sergiobayona commented on June 17, 2024

@jxnl I'd like to take a stab at a solution for Ruby for the problem you are solving with Instructor. Would you be interested in collaborating?

from ruby-openai.

sergiobayona avatar sergiobayona commented on June 17, 2024

I think this issue can be closed since instructor-rb solves it. cc @alexrudall

from ruby-openai.

Related Issues (20)

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.