main
1# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
3from __future__ import annotations
4
5import os
6from typing import Any, cast
7
8import pytest
9
10from openai import OpenAI, AsyncOpenAI
11from tests.utils import assert_matches_type
12from openai.pagination import SyncCursorPage, AsyncCursorPage
13from openai.types.vector_stores import (
14 VectorStoreFile,
15 VectorStoreFileBatch,
16)
17
18base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
19
20
21class TestFileBatches:
22 parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
23
24 @parametrize
25 def test_method_create(self, client: OpenAI) -> None:
26 file_batch = client.vector_stores.file_batches.create(
27 vector_store_id="vs_abc123",
28 )
29 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
30
31 @parametrize
32 def test_method_create_with_all_params(self, client: OpenAI) -> None:
33 file_batch = client.vector_stores.file_batches.create(
34 vector_store_id="vs_abc123",
35 attributes={"foo": "string"},
36 chunking_strategy={"type": "auto"},
37 file_ids=["string"],
38 files=[
39 {
40 "file_id": "file_id",
41 "attributes": {"foo": "string"},
42 "chunking_strategy": {"type": "auto"},
43 }
44 ],
45 )
46 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
47
48 @parametrize
49 def test_raw_response_create(self, client: OpenAI) -> None:
50 response = client.vector_stores.file_batches.with_raw_response.create(
51 vector_store_id="vs_abc123",
52 )
53
54 assert response.is_closed is True
55 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
56 file_batch = response.parse()
57 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
58
59 @parametrize
60 def test_streaming_response_create(self, client: OpenAI) -> None:
61 with client.vector_stores.file_batches.with_streaming_response.create(
62 vector_store_id="vs_abc123",
63 ) as response:
64 assert not response.is_closed
65 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
66
67 file_batch = response.parse()
68 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
69
70 assert cast(Any, response.is_closed) is True
71
72 @parametrize
73 def test_path_params_create(self, client: OpenAI) -> None:
74 with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"):
75 client.vector_stores.file_batches.with_raw_response.create(
76 vector_store_id="",
77 )
78
79 @parametrize
80 def test_method_retrieve(self, client: OpenAI) -> None:
81 file_batch = client.vector_stores.file_batches.retrieve(
82 batch_id="vsfb_abc123",
83 vector_store_id="vs_abc123",
84 )
85 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
86
87 @parametrize
88 def test_raw_response_retrieve(self, client: OpenAI) -> None:
89 response = client.vector_stores.file_batches.with_raw_response.retrieve(
90 batch_id="vsfb_abc123",
91 vector_store_id="vs_abc123",
92 )
93
94 assert response.is_closed is True
95 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
96 file_batch = response.parse()
97 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
98
99 @parametrize
100 def test_streaming_response_retrieve(self, client: OpenAI) -> None:
101 with client.vector_stores.file_batches.with_streaming_response.retrieve(
102 batch_id="vsfb_abc123",
103 vector_store_id="vs_abc123",
104 ) as response:
105 assert not response.is_closed
106 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
107
108 file_batch = response.parse()
109 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
110
111 assert cast(Any, response.is_closed) is True
112
113 @parametrize
114 def test_path_params_retrieve(self, client: OpenAI) -> None:
115 with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"):
116 client.vector_stores.file_batches.with_raw_response.retrieve(
117 batch_id="vsfb_abc123",
118 vector_store_id="",
119 )
120
121 with pytest.raises(ValueError, match=r"Expected a non-empty value for `batch_id` but received ''"):
122 client.vector_stores.file_batches.with_raw_response.retrieve(
123 batch_id="",
124 vector_store_id="vs_abc123",
125 )
126
127 @parametrize
128 def test_method_cancel(self, client: OpenAI) -> None:
129 file_batch = client.vector_stores.file_batches.cancel(
130 batch_id="batch_id",
131 vector_store_id="vector_store_id",
132 )
133 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
134
135 @parametrize
136 def test_raw_response_cancel(self, client: OpenAI) -> None:
137 response = client.vector_stores.file_batches.with_raw_response.cancel(
138 batch_id="batch_id",
139 vector_store_id="vector_store_id",
140 )
141
142 assert response.is_closed is True
143 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
144 file_batch = response.parse()
145 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
146
147 @parametrize
148 def test_streaming_response_cancel(self, client: OpenAI) -> None:
149 with client.vector_stores.file_batches.with_streaming_response.cancel(
150 batch_id="batch_id",
151 vector_store_id="vector_store_id",
152 ) as response:
153 assert not response.is_closed
154 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
155
156 file_batch = response.parse()
157 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
158
159 assert cast(Any, response.is_closed) is True
160
161 @parametrize
162 def test_path_params_cancel(self, client: OpenAI) -> None:
163 with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"):
164 client.vector_stores.file_batches.with_raw_response.cancel(
165 batch_id="batch_id",
166 vector_store_id="",
167 )
168
169 with pytest.raises(ValueError, match=r"Expected a non-empty value for `batch_id` but received ''"):
170 client.vector_stores.file_batches.with_raw_response.cancel(
171 batch_id="",
172 vector_store_id="vector_store_id",
173 )
174
175 @parametrize
176 def test_method_list_files(self, client: OpenAI) -> None:
177 file_batch = client.vector_stores.file_batches.list_files(
178 batch_id="batch_id",
179 vector_store_id="vector_store_id",
180 )
181 assert_matches_type(SyncCursorPage[VectorStoreFile], file_batch, path=["response"])
182
183 @parametrize
184 def test_method_list_files_with_all_params(self, client: OpenAI) -> None:
185 file_batch = client.vector_stores.file_batches.list_files(
186 batch_id="batch_id",
187 vector_store_id="vector_store_id",
188 after="after",
189 before="before",
190 filter="in_progress",
191 limit=0,
192 order="asc",
193 )
194 assert_matches_type(SyncCursorPage[VectorStoreFile], file_batch, path=["response"])
195
196 @parametrize
197 def test_raw_response_list_files(self, client: OpenAI) -> None:
198 response = client.vector_stores.file_batches.with_raw_response.list_files(
199 batch_id="batch_id",
200 vector_store_id="vector_store_id",
201 )
202
203 assert response.is_closed is True
204 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
205 file_batch = response.parse()
206 assert_matches_type(SyncCursorPage[VectorStoreFile], file_batch, path=["response"])
207
208 @parametrize
209 def test_streaming_response_list_files(self, client: OpenAI) -> None:
210 with client.vector_stores.file_batches.with_streaming_response.list_files(
211 batch_id="batch_id",
212 vector_store_id="vector_store_id",
213 ) as response:
214 assert not response.is_closed
215 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
216
217 file_batch = response.parse()
218 assert_matches_type(SyncCursorPage[VectorStoreFile], file_batch, path=["response"])
219
220 assert cast(Any, response.is_closed) is True
221
222 @parametrize
223 def test_path_params_list_files(self, client: OpenAI) -> None:
224 with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"):
225 client.vector_stores.file_batches.with_raw_response.list_files(
226 batch_id="batch_id",
227 vector_store_id="",
228 )
229
230 with pytest.raises(ValueError, match=r"Expected a non-empty value for `batch_id` but received ''"):
231 client.vector_stores.file_batches.with_raw_response.list_files(
232 batch_id="",
233 vector_store_id="vector_store_id",
234 )
235
236
237class TestAsyncFileBatches:
238 parametrize = pytest.mark.parametrize(
239 "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
240 )
241
242 @parametrize
243 async def test_method_create(self, async_client: AsyncOpenAI) -> None:
244 file_batch = await async_client.vector_stores.file_batches.create(
245 vector_store_id="vs_abc123",
246 )
247 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
248
249 @parametrize
250 async def test_method_create_with_all_params(self, async_client: AsyncOpenAI) -> None:
251 file_batch = await async_client.vector_stores.file_batches.create(
252 vector_store_id="vs_abc123",
253 attributes={"foo": "string"},
254 chunking_strategy={"type": "auto"},
255 file_ids=["string"],
256 files=[
257 {
258 "file_id": "file_id",
259 "attributes": {"foo": "string"},
260 "chunking_strategy": {"type": "auto"},
261 }
262 ],
263 )
264 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
265
266 @parametrize
267 async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None:
268 response = await async_client.vector_stores.file_batches.with_raw_response.create(
269 vector_store_id="vs_abc123",
270 )
271
272 assert response.is_closed is True
273 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
274 file_batch = response.parse()
275 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
276
277 @parametrize
278 async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None:
279 async with async_client.vector_stores.file_batches.with_streaming_response.create(
280 vector_store_id="vs_abc123",
281 ) as response:
282 assert not response.is_closed
283 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
284
285 file_batch = await response.parse()
286 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
287
288 assert cast(Any, response.is_closed) is True
289
290 @parametrize
291 async def test_path_params_create(self, async_client: AsyncOpenAI) -> None:
292 with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"):
293 await async_client.vector_stores.file_batches.with_raw_response.create(
294 vector_store_id="",
295 )
296
297 @parametrize
298 async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None:
299 file_batch = await async_client.vector_stores.file_batches.retrieve(
300 batch_id="vsfb_abc123",
301 vector_store_id="vs_abc123",
302 )
303 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
304
305 @parametrize
306 async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None:
307 response = await async_client.vector_stores.file_batches.with_raw_response.retrieve(
308 batch_id="vsfb_abc123",
309 vector_store_id="vs_abc123",
310 )
311
312 assert response.is_closed is True
313 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
314 file_batch = response.parse()
315 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
316
317 @parametrize
318 async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None:
319 async with async_client.vector_stores.file_batches.with_streaming_response.retrieve(
320 batch_id="vsfb_abc123",
321 vector_store_id="vs_abc123",
322 ) as response:
323 assert not response.is_closed
324 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
325
326 file_batch = await response.parse()
327 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
328
329 assert cast(Any, response.is_closed) is True
330
331 @parametrize
332 async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None:
333 with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"):
334 await async_client.vector_stores.file_batches.with_raw_response.retrieve(
335 batch_id="vsfb_abc123",
336 vector_store_id="",
337 )
338
339 with pytest.raises(ValueError, match=r"Expected a non-empty value for `batch_id` but received ''"):
340 await async_client.vector_stores.file_batches.with_raw_response.retrieve(
341 batch_id="",
342 vector_store_id="vs_abc123",
343 )
344
345 @parametrize
346 async def test_method_cancel(self, async_client: AsyncOpenAI) -> None:
347 file_batch = await async_client.vector_stores.file_batches.cancel(
348 batch_id="batch_id",
349 vector_store_id="vector_store_id",
350 )
351 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
352
353 @parametrize
354 async def test_raw_response_cancel(self, async_client: AsyncOpenAI) -> None:
355 response = await async_client.vector_stores.file_batches.with_raw_response.cancel(
356 batch_id="batch_id",
357 vector_store_id="vector_store_id",
358 )
359
360 assert response.is_closed is True
361 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
362 file_batch = response.parse()
363 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
364
365 @parametrize
366 async def test_streaming_response_cancel(self, async_client: AsyncOpenAI) -> None:
367 async with async_client.vector_stores.file_batches.with_streaming_response.cancel(
368 batch_id="batch_id",
369 vector_store_id="vector_store_id",
370 ) as response:
371 assert not response.is_closed
372 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
373
374 file_batch = await response.parse()
375 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
376
377 assert cast(Any, response.is_closed) is True
378
379 @parametrize
380 async def test_path_params_cancel(self, async_client: AsyncOpenAI) -> None:
381 with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"):
382 await async_client.vector_stores.file_batches.with_raw_response.cancel(
383 batch_id="batch_id",
384 vector_store_id="",
385 )
386
387 with pytest.raises(ValueError, match=r"Expected a non-empty value for `batch_id` but received ''"):
388 await async_client.vector_stores.file_batches.with_raw_response.cancel(
389 batch_id="",
390 vector_store_id="vector_store_id",
391 )
392
393 @parametrize
394 async def test_method_list_files(self, async_client: AsyncOpenAI) -> None:
395 file_batch = await async_client.vector_stores.file_batches.list_files(
396 batch_id="batch_id",
397 vector_store_id="vector_store_id",
398 )
399 assert_matches_type(AsyncCursorPage[VectorStoreFile], file_batch, path=["response"])
400
401 @parametrize
402 async def test_method_list_files_with_all_params(self, async_client: AsyncOpenAI) -> None:
403 file_batch = await async_client.vector_stores.file_batches.list_files(
404 batch_id="batch_id",
405 vector_store_id="vector_store_id",
406 after="after",
407 before="before",
408 filter="in_progress",
409 limit=0,
410 order="asc",
411 )
412 assert_matches_type(AsyncCursorPage[VectorStoreFile], file_batch, path=["response"])
413
414 @parametrize
415 async def test_raw_response_list_files(self, async_client: AsyncOpenAI) -> None:
416 response = await async_client.vector_stores.file_batches.with_raw_response.list_files(
417 batch_id="batch_id",
418 vector_store_id="vector_store_id",
419 )
420
421 assert response.is_closed is True
422 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
423 file_batch = response.parse()
424 assert_matches_type(AsyncCursorPage[VectorStoreFile], file_batch, path=["response"])
425
426 @parametrize
427 async def test_streaming_response_list_files(self, async_client: AsyncOpenAI) -> None:
428 async with async_client.vector_stores.file_batches.with_streaming_response.list_files(
429 batch_id="batch_id",
430 vector_store_id="vector_store_id",
431 ) as response:
432 assert not response.is_closed
433 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
434
435 file_batch = await response.parse()
436 assert_matches_type(AsyncCursorPage[VectorStoreFile], file_batch, path=["response"])
437
438 assert cast(Any, response.is_closed) is True
439
440 @parametrize
441 async def test_path_params_list_files(self, async_client: AsyncOpenAI) -> None:
442 with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"):
443 await async_client.vector_stores.file_batches.with_raw_response.list_files(
444 batch_id="batch_id",
445 vector_store_id="",
446 )
447
448 with pytest.raises(ValueError, match=r"Expected a non-empty value for `batch_id` but received ''"):
449 await async_client.vector_stores.file_batches.with_raw_response.list_files(
450 batch_id="",
451 vector_store_id="vector_store_id",
452 )