openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.21.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/beta/test_assistants.py

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