openai/openai-python

Public

mirrored fromhttps://github.com/openai/openai-pythonAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
dfdcf571ced31f7859cd1871be39e2fb3af6bafa

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

tests/api_resources/beta/test_vector_stores.py

428lines · modecode

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