-
-
Notifications
You must be signed in to change notification settings - Fork 350
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
When json_post is executed, is JSON.parse not executed on the response? #416
Comments
I ran into this error too. In lieu for there being a solution, I came up with this monkey patch: # workaround for https://github.com/alexrudall/ruby-openai/issues/416
if Rails.env.test?
module OpenAIClientExtensions
def chat(**kwargs)
rez = super
JSON.parse(rez)
end
end
module OpenAI
class Client
prepend OpenAIClientExtensions
end
end
end |
I found this issue when I was searching for a solution to the same problem. It's been a minute; and, I don't know if y'all are still having it; but, I found the solution. Set the request's content type: stub_request(:post, "https://api.openai.com/v1/chat/completions")
.to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" }) This'll get Faraday to parse the response correctly, 🚀. |
Ah, thanks for that! |
I believe #566 resolves this issue - if you are able to could you give it a test @gjtorikian, @jstewmc, @tonegawa07 ? Thank you! |
I noticed that in the recent commit (dc4d1c6) on https://github.com/alexrudall/ruby-openai, the processing for JSON.parse within the json_post method seems to have been removed. Could you please clarify the reason behind this change?
dc4d1c6
After creating a stub with WebMock as shown below, I encountered an error during the execution of dig('choices', 0, 'message', 'content') due to the absence of JSON.parse being executed.
It seems like the removal of JSON.parse from json_post might be the cause of this issue. What are your thoughts on this?
The text was updated successfully, but these errors were encountered: