Skip to content

Conversation

Haegin
Copy link
Contributor

@Haegin Haegin commented Nov 8, 2023

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?
    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.
  • Have you added an explanation of what your changes do and why you'd like us to include them?
    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 add pry-byebug as an upgrade to byebug 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.


def beta(apis)
dup.tap do |client|
client.send(:add_headers, "OpenAI-Beta": apis.map { |k, v| "#{k}=#{v}" }.join(";"))
Copy link
Contributor

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.

Suggested change
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(";")

Copy link
Contributor Author

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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️ this beta flag!

@alexrudall
Copy link
Owner

@Haegin thanks for your work here! If you address the above comments I'll look to release this ASAP

@Haegin Haegin force-pushed the assistant-support branch from e979475 to a3dd050 Compare November 9, 2023 13:57
Comment on lines 1 to 2
require "byebug"

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Gone!

Copy link
Contributor Author

@Haegin Haegin left a 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.


def beta(apis)
dup.tap do |client|
client.send(:add_headers, "OpenAI-Beta": apis.map { |k, v| "#{k}=#{v}" }.join(";"))
Copy link
Contributor Author

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.

@jbeker
Copy link

jbeker commented Nov 9, 2023

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.

@codenamev
Copy link
Contributor

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

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

Copy link
Contributor Author

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)

Copy link

@jcarrpries jcarrpries left a 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

@jcarrpries
Copy link

Can we get a final approval and merge on this @alexrudall Looking to add this support into my project asap.

@swistaczek
Copy link

@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!

@alexrudall alexrudall merged commit e2817f0 into alexrudall:main Nov 14, 2023
@alexrudall
Copy link
Owner

Big thanks all - released in v6.1

@dandailey
Copy link

Excited to use this! Any docs/info on how?

@alexrudall
Copy link
Owner

@dandailey PRs welcome on adding these endpoints to the README :D #376

@alexrudall
Copy link
Owner

@dandailey basically you make an assistant like this and then run it like this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants