Comments (7)
For sure! Are you on Twitter dm me @jxnlco
from ruby-openai.
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.
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.
@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.
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.
@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.
I think this issue can be closed since instructor-rb solves it. cc @alexrudall
from ruby-openai.
Related Issues (20)
- function calls documentation -> functions are "deprecated" and replaced by tools HOT 1
- Assistants Support for Azure's new API version 2024-02-15-preview HOT 1
- Raise a clear error if someone has required 2 gems called 'openai'
- Configure maximum length HOT 5
- Ability to suppress stdout error logging HOT 1
- Get response headers HOT 2
- {} is not of type 'boolean' - 'stream' HOT 1
- I am stuck getting response from GPT into a thread. HOT 2
- How can I add a custom tool (a function) to an assistant? HOT 3
- Include an image in a message into a thread HOT 2
- Enhance flexibility by supporting deployment_id for Azure OpenAI model switching
- client.files.content(id: "file-123") failing for image_files because of JSON parse HOT 2
- Faraday::Error: :json is not registered on Faraday::Response HOT 1
- Documentation does not include tool choice option HOT 1
- Support for Assistants v2 HOT 3
- Add Assistant#tool_resources example to README HOT 1
- Add the Vector Store, Vector Store Files and Vector Store Batch Files APIs HOT 8
- ActiveSupport::Notifications
- OpenAI error payloads in the body may not get parsed fully during chat streaming
- batches.list is missing after/limit query parameters support + README inaccuracy regarding batches
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ruby-openai.