wkok / openai-clojure

Clojure functions to drive the OpenAI API
https://cljdoc.org/d/net.clojars.wkok/openai-clojure
MIT License
202 stars 28 forks source link

Wrong API version on Azure endpoint? #68

Closed HanjoPurebuddha closed 1 month ago

HanjoPurebuddha commented 1 month ago

Hi when I request the API I get the following response:

:uri https://bali.openai.azure.com/openai/deployments/gpt-4-0613/chat/completions?api-version=2023-12-01-preview, :content-type-params {}, :version :http-1.1, :body {"error":{"code":"401","message":"Access denied due to invalid subscription key or wrong API endpoint. Make sure to provide a valid key for an active subscription and use a correct regional API endpoint for your resource."}}}
; Caught an exception during OpenAI API call: Interceptor Exception: status: 401

I compared the two strings and the only difference is the API version:

Used by the API: https://bali.openai.azure.com/openai/deployments/gpt-4-0613/chat/completions?api-version=2023-12-01-preview

Provided by azure: https://bali.openai.azure.com/openai/deployments/gpt-4-0613/chat/completions?api-version=2023-03-15-preview

What am I missing? Here's the code:

response (api/create-chat-completion
                          {:messages [{:role "user" :content dynamic-message}]
                           :temperature 0.8
                           :max_tokens 4096
                           :top_p 1
                           :model "gpt-4-0613"
                           :frequency_penalty 0.0
                           :presence_penalty 0.0}
                          {:impl :azure
                           :api-key api-key
                           :api-endpoint api-endpoint})
HanjoPurebuddha commented 1 month ago

I found where it is set in the code but I'm too new to know how to proceed :)

(azure.clj)

(defn patch-params [params]
  {:api-version "2023-12-01-preview"
   :deployment-id (:model params)
   :martian.core/body (dissoc params :model)})
wkok commented 1 month ago

Could you try with the latest v0.19.0 of this library by any chance? 

It's been set to use the latest stable release of Azure OpenAI - 2024-06-01 in the latest release of this library:

https://github.com/wkok/openai-clojure/blob/main/src%2Fwkok%2Fopenai_clojure%2Fazure.clj#L64

HanjoPurebuddha commented 1 month ago

Yes works perfectly thank you, I'm sorry I missed this! Appreciate the help 🙏