From ca7b9813852a54aa9d0092d42047041dd0613bd9 Mon Sep 17 00:00:00 2001 From: Werner Kok Date: Fri, 24 Nov 2023 22:15:06 +0000 Subject: [PATCH] Fixed warning for no matching content type --- src/wkok/openai_clojure/interceptors.clj | 2 +- src/wkok/openai_clojure/openai.clj | 48 +++++++++++++++++------- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/wkok/openai_clojure/interceptors.clj b/src/wkok/openai_clojure/interceptors.clj index aa41aee..f06b850 100644 --- a/src/wkok/openai_clojure/interceptors.clj +++ b/src/wkok/openai_clojure/interceptors.clj @@ -1,7 +1,7 @@ (ns wkok.openai-clojure.interceptors) (def set-request-options - {:name ::method + {:name ::set-request-options :enter (fn [{{{request :request} :wkok.openai-clojure.core/options} :params :as ctx}] (update ctx :request merge request))}) diff --git a/src/wkok/openai_clojure/openai.clj b/src/wkok/openai_clojure/openai.clj index 41a3610..d50b26a 100644 --- a/src/wkok/openai_clojure/openai.clj +++ b/src/wkok/openai_clojure/openai.clj @@ -79,19 +79,41 @@ "Bootstrap the martian from a local copy of the openai swagger spec" [] (let [definition (yaml/yaml->edn (slurp (io/resource "openapi.yaml"))) - base-url (openapi/base-url nil nil definition) - encoders (assoc (encoders/default-encoders) - "multipart/form-data" nil) - opts (update martian-http/default-opts - :interceptors (fn [interceptors] - (-> (remove #(#{:martian.hato/perform-request} (:name %)) - interceptors) - (concat [add-headers - openai-interceptors/set-request-options - (override-api-endpoint base-url) - (interceptors/encode-body encoders) - multipart-form-data - sse/perform-sse-capable-request]))))] + base-url (openapi/base-url nil nil definition) + encoders (assoc (encoders/default-encoders) + "multipart/form-data" nil + "application/octet-stream" nil) + opts (update martian-http/default-opts + :interceptors (fn [interceptors] + (-> interceptors + (interceptors/inject + add-headers + :after + :martian.interceptors/header-params) + (interceptors/inject + multipart-form-data + :after + ::add-headers) + (interceptors/inject + openai-interceptors/set-request-options + :before + :martian.hato/perform-request) + (interceptors/inject + (override-api-endpoint base-url) + :before + :martian.hato/perform-request) + (interceptors/inject + sse/perform-sse-capable-request + :replace + :martian.hato/perform-request) + (interceptors/inject + (interceptors/encode-body encoders) + :replace + :martian.interceptors/encode-body) + (interceptors/inject + (interceptors/coerce-response encoders) + :replace + :martian.interceptors/coerce-response))))] (-> (martian/bootstrap-openapi base-url definition opts) update-file-schemas)))