Content retrieval (and anything calling .get) only works for JSON
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:
- Have the API generate a file for you
- Call
client.files.content(id: file_id) - 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
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
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
@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}"}
)