alexrudall / ruby-openai

OpenAI API + Ruby! 🤖❤️ NEW: Assistant Vector Stores
MIT License
2.61k stars 302 forks source link

client.files.content(id: "file-123") failing for image_files because of JSON parse #450

Closed Lasvad closed 2 weeks ago

Lasvad commented 2 months ago

Describe the bug Reading files such as pngs that are generated by code interpreter seem to fail as the response is expected to be JSON

Doc reference this to read file content: client.files.content(id: "file-123")

example

Code interpreter returns...

"content"=>
  [{"type"=>"image_file", "image_file"=>{"file_id"=>"file-stub"}},
   {"type"=>"text",
    "text"=>
     {"value"=>

using the cmd

client.files.content(id: "file-stub")

returns

(JSON::ParserError)s/ruby-3.2.2/lib/ruby/3.2.0/json/common.rb:216:in `parse': unexpected token at '\x89PNG

I've tried to use File.write, TempFile, StringIO but the JSON parse error continues.

To Reproduce Steps to reproduce the behavior:

  1. Use Assistant to create a png with code interpreter
  2. Try to read the file_id that is provided in the response
  3. Error shows when using client.files.content(id: "file-123")

Expected behavior Need a way to parse image_files files from OpenAI

Screenshots

image

Desktop (please complete the following information):

Additional context ruby 3.2.2 Rails 7.0.4.3

DanL12186 commented 1 month ago

Duplicate of this issue

alexrudall commented 2 weeks ago

Closing for #421