openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.20.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/beta/test_assistants.py

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