Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Content retrieval (and anything calling .get) only works for JSON #421

Open
DanL12186 opened this issue Jan 19, 2024 · 3 comments
Open

Content retrieval (and anything calling .get) only works for JSON #421

DanL12186 opened this issue Jan 19, 2024 · 3 comments

Comments

@DanL12186
Copy link

DanL12186 commented Jan 19, 2024

Describe the bug
Attempting to retrieve the content of files via the API doesn't work unless the files are in JSON format; you'll get a JSON::ParserError error, because get() in http.rb calls jsonparsel() which calls JSON.parse(response) for every request.

For example, when trying to retrieve an image so we can attach it via ActiveStorage in order to easily display it to the user:

>> client.files.content(id: "file-xyz123")
JSON::ParserError: 451: unexpected token at '?PNG

Simply returning the response if it's not JSON would resolve this.

To Reproduce
Steps to reproduce the behavior:

  1. Have the API generate a file for you
  2. Call client.files.content(id: file_id)
  3. See error

Expected behavior
It should retrieve non-JSON content like generated PNGs successfully

Desktop (please complete the following information):

  • OS: MacOS X 10.15.7
  • Browser N/A
  • Version N/A
@leoplct
Copy link

leoplct commented Mar 23, 2024

Same issue.
The API supports the parameter purpose="assistants" and accepts several formats.

UPLOAD FILE: https://platform.openai.com/docs/assistants/tools/passing-files-to-code-interpreter
Accepted formats: https://platform.openai.com/docs/assistants/tools/supported-files

Here the library code: https://github.com/alexrudall/ruby-openai/blob/main/lib/openai/files.rb

@thisismydesign
Copy link

Having the same issue trying to send files. No matter the type of file I'm trying to send it tries to JSON parse it.

        file = entity.attachment.download
        temp_file = Tempfile.new(['email', '.html'])
        temp_file.write(file)
        temp_file.rewind

client.files.upload(parameters: { file: temp_file, purpose: "assistants" })

JSON::ParserError: unexpected token

@DanL12186
Copy link
Author

@thisismydesign Figure you've worked this out, but in case you're having issues, you can easily work around it just by using a built-in or gem-based HTTP library to make a call to the files endpoint

RestClient.get(
  "https://api.openai.com/v1/files/#{file_id}/content",
  {Authorization: "Bearer #{ACCESS_TOKEN}"}
)

@gregszero gregszero mentioned this issue Oct 29, 2024
3 tasks
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants