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_assistants.py

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