Skip to content

Commit

Permalink
Fixed issue where options was incorrectly added into multipart fields
Browse files Browse the repository at this point in the history
  • Loading branch information
wkok committed Nov 4, 2023
1 parent 4b3bf17 commit 4ac64cf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
13 changes: 7 additions & 6 deletions src/wkok/openai_clojure/openai.clj
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@
(def multipart-form-data
{:name ::multipart-form-data
:enter (fn [{:keys [handler params] :as ctx}]
(if (multipart-form-data? handler)
(-> (assoc-in ctx [:request :multipart]
(map param->multipart-entry params))
(update-in [:request :headers] dissoc "Content-Type")
(update :request dissoc :body))
ctx))})
(let [params' (dissoc params :wkok.openai-clojure.core/options)]
(if (multipart-form-data? handler)
(-> (assoc-in ctx [:request :multipart]
(map param->multipart-entry params'))
(update-in [:request :headers] dissoc "Content-Type")
(update :request dissoc :body))
ctx)))})

(defn update-file-schema
[m operation-id field-name]
Expand Down
8 changes: 6 additions & 2 deletions test/wkok/openai_clojure/openai_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
:mask (io/file "path/to/mask.png")
:prompt "A cute baby sea otter wearing a beret"
:n 2
:size "1024x1024"})]
:size "1024x1024"
:wkok.openai-clojure.core/options {:api-key "123"}})]

(testing "contains Authorization header"
(is (contains? (:headers request) "Authorization")))
Expand All @@ -30,7 +31,10 @@
(testing "multipart prompt set correctly"
(let [prompt (find-multipart request "prompt")]
(is (= "A cute baby sea otter wearing a beret"
(:content prompt))))))))
(:content prompt)))))

(testing "options not set in multipart fields"
(is (nil? (find-multipart request "options")))))))

(deftest add-headers-init
(let [add-headers-fn (-> openai/add-headers :enter)]
Expand Down

0 comments on commit 4ac64cf

Please sign in to comment.