openai/openai-python

Public

mirrored from https://github.com/openai/openai-pythonAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.23.6

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/beta/test_vector_stores.py

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