wkok / openai-clojure

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

Azure API deprecation #55

Closed chrisbetz closed 9 months ago

chrisbetz commented 9 months ago

As stated in https://learn.microsoft.com/en-us/azure/ai-services/openai/api-version-deprecation, MS will deprecate certain versions of the OpenAI inference API.

I was able to "patch" this for my use with a little hack, but you might want to update to

https://github.com/Azure/azure-rest-api-specs/blob/main/specification/cognitiveservices/data-plane/AzureOpenAI/inference/preview/2023-12-01-preview/inference.json

The hack (for others to use, with the inference file in your resources folder as AzureOpenAI/2023-12-01-preview.json) is

(ns azure.openai.patch)

(in-ns 'wkok.openai-clojure.azure)

(defn load-openai-spec []
  (json/decode (slurp (io/resource "AzureOpenAI/2023-12-01-preview.json")) keyword))

(def m
  (delay
    (patch-handler
      (martian/bootstrap-openapi "/openai"
                                 (load-openai-spec)
                                 (update
                                   martian-http/default-opts
                                   :interceptors
                                   #(-> (remove (comp #{martian-http/perform-request}) %)
                                        (concat [add-authentication-header
                                                 openai-interceptors/set-request-options
                                                 override-api-endpoint
                                                 sse/perform-sse-capable-request])))))))

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

and then requiring azure.openai.patch at the right point in your code ;)

wkok commented 9 months ago

Thanks! Updated to latest spec in https://github.com/wkok/openai-clojure/pull/56 if you'd like to confirm

chrisbetz commented 9 months ago

Yes, can confirm it's working. Thanks a lot.