openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
46ad497f38e3082f97616cb769f71b054ae22dcb

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/beta/threads/test_runs.py

1009lines · 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.threads import (
14 Run,
15)
16
17base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
18
19
20class TestRuns:
21 parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
22
23 @parametrize
24 def test_method_create_overload_1(self, client: OpenAI) -> None:
25 run = client.beta.threads.runs.create(
26 thread_id="thread_id",
27 assistant_id="assistant_id",
28 )
29 assert_matches_type(Run, run, path=["response"])
30
31 @parametrize
32 def test_method_create_with_all_params_overload_1(self, client: OpenAI) -> None:
33 run = client.beta.threads.runs.create(
34 thread_id="thread_id",
35 assistant_id="assistant_id",
36 include=["step_details.tool_calls[*].file_search.results[*].content"],
37 additional_instructions="additional_instructions",
38 additional_messages=[
39 {
40 "content": "string",
41 "role": "user",
42 "attachments": [
43 {
44 "file_id": "file_id",
45 "tools": [{"type": "code_interpreter"}],
46 }
47 ],
48 "metadata": {},
49 }
50 ],
51 instructions="instructions",
52 max_completion_tokens=256,
53 max_prompt_tokens=256,
54 metadata={},
55 model="gpt-4o",
56 parallel_tool_calls=True,
57 response_format="auto",
58 stream=False,
59 temperature=1,
60 tool_choice="none",
61 tools=[{"type": "code_interpreter"}],
62 top_p=1,
63 truncation_strategy={
64 "type": "auto",
65 "last_messages": 1,
66 },
67 )
68 assert_matches_type(Run, run, path=["response"])
69
70 @parametrize
71 def test_raw_response_create_overload_1(self, client: OpenAI) -> None:
72 response = client.beta.threads.runs.with_raw_response.create(
73 thread_id="thread_id",
74 assistant_id="assistant_id",
75 )
76
77 assert response.is_closed is True
78 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
79 run = response.parse()
80 assert_matches_type(Run, run, path=["response"])
81
82 @parametrize
83 def test_streaming_response_create_overload_1(self, client: OpenAI) -> None:
84 with client.beta.threads.runs.with_streaming_response.create(
85 thread_id="thread_id",
86 assistant_id="assistant_id",
87 ) as response:
88 assert not response.is_closed
89 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
90
91 run = response.parse()
92 assert_matches_type(Run, run, path=["response"])
93
94 assert cast(Any, response.is_closed) is True
95
96 @parametrize
97 def test_path_params_create_overload_1(self, client: OpenAI) -> None:
98 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
99 client.beta.threads.runs.with_raw_response.create(
100 thread_id="",
101 assistant_id="assistant_id",
102 )
103
104 @parametrize
105 def test_method_create_overload_2(self, client: OpenAI) -> None:
106 run_stream = client.beta.threads.runs.create(
107 thread_id="thread_id",
108 assistant_id="assistant_id",
109 stream=True,
110 )
111 run_stream.response.close()
112
113 @parametrize
114 def test_method_create_with_all_params_overload_2(self, client: OpenAI) -> None:
115 run_stream = client.beta.threads.runs.create(
116 thread_id="thread_id",
117 assistant_id="assistant_id",
118 stream=True,
119 include=["step_details.tool_calls[*].file_search.results[*].content"],
120 additional_instructions="additional_instructions",
121 additional_messages=[
122 {
123 "content": "string",
124 "role": "user",
125 "attachments": [
126 {
127 "file_id": "file_id",
128 "tools": [{"type": "code_interpreter"}],
129 }
130 ],
131 "metadata": {},
132 }
133 ],
134 instructions="instructions",
135 max_completion_tokens=256,
136 max_prompt_tokens=256,
137 metadata={},
138 model="gpt-4o",
139 parallel_tool_calls=True,
140 response_format="auto",
141 temperature=1,
142 tool_choice="none",
143 tools=[{"type": "code_interpreter"}],
144 top_p=1,
145 truncation_strategy={
146 "type": "auto",
147 "last_messages": 1,
148 },
149 )
150 run_stream.response.close()
151
152 @parametrize
153 def test_raw_response_create_overload_2(self, client: OpenAI) -> None:
154 response = client.beta.threads.runs.with_raw_response.create(
155 thread_id="thread_id",
156 assistant_id="assistant_id",
157 stream=True,
158 )
159
160 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
161 stream = response.parse()
162 stream.close()
163
164 @parametrize
165 def test_streaming_response_create_overload_2(self, client: OpenAI) -> None:
166 with client.beta.threads.runs.with_streaming_response.create(
167 thread_id="thread_id",
168 assistant_id="assistant_id",
169 stream=True,
170 ) as response:
171 assert not response.is_closed
172 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
173
174 stream = response.parse()
175 stream.close()
176
177 assert cast(Any, response.is_closed) is True
178
179 @parametrize
180 def test_path_params_create_overload_2(self, client: OpenAI) -> None:
181 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
182 client.beta.threads.runs.with_raw_response.create(
183 thread_id="",
184 assistant_id="assistant_id",
185 stream=True,
186 )
187
188 @parametrize
189 def test_method_retrieve(self, client: OpenAI) -> None:
190 run = client.beta.threads.runs.retrieve(
191 run_id="run_id",
192 thread_id="thread_id",
193 )
194 assert_matches_type(Run, run, path=["response"])
195
196 @parametrize
197 def test_raw_response_retrieve(self, client: OpenAI) -> None:
198 response = client.beta.threads.runs.with_raw_response.retrieve(
199 run_id="run_id",
200 thread_id="thread_id",
201 )
202
203 assert response.is_closed is True
204 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
205 run = response.parse()
206 assert_matches_type(Run, run, path=["response"])
207
208 @parametrize
209 def test_streaming_response_retrieve(self, client: OpenAI) -> None:
210 with client.beta.threads.runs.with_streaming_response.retrieve(
211 run_id="run_id",
212 thread_id="thread_id",
213 ) as response:
214 assert not response.is_closed
215 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
216
217 run = response.parse()
218 assert_matches_type(Run, run, path=["response"])
219
220 assert cast(Any, response.is_closed) is True
221
222 @parametrize
223 def test_path_params_retrieve(self, client: OpenAI) -> None:
224 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
225 client.beta.threads.runs.with_raw_response.retrieve(
226 run_id="run_id",
227 thread_id="",
228 )
229
230 with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
231 client.beta.threads.runs.with_raw_response.retrieve(
232 run_id="",
233 thread_id="thread_id",
234 )
235
236 @parametrize
237 def test_method_update(self, client: OpenAI) -> None:
238 run = client.beta.threads.runs.update(
239 run_id="run_id",
240 thread_id="thread_id",
241 )
242 assert_matches_type(Run, run, path=["response"])
243
244 @parametrize
245 def test_method_update_with_all_params(self, client: OpenAI) -> None:
246 run = client.beta.threads.runs.update(
247 run_id="run_id",
248 thread_id="thread_id",
249 metadata={},
250 )
251 assert_matches_type(Run, run, path=["response"])
252
253 @parametrize
254 def test_raw_response_update(self, client: OpenAI) -> None:
255 response = client.beta.threads.runs.with_raw_response.update(
256 run_id="run_id",
257 thread_id="thread_id",
258 )
259
260 assert response.is_closed is True
261 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
262 run = response.parse()
263 assert_matches_type(Run, run, path=["response"])
264
265 @parametrize
266 def test_streaming_response_update(self, client: OpenAI) -> None:
267 with client.beta.threads.runs.with_streaming_response.update(
268 run_id="run_id",
269 thread_id="thread_id",
270 ) as response:
271 assert not response.is_closed
272 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
273
274 run = response.parse()
275 assert_matches_type(Run, run, path=["response"])
276
277 assert cast(Any, response.is_closed) is True
278
279 @parametrize
280 def test_path_params_update(self, client: OpenAI) -> None:
281 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
282 client.beta.threads.runs.with_raw_response.update(
283 run_id="run_id",
284 thread_id="",
285 )
286
287 with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
288 client.beta.threads.runs.with_raw_response.update(
289 run_id="",
290 thread_id="thread_id",
291 )
292
293 @parametrize
294 def test_method_list(self, client: OpenAI) -> None:
295 run = client.beta.threads.runs.list(
296 thread_id="thread_id",
297 )
298 assert_matches_type(SyncCursorPage[Run], run, path=["response"])
299
300 @parametrize
301 def test_method_list_with_all_params(self, client: OpenAI) -> None:
302 run = client.beta.threads.runs.list(
303 thread_id="thread_id",
304 after="after",
305 before="before",
306 limit=0,
307 order="asc",
308 )
309 assert_matches_type(SyncCursorPage[Run], run, path=["response"])
310
311 @parametrize
312 def test_raw_response_list(self, client: OpenAI) -> None:
313 response = client.beta.threads.runs.with_raw_response.list(
314 thread_id="thread_id",
315 )
316
317 assert response.is_closed is True
318 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
319 run = response.parse()
320 assert_matches_type(SyncCursorPage[Run], run, path=["response"])
321
322 @parametrize
323 def test_streaming_response_list(self, client: OpenAI) -> None:
324 with client.beta.threads.runs.with_streaming_response.list(
325 thread_id="thread_id",
326 ) as response:
327 assert not response.is_closed
328 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
329
330 run = response.parse()
331 assert_matches_type(SyncCursorPage[Run], run, path=["response"])
332
333 assert cast(Any, response.is_closed) is True
334
335 @parametrize
336 def test_path_params_list(self, client: OpenAI) -> None:
337 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
338 client.beta.threads.runs.with_raw_response.list(
339 thread_id="",
340 )
341
342 @parametrize
343 def test_method_cancel(self, client: OpenAI) -> None:
344 run = client.beta.threads.runs.cancel(
345 run_id="run_id",
346 thread_id="thread_id",
347 )
348 assert_matches_type(Run, run, path=["response"])
349
350 @parametrize
351 def test_raw_response_cancel(self, client: OpenAI) -> None:
352 response = client.beta.threads.runs.with_raw_response.cancel(
353 run_id="run_id",
354 thread_id="thread_id",
355 )
356
357 assert response.is_closed is True
358 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
359 run = response.parse()
360 assert_matches_type(Run, run, path=["response"])
361
362 @parametrize
363 def test_streaming_response_cancel(self, client: OpenAI) -> None:
364 with client.beta.threads.runs.with_streaming_response.cancel(
365 run_id="run_id",
366 thread_id="thread_id",
367 ) as response:
368 assert not response.is_closed
369 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
370
371 run = response.parse()
372 assert_matches_type(Run, run, path=["response"])
373
374 assert cast(Any, response.is_closed) is True
375
376 @parametrize
377 def test_path_params_cancel(self, client: OpenAI) -> None:
378 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
379 client.beta.threads.runs.with_raw_response.cancel(
380 run_id="run_id",
381 thread_id="",
382 )
383
384 with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
385 client.beta.threads.runs.with_raw_response.cancel(
386 run_id="",
387 thread_id="thread_id",
388 )
389
390 @parametrize
391 def test_method_submit_tool_outputs_overload_1(self, client: OpenAI) -> None:
392 run = client.beta.threads.runs.submit_tool_outputs(
393 run_id="run_id",
394 thread_id="thread_id",
395 tool_outputs=[{}],
396 )
397 assert_matches_type(Run, run, path=["response"])
398
399 @parametrize
400 def test_method_submit_tool_outputs_with_all_params_overload_1(self, client: OpenAI) -> None:
401 run = client.beta.threads.runs.submit_tool_outputs(
402 run_id="run_id",
403 thread_id="thread_id",
404 tool_outputs=[
405 {
406 "output": "output",
407 "tool_call_id": "tool_call_id",
408 }
409 ],
410 stream=False,
411 )
412 assert_matches_type(Run, run, path=["response"])
413
414 @parametrize
415 def test_raw_response_submit_tool_outputs_overload_1(self, client: OpenAI) -> None:
416 response = client.beta.threads.runs.with_raw_response.submit_tool_outputs(
417 run_id="run_id",
418 thread_id="thread_id",
419 tool_outputs=[{}],
420 )
421
422 assert response.is_closed is True
423 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
424 run = response.parse()
425 assert_matches_type(Run, run, path=["response"])
426
427 @parametrize
428 def test_streaming_response_submit_tool_outputs_overload_1(self, client: OpenAI) -> None:
429 with client.beta.threads.runs.with_streaming_response.submit_tool_outputs(
430 run_id="run_id",
431 thread_id="thread_id",
432 tool_outputs=[{}],
433 ) as response:
434 assert not response.is_closed
435 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
436
437 run = response.parse()
438 assert_matches_type(Run, run, path=["response"])
439
440 assert cast(Any, response.is_closed) is True
441
442 @parametrize
443 def test_path_params_submit_tool_outputs_overload_1(self, client: OpenAI) -> None:
444 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
445 client.beta.threads.runs.with_raw_response.submit_tool_outputs(
446 run_id="run_id",
447 thread_id="",
448 tool_outputs=[{}],
449 )
450
451 with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
452 client.beta.threads.runs.with_raw_response.submit_tool_outputs(
453 run_id="",
454 thread_id="thread_id",
455 tool_outputs=[{}],
456 )
457
458 @parametrize
459 def test_method_submit_tool_outputs_overload_2(self, client: OpenAI) -> None:
460 run_stream = client.beta.threads.runs.submit_tool_outputs(
461 run_id="run_id",
462 thread_id="thread_id",
463 stream=True,
464 tool_outputs=[{}],
465 )
466 run_stream.response.close()
467
468 @parametrize
469 def test_raw_response_submit_tool_outputs_overload_2(self, client: OpenAI) -> None:
470 response = client.beta.threads.runs.with_raw_response.submit_tool_outputs(
471 run_id="run_id",
472 thread_id="thread_id",
473 stream=True,
474 tool_outputs=[{}],
475 )
476
477 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
478 stream = response.parse()
479 stream.close()
480
481 @parametrize
482 def test_streaming_response_submit_tool_outputs_overload_2(self, client: OpenAI) -> None:
483 with client.beta.threads.runs.with_streaming_response.submit_tool_outputs(
484 run_id="run_id",
485 thread_id="thread_id",
486 stream=True,
487 tool_outputs=[{}],
488 ) as response:
489 assert not response.is_closed
490 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
491
492 stream = response.parse()
493 stream.close()
494
495 assert cast(Any, response.is_closed) is True
496
497 @parametrize
498 def test_path_params_submit_tool_outputs_overload_2(self, client: OpenAI) -> None:
499 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
500 client.beta.threads.runs.with_raw_response.submit_tool_outputs(
501 run_id="run_id",
502 thread_id="",
503 stream=True,
504 tool_outputs=[{}],
505 )
506
507 with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
508 client.beta.threads.runs.with_raw_response.submit_tool_outputs(
509 run_id="",
510 thread_id="thread_id",
511 stream=True,
512 tool_outputs=[{}],
513 )
514
515
516class TestAsyncRuns:
517 parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
518
519 @parametrize
520 async def test_method_create_overload_1(self, async_client: AsyncOpenAI) -> None:
521 run = await async_client.beta.threads.runs.create(
522 thread_id="thread_id",
523 assistant_id="assistant_id",
524 )
525 assert_matches_type(Run, run, path=["response"])
526
527 @parametrize
528 async def test_method_create_with_all_params_overload_1(self, async_client: AsyncOpenAI) -> None:
529 run = await async_client.beta.threads.runs.create(
530 thread_id="thread_id",
531 assistant_id="assistant_id",
532 include=["step_details.tool_calls[*].file_search.results[*].content"],
533 additional_instructions="additional_instructions",
534 additional_messages=[
535 {
536 "content": "string",
537 "role": "user",
538 "attachments": [
539 {
540 "file_id": "file_id",
541 "tools": [{"type": "code_interpreter"}],
542 }
543 ],
544 "metadata": {},
545 }
546 ],
547 instructions="instructions",
548 max_completion_tokens=256,
549 max_prompt_tokens=256,
550 metadata={},
551 model="gpt-4o",
552 parallel_tool_calls=True,
553 response_format="auto",
554 stream=False,
555 temperature=1,
556 tool_choice="none",
557 tools=[{"type": "code_interpreter"}],
558 top_p=1,
559 truncation_strategy={
560 "type": "auto",
561 "last_messages": 1,
562 },
563 )
564 assert_matches_type(Run, run, path=["response"])
565
566 @parametrize
567 async def test_raw_response_create_overload_1(self, async_client: AsyncOpenAI) -> None:
568 response = await async_client.beta.threads.runs.with_raw_response.create(
569 thread_id="thread_id",
570 assistant_id="assistant_id",
571 )
572
573 assert response.is_closed is True
574 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
575 run = response.parse()
576 assert_matches_type(Run, run, path=["response"])
577
578 @parametrize
579 async def test_streaming_response_create_overload_1(self, async_client: AsyncOpenAI) -> None:
580 async with async_client.beta.threads.runs.with_streaming_response.create(
581 thread_id="thread_id",
582 assistant_id="assistant_id",
583 ) as response:
584 assert not response.is_closed
585 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
586
587 run = await response.parse()
588 assert_matches_type(Run, run, path=["response"])
589
590 assert cast(Any, response.is_closed) is True
591
592 @parametrize
593 async def test_path_params_create_overload_1(self, async_client: AsyncOpenAI) -> None:
594 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
595 await async_client.beta.threads.runs.with_raw_response.create(
596 thread_id="",
597 assistant_id="assistant_id",
598 )
599
600 @parametrize
601 async def test_method_create_overload_2(self, async_client: AsyncOpenAI) -> None:
602 run_stream = await async_client.beta.threads.runs.create(
603 thread_id="thread_id",
604 assistant_id="assistant_id",
605 stream=True,
606 )
607 await run_stream.response.aclose()
608
609 @parametrize
610 async def test_method_create_with_all_params_overload_2(self, async_client: AsyncOpenAI) -> None:
611 run_stream = await async_client.beta.threads.runs.create(
612 thread_id="thread_id",
613 assistant_id="assistant_id",
614 stream=True,
615 include=["step_details.tool_calls[*].file_search.results[*].content"],
616 additional_instructions="additional_instructions",
617 additional_messages=[
618 {
619 "content": "string",
620 "role": "user",
621 "attachments": [
622 {
623 "file_id": "file_id",
624 "tools": [{"type": "code_interpreter"}],
625 }
626 ],
627 "metadata": {},
628 }
629 ],
630 instructions="instructions",
631 max_completion_tokens=256,
632 max_prompt_tokens=256,
633 metadata={},
634 model="gpt-4o",
635 parallel_tool_calls=True,
636 response_format="auto",
637 temperature=1,
638 tool_choice="none",
639 tools=[{"type": "code_interpreter"}],
640 top_p=1,
641 truncation_strategy={
642 "type": "auto",
643 "last_messages": 1,
644 },
645 )
646 await run_stream.response.aclose()
647
648 @parametrize
649 async def test_raw_response_create_overload_2(self, async_client: AsyncOpenAI) -> None:
650 response = await async_client.beta.threads.runs.with_raw_response.create(
651 thread_id="thread_id",
652 assistant_id="assistant_id",
653 stream=True,
654 )
655
656 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
657 stream = response.parse()
658 await stream.close()
659
660 @parametrize
661 async def test_streaming_response_create_overload_2(self, async_client: AsyncOpenAI) -> None:
662 async with async_client.beta.threads.runs.with_streaming_response.create(
663 thread_id="thread_id",
664 assistant_id="assistant_id",
665 stream=True,
666 ) as response:
667 assert not response.is_closed
668 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
669
670 stream = await response.parse()
671 await stream.close()
672
673 assert cast(Any, response.is_closed) is True
674
675 @parametrize
676 async def test_path_params_create_overload_2(self, async_client: AsyncOpenAI) -> None:
677 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
678 await async_client.beta.threads.runs.with_raw_response.create(
679 thread_id="",
680 assistant_id="assistant_id",
681 stream=True,
682 )
683
684 @parametrize
685 async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None:
686 run = await async_client.beta.threads.runs.retrieve(
687 run_id="run_id",
688 thread_id="thread_id",
689 )
690 assert_matches_type(Run, run, path=["response"])
691
692 @parametrize
693 async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None:
694 response = await async_client.beta.threads.runs.with_raw_response.retrieve(
695 run_id="run_id",
696 thread_id="thread_id",
697 )
698
699 assert response.is_closed is True
700 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
701 run = response.parse()
702 assert_matches_type(Run, run, path=["response"])
703
704 @parametrize
705 async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None:
706 async with async_client.beta.threads.runs.with_streaming_response.retrieve(
707 run_id="run_id",
708 thread_id="thread_id",
709 ) as response:
710 assert not response.is_closed
711 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
712
713 run = await response.parse()
714 assert_matches_type(Run, run, path=["response"])
715
716 assert cast(Any, response.is_closed) is True
717
718 @parametrize
719 async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None:
720 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
721 await async_client.beta.threads.runs.with_raw_response.retrieve(
722 run_id="run_id",
723 thread_id="",
724 )
725
726 with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
727 await async_client.beta.threads.runs.with_raw_response.retrieve(
728 run_id="",
729 thread_id="thread_id",
730 )
731
732 @parametrize
733 async def test_method_update(self, async_client: AsyncOpenAI) -> None:
734 run = await async_client.beta.threads.runs.update(
735 run_id="run_id",
736 thread_id="thread_id",
737 )
738 assert_matches_type(Run, run, path=["response"])
739
740 @parametrize
741 async def test_method_update_with_all_params(self, async_client: AsyncOpenAI) -> None:
742 run = await async_client.beta.threads.runs.update(
743 run_id="run_id",
744 thread_id="thread_id",
745 metadata={},
746 )
747 assert_matches_type(Run, run, path=["response"])
748
749 @parametrize
750 async def test_raw_response_update(self, async_client: AsyncOpenAI) -> None:
751 response = await async_client.beta.threads.runs.with_raw_response.update(
752 run_id="run_id",
753 thread_id="thread_id",
754 )
755
756 assert response.is_closed is True
757 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
758 run = response.parse()
759 assert_matches_type(Run, run, path=["response"])
760
761 @parametrize
762 async def test_streaming_response_update(self, async_client: AsyncOpenAI) -> None:
763 async with async_client.beta.threads.runs.with_streaming_response.update(
764 run_id="run_id",
765 thread_id="thread_id",
766 ) as response:
767 assert not response.is_closed
768 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
769
770 run = await response.parse()
771 assert_matches_type(Run, run, path=["response"])
772
773 assert cast(Any, response.is_closed) is True
774
775 @parametrize
776 async def test_path_params_update(self, async_client: AsyncOpenAI) -> None:
777 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
778 await async_client.beta.threads.runs.with_raw_response.update(
779 run_id="run_id",
780 thread_id="",
781 )
782
783 with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
784 await async_client.beta.threads.runs.with_raw_response.update(
785 run_id="",
786 thread_id="thread_id",
787 )
788
789 @parametrize
790 async def test_method_list(self, async_client: AsyncOpenAI) -> None:
791 run = await async_client.beta.threads.runs.list(
792 thread_id="thread_id",
793 )
794 assert_matches_type(AsyncCursorPage[Run], run, path=["response"])
795
796 @parametrize
797 async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> None:
798 run = await async_client.beta.threads.runs.list(
799 thread_id="thread_id",
800 after="after",
801 before="before",
802 limit=0,
803 order="asc",
804 )
805 assert_matches_type(AsyncCursorPage[Run], run, path=["response"])
806
807 @parametrize
808 async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None:
809 response = await async_client.beta.threads.runs.with_raw_response.list(
810 thread_id="thread_id",
811 )
812
813 assert response.is_closed is True
814 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
815 run = response.parse()
816 assert_matches_type(AsyncCursorPage[Run], run, path=["response"])
817
818 @parametrize
819 async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None:
820 async with async_client.beta.threads.runs.with_streaming_response.list(
821 thread_id="thread_id",
822 ) as response:
823 assert not response.is_closed
824 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
825
826 run = await response.parse()
827 assert_matches_type(AsyncCursorPage[Run], run, path=["response"])
828
829 assert cast(Any, response.is_closed) is True
830
831 @parametrize
832 async def test_path_params_list(self, async_client: AsyncOpenAI) -> None:
833 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
834 await async_client.beta.threads.runs.with_raw_response.list(
835 thread_id="",
836 )
837
838 @parametrize
839 async def test_method_cancel(self, async_client: AsyncOpenAI) -> None:
840 run = await async_client.beta.threads.runs.cancel(
841 run_id="run_id",
842 thread_id="thread_id",
843 )
844 assert_matches_type(Run, run, path=["response"])
845
846 @parametrize
847 async def test_raw_response_cancel(self, async_client: AsyncOpenAI) -> None:
848 response = await async_client.beta.threads.runs.with_raw_response.cancel(
849 run_id="run_id",
850 thread_id="thread_id",
851 )
852
853 assert response.is_closed is True
854 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
855 run = response.parse()
856 assert_matches_type(Run, run, path=["response"])
857
858 @parametrize
859 async def test_streaming_response_cancel(self, async_client: AsyncOpenAI) -> None:
860 async with async_client.beta.threads.runs.with_streaming_response.cancel(
861 run_id="run_id",
862 thread_id="thread_id",
863 ) as response:
864 assert not response.is_closed
865 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
866
867 run = await response.parse()
868 assert_matches_type(Run, run, path=["response"])
869
870 assert cast(Any, response.is_closed) is True
871
872 @parametrize
873 async def test_path_params_cancel(self, async_client: AsyncOpenAI) -> None:
874 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
875 await async_client.beta.threads.runs.with_raw_response.cancel(
876 run_id="run_id",
877 thread_id="",
878 )
879
880 with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
881 await async_client.beta.threads.runs.with_raw_response.cancel(
882 run_id="",
883 thread_id="thread_id",
884 )
885
886 @parametrize
887 async def test_method_submit_tool_outputs_overload_1(self, async_client: AsyncOpenAI) -> None:
888 run = await async_client.beta.threads.runs.submit_tool_outputs(
889 run_id="run_id",
890 thread_id="thread_id",
891 tool_outputs=[{}],
892 )
893 assert_matches_type(Run, run, path=["response"])
894
895 @parametrize
896 async def test_method_submit_tool_outputs_with_all_params_overload_1(self, async_client: AsyncOpenAI) -> None:
897 run = await async_client.beta.threads.runs.submit_tool_outputs(
898 run_id="run_id",
899 thread_id="thread_id",
900 tool_outputs=[
901 {
902 "output": "output",
903 "tool_call_id": "tool_call_id",
904 }
905 ],
906 stream=False,
907 )
908 assert_matches_type(Run, run, path=["response"])
909
910 @parametrize
911 async def test_raw_response_submit_tool_outputs_overload_1(self, async_client: AsyncOpenAI) -> None:
912 response = await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs(
913 run_id="run_id",
914 thread_id="thread_id",
915 tool_outputs=[{}],
916 )
917
918 assert response.is_closed is True
919 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
920 run = response.parse()
921 assert_matches_type(Run, run, path=["response"])
922
923 @parametrize
924 async def test_streaming_response_submit_tool_outputs_overload_1(self, async_client: AsyncOpenAI) -> None:
925 async with async_client.beta.threads.runs.with_streaming_response.submit_tool_outputs(
926 run_id="run_id",
927 thread_id="thread_id",
928 tool_outputs=[{}],
929 ) as response:
930 assert not response.is_closed
931 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
932
933 run = await response.parse()
934 assert_matches_type(Run, run, path=["response"])
935
936 assert cast(Any, response.is_closed) is True
937
938 @parametrize
939 async def test_path_params_submit_tool_outputs_overload_1(self, async_client: AsyncOpenAI) -> None:
940 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
941 await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs(
942 run_id="run_id",
943 thread_id="",
944 tool_outputs=[{}],
945 )
946
947 with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
948 await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs(
949 run_id="",
950 thread_id="thread_id",
951 tool_outputs=[{}],
952 )
953
954 @parametrize
955 async def test_method_submit_tool_outputs_overload_2(self, async_client: AsyncOpenAI) -> None:
956 run_stream = await async_client.beta.threads.runs.submit_tool_outputs(
957 run_id="run_id",
958 thread_id="thread_id",
959 stream=True,
960 tool_outputs=[{}],
961 )
962 await run_stream.response.aclose()
963
964 @parametrize
965 async def test_raw_response_submit_tool_outputs_overload_2(self, async_client: AsyncOpenAI) -> None:
966 response = await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs(
967 run_id="run_id",
968 thread_id="thread_id",
969 stream=True,
970 tool_outputs=[{}],
971 )
972
973 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
974 stream = response.parse()
975 await stream.close()
976
977 @parametrize
978 async def test_streaming_response_submit_tool_outputs_overload_2(self, async_client: AsyncOpenAI) -> None:
979 async with async_client.beta.threads.runs.with_streaming_response.submit_tool_outputs(
980 run_id="run_id",
981 thread_id="thread_id",
982 stream=True,
983 tool_outputs=[{}],
984 ) as response:
985 assert not response.is_closed
986 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
987
988 stream = await response.parse()
989 await stream.close()
990
991 assert cast(Any, response.is_closed) is True
992
993 @parametrize
994 async def test_path_params_submit_tool_outputs_overload_2(self, async_client: AsyncOpenAI) -> None:
995 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
996 await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs(
997 run_id="run_id",
998 thread_id="",
999 stream=True,
1000 tool_outputs=[{}],
1001 )
1002
1003 with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
1004 await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs(
1005 run_id="",
1006 thread_id="thread_id",
1007 stream=True,
1008 tool_outputs=[{}],
1009 )
1010