alexrudall / ruby-openai

OpenAI API + Ruby! 🤖❤️
MIT License
2.75k stars 323 forks source link

404 Error from Azure API from version `7.3.0` #531

Closed ymtdzzz closed 3 hours ago

ymtdzzz commented 4 hours ago

Describe the bug From the version 7.3.0, Faraday::ResourceNotFound: the server responded with status 404 occurs when calling #embeddings method to send a request to Azure.

To Reproduce Steps to reproduce the behavior:

  1. Configure to use Azure OpenAI
OpenAI.configure do |config|
  config.access_token = ENV.fetch("AZURE_OPENAI_API_ACCESS_TOKEN", "")
  config.uri_base = ENV.fetch("AZURE_OPENAI_API_URI_BASE", "")
  config.api_type = :azure
  config.api_version = ENV.fetch("AZURE_OPENAI_API_VERSION", "")
  config.request_timeout = 60
end
  1. Call #embeddings
> client = OpenAI::Client.new
> client.embeddings(parameters: {model: "text-embedding-3-small", input: "test-input"})
  1. See error
Faraday::ResourceNotFound: the server responded with status 404
from /Users/your-name/.asdf/installs/ruby/3.2.5/lib/ruby/gems/3.2.0/gems/faraday-1.10.4/lib/faraday/response/raise_error.rb:22:in `on_complete'

I have confirmed that it works on the version 7.2.0

Expected behavior No errors occurred

Screenshots N/A

Desktop :

Possible solution Maybe the following change might be the cause:

https://github.com/alexrudall/ruby-openai/pull/527

https://github.com/alexrudall/ruby-openai/blob/a5714d340c254b810abff11d8fdc2e49d703fa14/lib/openai/http.rb#L21-L26

https://github.com/alexrudall/ruby-openai/blob/a5714d340c254b810abff11d8fdc2e49d703fa14/lib/openai/http.rb#L88-L91

If we use Azure, req.params already has the api_key param. So should we merge query_params instead of overwriting ?

alexrudall commented 3 hours ago

Hi @ymtdzzz, thank you for the clearly specified issue and apologies for any inconvenience. Would you be able to test if #532 does indeed fix the issue? Thank you.

ymtdzzz commented 3 hours ago

@alexrudall , thanks for your rapid response!

532 seems to fix this issue :+1:

[3] pry(main)> OpenAI::VERSION
=> "7.3.1"
[4] pry(main)> response = client.embeddings(parameters: {model: "text-embedding-3-small", input: "test-input"})
[5] pry(main)> response.dig("data", 0, "embedding").length
=> 1536
alexrudall commented 3 hours ago

@alexrudall , thanks for your rapid response! #532 seems to fix this issue 👍

[3] pry(main)> OpenAI::VERSION
=> "7.3.1"
[4] pry(main)> response = client.embeddings(parameters: {model: "text-embedding-3-small", input: "test-input"})
[5] pry(main)> response.dig("data", 0, "embedding").length
=> 1536

Thank you @ymtdzzz, v7.3.1 is now released and contains the fix.

ymtdzzz commented 3 hours ago

Thanks! This issue is fixed so I close it.