From ca621cfb24af30c3a0b83c4a0379fe5b94a00290 Mon Sep 17 00:00:00 2001 From: Peter Denno Date: Tue, 5 Nov 2024 13:45:10 -0500 Subject: [PATCH] Added support for OpenAI Vector Stores(#75) --- src/wkok/openai_clojure/api.clj | 81 +++++++++++++++++++++++++++ test/wkok/openai_clojure/api_test.clj | 20 ++++++- 2 files changed, 100 insertions(+), 1 deletion(-) diff --git a/src/wkok/openai_clojure/api.clj b/src/wkok/openai_clojure/api.clj index 5075c81..c8ef487 100644 --- a/src/wkok/openai_clojure/api.clj +++ b/src/wkok/openai_clojure/api.clj @@ -865,3 +865,84 @@ ([params options] (let [opts (assoc-in options [:openai-beta] ASSISTANTS_HTTP_HEADER_STR)] (core/response-for :create-thread-and-run params opts)))) + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Vector stores (beta) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(defn create-vector-store + "Create a vector store. + + Example: + ``` + (create-vector-store {:name \"Support FAQ\" :file-ids [\"file-id-123\"]}) + ``` + + Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/vector-stores/create) + " + ([params] + (create-vector-store params nil)) + ([params options] + (let [opts (assoc-in options [:openai-beta] ASSISTANTS_HTTP_HEADER_STR)] + (core/response-for :create-vector-store params opts)))) + +(defn list-vector-stores + "Returns a list of vector stores. + + Example: + ``` + (list-vector-stores {:limit 1}) + ``` + Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/vector-stores/list) + " + ([params] + (list-vector-stores params nil)) + ([params options] + (let [opts (assoc-in options [:openai-beta] ASSISTANTS_HTTP_HEADER_STR)] + (core/response-for :list-vector-stores params opts)))) + +(defn retrieve-vector-store + "Retrieves a vector store. + + Example: + ``` + (retrieve-vector-store {:vector_store_id \"vs_abc123\"}) + ``` + Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/vector-stores/retrieve) + " + ([params] + (retrieve-vector-store params nil)) + ([params options] + (let [opts (assoc-in options [:openai-beta] ASSISTANTS_HTTP_HEADER_STR)] + (core/response-for :get-vector-store params opts)))) + +(defn modify-vector-store + "Modifies a vector store. + + Example: + ``` + (modify-vector-store {:vector_store_id \"vs_abc123\" :name \"Support FAQ\"}) + ``` + Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/vector-stores/modify) + " + ([params] + (modify-vector-store params nil)) + ([params options] + (let [opts (assoc-in options [:openai-beta] ASSISTANTS_HTTP_HEADER_STR)] + (core/response-for :modify-vector-store params opts)))) + +(defn delete-vector-store + "Deletes a vector store. + + Example: + ``` + (delete-vector-store {:vector_store_id \"vs_abc123\"}) + ``` + Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/vector-stores/delete) + " + ([params] + (delete-vector-store params nil)) + ([params options] + (let [opts (assoc-in options [:openai-beta] ASSISTANTS_HTTP_HEADER_STR)] + (core/response-for :delete-vector-store params opts)))) diff --git a/test/wkok/openai_clojure/api_test.clj b/test/wkok/openai_clojure/api_test.clj index bb9a8f8..39bc338 100644 --- a/test/wkok/openai_clojure/api_test.clj +++ b/test/wkok/openai_clojure/api_test.clj @@ -291,7 +291,25 @@ :step_id "----id----"}))) (is (= :success - (api/create-thread-and-run {:assistant_id "----id----"})))))) + (api/create-thread-and-run {:assistant_id "----id----"}))) + + (is (= :success + (api/create-vector-store {:name "Support FAQ" :file-ids ["----id----"]}))) + + (is (= :success + (api/list-vector-stores {:limit 1}))) + + (is (= :success + (api/retrieve-vector-store {:vector_store_id "----id----"}))) + + (is (= :success + (api/retrieve-vector-store {:vector_store_id "----id----"}))) + + (is (= :success + (api/modify-vector-store {:vector_store_id "----id----" :name "Support FAQ v2"}))) + + (is (= :success + (api/delete-vector-store {:vector_store_id "----id----"})))))) (deftest create-chat-completion-tools