Skip to content

Commit a1f6086

Browse files
authored
feat(vector-stores): add vector stores APIs (#324)
1 parent e166fd3 commit a1f6086

File tree

20 files changed

+850
-3
lines changed

20 files changed

+850
-3
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ jobs:
6767
test: "*.TestRuns"
6868
- name: Threads
6969
test: "*.TestThreads"
70+
- name: Vector Stores
71+
test: "*.TestVectorStores"
7072
- name: Misc.
7173
test: "*.misc.*"
7274
steps:

openai-client/src/commonMain/kotlin/com.aallam.openai.client/OpenAI.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import kotlin.time.Duration.Companion.seconds
1111
* OpenAI API.
1212
*/
1313
public interface OpenAI : Completions, Files, Edits, Embeddings, Models, Moderations, FineTunes, Images, Chat, Audio,
14-
FineTuning, Assistants, Threads, Runs, Messages, Closeable
14+
FineTuning, Assistants, Threads, Runs, Messages, VectorStores, Closeable
1515

1616
/**
1717
* Creates an instance of [OpenAI].
Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
package com.aallam.openai.client
2+
3+
import com.aallam.openai.api.BetaOpenAI
4+
import com.aallam.openai.api.core.RequestOptions
5+
import com.aallam.openai.api.core.SortOrder
6+
import com.aallam.openai.api.core.Status
7+
import com.aallam.openai.api.file.FileId
8+
import com.aallam.openai.api.vectorstore.*
9+
10+
/**
11+
* Vector stores are used to store files for use by the file_search tool.
12+
*/
13+
public interface VectorStores {
14+
15+
/**
16+
* Create a new vector store.
17+
*
18+
* @param request The request to create a vector store.
19+
* @param requestOptions request options.
20+
*/
21+
@BetaOpenAI
22+
public suspend fun createVectorStore(
23+
request: VectorStoreRequest? = null,
24+
requestOptions: RequestOptions? = null,
25+
): VectorStore
26+
27+
/**
28+
* List all vector stores.
29+
*
30+
* @param limit A limit on the number of objects to be returned. The Limit can range between 1 and 100, and the default is 20.
31+
* @param order Sort order by the created_at timestamp of the objects.
32+
* @param after A cursor for use in pagination. After is an object ID that defines your place in the list.
33+
* For instance, if you make a list request and receive 100 objects, ending with obj_foo, your later call can
34+
* include after=obj_foo to fetch the next page of the list.
35+
* @param before A cursor for use in pagination. Before is an object ID that defines your place in the list.
36+
* For instance, if you make a list request and receive 100 objects, ending with "obj_foo", your later call can
37+
* include before = "obj_foo" to fetch the previous page of the list.
38+
* @param requestOptions request options.
39+
*/
40+
@BetaOpenAI
41+
public suspend fun vectorStores(
42+
limit: Int? = null,
43+
order: SortOrder? = null,
44+
after: VectorStoreId? = null,
45+
before: VectorStoreId? = null,
46+
requestOptions: RequestOptions? = null,
47+
): List<VectorStore>
48+
49+
/**
50+
* Retrieve a vector store.
51+
*
52+
* @param id The ID of the vector store to retrieve.
53+
* @param requestOptions request options.
54+
*/
55+
@BetaOpenAI
56+
public suspend fun vectorStore(id: VectorStoreId, requestOptions: RequestOptions? = null): VectorStore?
57+
58+
59+
/**
60+
* Update a vector store.
61+
*
62+
* @param id The ID of the vector store to update.
63+
* @param request The request to update a vector store.
64+
* @param requestOptions request options.
65+
*/
66+
@BetaOpenAI
67+
public suspend fun updateVectorStore(
68+
id: VectorStoreId,
69+
request: VectorStoreRequest,
70+
requestOptions: RequestOptions? = null
71+
): VectorStore
72+
73+
/**
74+
* Delete a vector store.
75+
*
76+
* @param id The ID of the vector store to delete.
77+
* @param requestOptions request options.
78+
*/
79+
@BetaOpenAI
80+
public suspend fun delete(id: VectorStoreId, requestOptions: RequestOptions? = null): Boolean
81+
82+
/**
83+
* Create a vector store file by attaching a File to a vector store.
84+
*
85+
* @param id The ID of the vector store that the file should be attached to.
86+
* @param request The request to create a vector store file.
87+
* @param requestOptions request options.
88+
*/
89+
@BetaOpenAI
90+
public suspend fun createVectorStoreFile(
91+
id: VectorStoreId,
92+
request: VectorStoreFileRequest,
93+
requestOptions: RequestOptions? = null,
94+
): VectorStoreFile
95+
96+
/**
97+
* Returns a list of vector store files.
98+
*
99+
* @param id The ID of the vector store that the files belong to.
100+
* @param limit A limit on the number of objects to be returned. The Limit can range between 1 and 100, and the
101+
* default is 20.
102+
* @param order Sort order by the created_at timestamp of the objects.
103+
* @param after A cursor for use in pagination. After is an object ID that defines your place in the list.
104+
* For instance, if you make a list request and receive 100 objects, ending with obj_foo, your later call can
105+
* include after=obj_foo to fetch the next page of the list.
106+
* @param before A cursor for use in pagination. Before is an object ID that defines your place in the list.
107+
* For instance, if you make a list request and receive 100 objects, ending with obj_foo, your later call can
108+
* include before=obj_foo to fetch the previous page of the list.
109+
* @param filter Filter by file status. One of [Status.InProgress], [Status.Completed], [Status.Failed],
110+
* [Status.Cancelled].
111+
* @param requestOptions request options.
112+
*/
113+
@BetaOpenAI
114+
public suspend fun vectorStoreFiles(
115+
id: VectorStoreId,
116+
limit: Int? = null,
117+
order: SortOrder? = null,
118+
after: VectorStoreId? = null,
119+
before: VectorStoreId? = null,
120+
filter: Status? = null,
121+
requestOptions: RequestOptions? = null,
122+
): List<VectorStoreFile>
123+
124+
/**
125+
* Delete a vector store file.
126+
* This will remove the file from the vector store, but the file itself will not be deleted.
127+
* To delete the file, `OpenAI.delete(fileId)`.
128+
*
129+
* @param id The ID of the vector store that the file belongs to.
130+
* @param fileId The ID of the file to delete.
131+
* @param requestOptions request options.
132+
*/
133+
@BetaOpenAI
134+
public suspend fun delete(id: VectorStoreId, fileId: FileId, requestOptions: RequestOptions? = null): Boolean
135+
136+
/**
137+
* Create a batch of vector store files.
138+
*
139+
* @param id The ID of the vector store for which to create a File Batch.
140+
* @param request The request to create a vector store files batch.
141+
* @param requestOptions request options.
142+
*/
143+
@BetaOpenAI
144+
public suspend fun createVectorStoreFilesBatch(
145+
id: VectorStoreId,
146+
request: FileBatchRequest,
147+
requestOptions: RequestOptions? = null,
148+
): FilesBatch
149+
150+
/**
151+
* Retrieves a vector store file batch.
152+
*
153+
* @param vectorStoreId The ID of the vector store file batch to retrieve.
154+
* @param batchId The ID of the vector store file batch to retrieve.
155+
* @param requestOptions request options.
156+
*/
157+
@BetaOpenAI
158+
public suspend fun vectorStoreFileBatch(
159+
vectorStoreId: VectorStoreId,
160+
batchId: BatchId,
161+
requestOptions: RequestOptions? = null,
162+
): FilesBatch?
163+
164+
/**
165+
* Cancel a vector store file batch.
166+
* This attempts to cancel the processing of files in this batch as soon as possible.
167+
*
168+
* @param vectorStoreId The ID of the vector store file batch to cancel.
169+
* @param batchId The ID of the vector store file batch to cancel.
170+
* @param requestOptions request options.
171+
*/
172+
@BetaOpenAI
173+
public suspend fun cancel(
174+
vectorStoreId: VectorStoreId,
175+
batchId: BatchId,
176+
requestOptions: RequestOptions? = null,
177+
): FilesBatch?
178+
179+
/**
180+
* Returns a list of vector store files in a batch.
181+
*
182+
* @param id The ID of the vector store that the files belong to.
183+
* @param limit A limit on the number of objects to be returned. The Limit can range between 1 and 100, and the
184+
* default is 20.
185+
* @param order Sort order by the created_at timestamp of the objects.
186+
* @param after A cursor for use in pagination. After is an object ID that defines your place in the list.
187+
* For instance, if you make a list request and receive 100 objects, ending with obj_foo, your later call can
188+
* include after=obj_foo to fetch the next page of the list.
189+
* @param before A cursor for use in pagination. Before is an object ID that defines your place in the list.
190+
* For instance, if you make a list request and receive 100 objects, ending with obj_foo, your later call can
191+
* include before=obj_foo to fetch the previous page of the list.
192+
* @param filter Filter by file status. One of [Status.InProgress], [Status.Completed], [Status.Failed],
193+
* [Status.Cancelled].
194+
* @param requestOptions request options.
195+
*/
196+
@BetaOpenAI
197+
public suspend fun vectorStoreFilesBatches(
198+
vectorStoreId: VectorStoreId,
199+
batchId: BatchId,
200+
limit: Int? = null,
201+
order: SortOrder? = null,
202+
after: VectorStoreId? = null,
203+
before: VectorStoreId? = null,
204+
filter: Status? = null,
205+
requestOptions: RequestOptions? = null,
206+
): List<VectorStoreFile>
207+
}

openai-client/src/commonMain/kotlin/com.aallam.openai.client/internal/OpenAIApi.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ internal class OpenAIApi(
2727
Threads by ThreadsApi(requester),
2828
Runs by RunsApi(requester),
2929
Messages by MessagesApi(requester),
30+
VectorStores by VectorStoresApi(requester),
3031
Closeable by requester

openai-client/src/commonMain/kotlin/com.aallam.openai.client/internal/api/ApiPath.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ internal object ApiPath {
2121
const val FineTuningJobs = "fine_tuning/jobs"
2222
const val Assistants = "assistants"
2323
const val Threads = "threads"
24+
const val VectorStores = "vector_stores"
2425
}

0 commit comments

Comments
 (0)