-
-
Notifications
You must be signed in to change notification settings - Fork 370
Support for Assistants, Threads, Messages and Runs #361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This is done by setting the OpenAI-Beta header on the client.
lib/openai/client.rb
Outdated
|
||
def beta(apis) | ||
dup.tap do |client| | ||
client.send(:add_headers, "OpenAI-Beta": apis.map { |k, v| "#{k}=#{v}" }.join(";")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add_headers
is a public method. Prefer calling it explicitly.
client.send(:add_headers, "OpenAI-Beta": apis.map { |k, v| "#{k}=#{v}" }.join(";")) | |
client.add_headers "OpenAI-Beta": apis.map { |k, v| "#{k}=#{v}" }.join(";") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I didn't actually intend to make the other header methods public so I've changed the others back to private.
module OpenAI | ||
class Threads | ||
def initialize(client:) | ||
@client = client.beta(assistants: "v1") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️ this beta flag!
@Haegin thanks for your work here! If you address the above comments I'll look to release this ASAP |
e979475
to
a3dd050
Compare
spec/openai/client/client_spec.rb
Outdated
require "byebug" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Gone!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback, I think I've addressed everything.
lib/openai/client.rb
Outdated
|
||
def beta(apis) | ||
dup.tap do |client| | ||
client.send(:add_headers, "OpenAI-Beta": apis.map { |k, v| "#{k}=#{v}" }.join(";")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I didn't actually intend to make the other header methods public so I've changed the others back to private.
I'm not sure if this should be addressed in this PR or another, but the code in file uploads that tries to validate the uploaded file as JSON prevents the ability to upload arbitrary files for use with Assistants. |
I've added Assistant File support in #356 |
def submit_tool_outputs(thread_id:, run_id:, parameters: {}) | ||
@client.json_post(path: "/threads/#{thread_id}/runs/#{run_id}/submit_tool_outputs", | ||
parameters: parameters) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps we can figure this out in follow-up since the API itself is in BETA and shouldn't introduce any breaking changes. But the API ref documents essentially "nested" a step model inside of the runs model: https://platform.openai.com/docs/api-reference/runs/getRunStep ....it looks like those APIs are not exposed here in this iteration of the runs.rb ...in order to build these Assistants end-to-end we will need to get the Step Objects incorporated. (https://platform.openai.com/docs/api-reference/runs/step-object) .... but I don't have a good solution, just an observation that OPENAI didn't isolate steps into it's own class of API's...they just appended more API functionality to their runs model. Generally the PR LGTM. maybe I can start a PR once this goes in? or If you've pretty much have this going already lmk & I can just wait for those next round of changes. great work...
Either way...the step objects are missing in this iteration? or maybe I'm just not seeing it. IMO this PR looks great and can be merged. In follow-up we need to add the step objects
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point - I've added support for them as a separate class.
client.run_steps.list(thread_id: thread_id, run_id: run_id)
client.run_steps.retrieve(thread_id: thread_id, run_id: run_id, id: step_id)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look good to me! Can't wait to use them
Can we get a final approval and merge on this @alexrudall Looking to add this support into my project asap. |
@alexrudall I also reviewed it on my end, and I think this looks great. Let us know when you think we can access this one upstream. Thank you! |
Big thanks all - released in v6.1 |
Excited to use this! Any docs/info on how? |
@dandailey PRs welcome on adding these endpoints to the README :D #376 |
@dandailey basically you make an assistant like this and then run it like this |
All Submissions:
There's a draft PR open for Assistants (Adds OpeAI::AssistantFiles #356), and that seems to include some useful stuff for files I haven't included, but it's missing threads, messages and runs.
This adds support for the new Assistant APIs, with messages, threads, and runs to allow users to build interactive assistants/chatbots.
I've tried to keep to project conventions, though did addpry-byebug
as an upgrade tobyebug
for easier debugging while I was working on the project. Happy to remove that if you'd prefer.pry-byebug
doesn't support Ruby 2.6 and while it's no longer supported, I don't want to force a major version bump for this change so I've removed it.