Skip to content

Fix for Faraday::ParsingError when retrieving the content of a file from OpenAI #593

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

MarhicJeromeGIT
Copy link

@MarhicJeromeGIT MarhicJeromeGIT commented May 15, 2025

All Submissions:

Fix for Faraday::ParsingError when retrieving the content of a file from OpenAI.

Steps to reproduce (batch mode in openai, trying to retrieve the results after submitting a batch)

client = OpenAI::Client.new(access_token: ENV['OPENAI_API_KEY'])
output_file_id = "file-K1YqCx8oVZ1Fv3hPPWq23K" # Replace with your actual file ID containing JSONL rows
output_response = client.files.content(id: output_file_id)

On 8.1.0 main we get an error:

=> Faraday::ParsingError parsing Error
JSON::Ext::Parser#parse': unexpected token at

(this is because faraday_middleware tries to parse the response content as JSON - it might be a Faraday 1.x problem only ?)

Note: I believe this comment refers to the same issue : #544 (comment)

  • 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?
  • Have you added an explanation of what your changes do and why you'd like us to include them?

@MarhicJeromeGIT MarhicJeromeGIT changed the title Fix/file content json Fix for Faraday::ParsingError when retrieving the content of a file from OpenAI May 15, 2025
@MarhicJeromeGIT MarhicJeromeGIT mentioned this pull request May 15, 2025
3 tasks
@MarhicJeromeGIT MarhicJeromeGIT marked this pull request as ready for review May 15, 2025 01:14
parse_json(conn.get(uri(path: path), parameters) do |req|
req.headers = headers.merge({ "Accept" => "application/octet-stream" })
end&.body)
end
Copy link
Author

Choose a reason for hiding this comment

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

alternatively pass a "headers" parameter to #get above ?

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.

1 participant