Skip to content

Commit ca621cf

Browse files
authored
Added support for OpenAI Vector Stores(#75)
1 parent ebbc57b commit ca621cf

File tree

2 files changed

+100
-1
lines changed

2 files changed

+100
-1
lines changed

src/wkok/openai_clojure/api.clj

+81
Original file line numberDiff line numberDiff line change
@@ -865,3 +865,84 @@
865865
([params options]
866866
(let [opts (assoc-in options [:openai-beta] ASSISTANTS_HTTP_HEADER_STR)]
867867
(core/response-for :create-thread-and-run params opts))))
868+
869+
870+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
871+
;; Vector stores (beta)
872+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
873+
874+
(defn create-vector-store
875+
"Create a vector store.
876+
877+
Example:
878+
```
879+
(create-vector-store {:name \"Support FAQ\" :file-ids [\"file-id-123\"]})
880+
```
881+
882+
Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/vector-stores/create)
883+
"
884+
([params]
885+
(create-vector-store params nil))
886+
([params options]
887+
(let [opts (assoc-in options [:openai-beta] ASSISTANTS_HTTP_HEADER_STR)]
888+
(core/response-for :create-vector-store params opts))))
889+
890+
(defn list-vector-stores
891+
"Returns a list of vector stores.
892+
893+
Example:
894+
```
895+
(list-vector-stores {:limit 1})
896+
```
897+
Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/vector-stores/list)
898+
"
899+
([params]
900+
(list-vector-stores params nil))
901+
([params options]
902+
(let [opts (assoc-in options [:openai-beta] ASSISTANTS_HTTP_HEADER_STR)]
903+
(core/response-for :list-vector-stores params opts))))
904+
905+
(defn retrieve-vector-store
906+
"Retrieves a vector store.
907+
908+
Example:
909+
```
910+
(retrieve-vector-store {:vector_store_id \"vs_abc123\"})
911+
```
912+
Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/vector-stores/retrieve)
913+
"
914+
([params]
915+
(retrieve-vector-store params nil))
916+
([params options]
917+
(let [opts (assoc-in options [:openai-beta] ASSISTANTS_HTTP_HEADER_STR)]
918+
(core/response-for :get-vector-store params opts))))
919+
920+
(defn modify-vector-store
921+
"Modifies a vector store.
922+
923+
Example:
924+
```
925+
(modify-vector-store {:vector_store_id \"vs_abc123\" :name \"Support FAQ\"})
926+
```
927+
Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/vector-stores/modify)
928+
"
929+
([params]
930+
(modify-vector-store params nil))
931+
([params options]
932+
(let [opts (assoc-in options [:openai-beta] ASSISTANTS_HTTP_HEADER_STR)]
933+
(core/response-for :modify-vector-store params opts))))
934+
935+
(defn delete-vector-store
936+
"Deletes a vector store.
937+
938+
Example:
939+
```
940+
(delete-vector-store {:vector_store_id \"vs_abc123\"})
941+
```
942+
Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/vector-stores/delete)
943+
"
944+
([params]
945+
(delete-vector-store params nil))
946+
([params options]
947+
(let [opts (assoc-in options [:openai-beta] ASSISTANTS_HTTP_HEADER_STR)]
948+
(core/response-for :delete-vector-store params opts))))

test/wkok/openai_clojure/api_test.clj

+19-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,25 @@
291291
:step_id "----id----"})))
292292

293293
(is (= :success
294-
(api/create-thread-and-run {:assistant_id "----id----"}))))))
294+
(api/create-thread-and-run {:assistant_id "----id----"})))
295+
296+
(is (= :success
297+
(api/create-vector-store {:name "Support FAQ" :file-ids ["----id----"]})))
298+
299+
(is (= :success
300+
(api/list-vector-stores {:limit 1})))
301+
302+
(is (= :success
303+
(api/retrieve-vector-store {:vector_store_id "----id----"})))
304+
305+
(is (= :success
306+
(api/retrieve-vector-store {:vector_store_id "----id----"})))
307+
308+
(is (= :success
309+
(api/modify-vector-store {:vector_store_id "----id----" :name "Support FAQ v2"})))
310+
311+
(is (= :success
312+
(api/delete-vector-store {:vector_store_id "----id----"}))))))
295313

296314
(deftest create-chat-completion-tools
297315

0 commit comments

Comments
 (0)