openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
e8c28f2ec93063bf73c53e6c8d19bae935a135be

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/beta/threads/test_runs.py

1351lines · 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
17# pyright: reportDeprecated=false
18
19base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
20
21
22class TestRuns:
23 parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
24
25 @parametrize
26 def test_method_create_overload_1(self, client: OpenAI) -> None:
27 run = client.beta.threads.runs.create(
28 "string",
29 assistant_id="string",
30 )
31 assert_matches_type(Run, run, path=["response"])
32
33 @parametrize
34 def test_method_create_with_all_params_overload_1(self, client: OpenAI) -> None:
35 run = client.beta.threads.runs.create(
36 "string",
37 assistant_id="string",
38 additional_instructions="string",
39 additional_messages=[
40 {
41 "content": "string",
42 "role": "user",
43 "attachments": [
44 {
45 "file_id": "string",
46 "tools": [
47 {"type": "code_interpreter"},
48 {"type": "code_interpreter"},
49 {"type": "code_interpreter"},
50 ],
51 },
52 {
53 "file_id": "string",
54 "tools": [
55 {"type": "code_interpreter"},
56 {"type": "code_interpreter"},
57 {"type": "code_interpreter"},
58 ],
59 },
60 {
61 "file_id": "string",
62 "tools": [
63 {"type": "code_interpreter"},
64 {"type": "code_interpreter"},
65 {"type": "code_interpreter"},
66 ],
67 },
68 ],
69 "metadata": {},
70 },
71 {
72 "content": "string",
73 "role": "user",
74 "attachments": [
75 {
76 "file_id": "string",
77 "tools": [
78 {"type": "code_interpreter"},
79 {"type": "code_interpreter"},
80 {"type": "code_interpreter"},
81 ],
82 },
83 {
84 "file_id": "string",
85 "tools": [
86 {"type": "code_interpreter"},
87 {"type": "code_interpreter"},
88 {"type": "code_interpreter"},
89 ],
90 },
91 {
92 "file_id": "string",
93 "tools": [
94 {"type": "code_interpreter"},
95 {"type": "code_interpreter"},
96 {"type": "code_interpreter"},
97 ],
98 },
99 ],
100 "metadata": {},
101 },
102 {
103 "content": "string",
104 "role": "user",
105 "attachments": [
106 {
107 "file_id": "string",
108 "tools": [
109 {"type": "code_interpreter"},
110 {"type": "code_interpreter"},
111 {"type": "code_interpreter"},
112 ],
113 },
114 {
115 "file_id": "string",
116 "tools": [
117 {"type": "code_interpreter"},
118 {"type": "code_interpreter"},
119 {"type": "code_interpreter"},
120 ],
121 },
122 {
123 "file_id": "string",
124 "tools": [
125 {"type": "code_interpreter"},
126 {"type": "code_interpreter"},
127 {"type": "code_interpreter"},
128 ],
129 },
130 ],
131 "metadata": {},
132 },
133 ],
134 instructions="string",
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 stream=False,
142 temperature=1,
143 tool_choice="none",
144 tools=[{"type": "code_interpreter"}, {"type": "code_interpreter"}, {"type": "code_interpreter"}],
145 top_p=1,
146 truncation_strategy={
147 "type": "auto",
148 "last_messages": 1,
149 },
150 )
151 assert_matches_type(Run, run, path=["response"])
152
153 @parametrize
154 def test_raw_response_create_overload_1(self, client: OpenAI) -> None:
155 response = client.beta.threads.runs.with_raw_response.create(
156 "string",
157 assistant_id="string",
158 )
159
160 assert response.is_closed is True
161 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
162 run = response.parse()
163 assert_matches_type(Run, run, path=["response"])
164
165 @parametrize
166 def test_streaming_response_create_overload_1(self, client: OpenAI) -> None:
167 with client.beta.threads.runs.with_streaming_response.create(
168 "string",
169 assistant_id="string",
170 ) as response:
171 assert not response.is_closed
172 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
173
174 run = response.parse()
175 assert_matches_type(Run, run, path=["response"])
176
177 assert cast(Any, response.is_closed) is True
178
179 @parametrize
180 def test_path_params_create_overload_1(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 "",
184 assistant_id="string",
185 )
186
187 @parametrize
188 def test_method_create_overload_2(self, client: OpenAI) -> None:
189 run_stream = client.beta.threads.runs.create(
190 "string",
191 assistant_id="string",
192 stream=True,
193 )
194 run_stream.response.close()
195
196 @parametrize
197 def test_method_create_with_all_params_overload_2(self, client: OpenAI) -> None:
198 run_stream = client.beta.threads.runs.create(
199 "string",
200 assistant_id="string",
201 stream=True,
202 additional_instructions="string",
203 additional_messages=[
204 {
205 "content": "string",
206 "role": "user",
207 "attachments": [
208 {
209 "file_id": "string",
210 "tools": [
211 {"type": "code_interpreter"},
212 {"type": "code_interpreter"},
213 {"type": "code_interpreter"},
214 ],
215 },
216 {
217 "file_id": "string",
218 "tools": [
219 {"type": "code_interpreter"},
220 {"type": "code_interpreter"},
221 {"type": "code_interpreter"},
222 ],
223 },
224 {
225 "file_id": "string",
226 "tools": [
227 {"type": "code_interpreter"},
228 {"type": "code_interpreter"},
229 {"type": "code_interpreter"},
230 ],
231 },
232 ],
233 "metadata": {},
234 },
235 {
236 "content": "string",
237 "role": "user",
238 "attachments": [
239 {
240 "file_id": "string",
241 "tools": [
242 {"type": "code_interpreter"},
243 {"type": "code_interpreter"},
244 {"type": "code_interpreter"},
245 ],
246 },
247 {
248 "file_id": "string",
249 "tools": [
250 {"type": "code_interpreter"},
251 {"type": "code_interpreter"},
252 {"type": "code_interpreter"},
253 ],
254 },
255 {
256 "file_id": "string",
257 "tools": [
258 {"type": "code_interpreter"},
259 {"type": "code_interpreter"},
260 {"type": "code_interpreter"},
261 ],
262 },
263 ],
264 "metadata": {},
265 },
266 {
267 "content": "string",
268 "role": "user",
269 "attachments": [
270 {
271 "file_id": "string",
272 "tools": [
273 {"type": "code_interpreter"},
274 {"type": "code_interpreter"},
275 {"type": "code_interpreter"},
276 ],
277 },
278 {
279 "file_id": "string",
280 "tools": [
281 {"type": "code_interpreter"},
282 {"type": "code_interpreter"},
283 {"type": "code_interpreter"},
284 ],
285 },
286 {
287 "file_id": "string",
288 "tools": [
289 {"type": "code_interpreter"},
290 {"type": "code_interpreter"},
291 {"type": "code_interpreter"},
292 ],
293 },
294 ],
295 "metadata": {},
296 },
297 ],
298 instructions="string",
299 max_completion_tokens=256,
300 max_prompt_tokens=256,
301 metadata={},
302 model="gpt-4o",
303 parallel_tool_calls=True,
304 response_format="auto",
305 temperature=1,
306 tool_choice="none",
307 tools=[{"type": "code_interpreter"}, {"type": "code_interpreter"}, {"type": "code_interpreter"}],
308 top_p=1,
309 truncation_strategy={
310 "type": "auto",
311 "last_messages": 1,
312 },
313 )
314 run_stream.response.close()
315
316 @parametrize
317 def test_raw_response_create_overload_2(self, client: OpenAI) -> None:
318 response = client.beta.threads.runs.with_raw_response.create(
319 "string",
320 assistant_id="string",
321 stream=True,
322 )
323
324 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
325 stream = response.parse()
326 stream.close()
327
328 @parametrize
329 def test_streaming_response_create_overload_2(self, client: OpenAI) -> None:
330 with client.beta.threads.runs.with_streaming_response.create(
331 "string",
332 assistant_id="string",
333 stream=True,
334 ) as response:
335 assert not response.is_closed
336 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
337
338 stream = response.parse()
339 stream.close()
340
341 assert cast(Any, response.is_closed) is True
342
343 @parametrize
344 def test_path_params_create_overload_2(self, client: OpenAI) -> None:
345 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
346 client.beta.threads.runs.with_raw_response.create(
347 "",
348 assistant_id="string",
349 stream=True,
350 )
351
352 @parametrize
353 def test_method_retrieve(self, client: OpenAI) -> None:
354 run = client.beta.threads.runs.retrieve(
355 "string",
356 thread_id="string",
357 )
358 assert_matches_type(Run, run, path=["response"])
359
360 @parametrize
361 def test_raw_response_retrieve(self, client: OpenAI) -> None:
362 response = client.beta.threads.runs.with_raw_response.retrieve(
363 "string",
364 thread_id="string",
365 )
366
367 assert response.is_closed is True
368 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
369 run = response.parse()
370 assert_matches_type(Run, run, path=["response"])
371
372 @parametrize
373 def test_streaming_response_retrieve(self, client: OpenAI) -> None:
374 with client.beta.threads.runs.with_streaming_response.retrieve(
375 "string",
376 thread_id="string",
377 ) as response:
378 assert not response.is_closed
379 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
380
381 run = response.parse()
382 assert_matches_type(Run, run, path=["response"])
383
384 assert cast(Any, response.is_closed) is True
385
386 @parametrize
387 def test_path_params_retrieve(self, client: OpenAI) -> None:
388 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
389 client.beta.threads.runs.with_raw_response.retrieve(
390 "string",
391 thread_id="",
392 )
393
394 with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
395 client.beta.threads.runs.with_raw_response.retrieve(
396 "",
397 thread_id="string",
398 )
399
400 @parametrize
401 def test_method_update(self, client: OpenAI) -> None:
402 run = client.beta.threads.runs.update(
403 "string",
404 thread_id="string",
405 )
406 assert_matches_type(Run, run, path=["response"])
407
408 @parametrize
409 def test_method_update_with_all_params(self, client: OpenAI) -> None:
410 run = client.beta.threads.runs.update(
411 "string",
412 thread_id="string",
413 metadata={},
414 )
415 assert_matches_type(Run, run, path=["response"])
416
417 @parametrize
418 def test_raw_response_update(self, client: OpenAI) -> None:
419 response = client.beta.threads.runs.with_raw_response.update(
420 "string",
421 thread_id="string",
422 )
423
424 assert response.is_closed is True
425 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
426 run = response.parse()
427 assert_matches_type(Run, run, path=["response"])
428
429 @parametrize
430 def test_streaming_response_update(self, client: OpenAI) -> None:
431 with client.beta.threads.runs.with_streaming_response.update(
432 "string",
433 thread_id="string",
434 ) as response:
435 assert not response.is_closed
436 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
437
438 run = response.parse()
439 assert_matches_type(Run, run, path=["response"])
440
441 assert cast(Any, response.is_closed) is True
442
443 @parametrize
444 def test_path_params_update(self, client: OpenAI) -> None:
445 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
446 client.beta.threads.runs.with_raw_response.update(
447 "string",
448 thread_id="",
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.update(
453 "",
454 thread_id="string",
455 )
456
457 @parametrize
458 def test_method_list(self, client: OpenAI) -> None:
459 run = client.beta.threads.runs.list(
460 "string",
461 )
462 assert_matches_type(SyncCursorPage[Run], run, path=["response"])
463
464 @parametrize
465 def test_method_list_with_all_params(self, client: OpenAI) -> None:
466 run = client.beta.threads.runs.list(
467 "string",
468 after="string",
469 before="string",
470 limit=0,
471 order="asc",
472 )
473 assert_matches_type(SyncCursorPage[Run], run, path=["response"])
474
475 @parametrize
476 def test_raw_response_list(self, client: OpenAI) -> None:
477 response = client.beta.threads.runs.with_raw_response.list(
478 "string",
479 )
480
481 assert response.is_closed is True
482 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
483 run = response.parse()
484 assert_matches_type(SyncCursorPage[Run], run, path=["response"])
485
486 @parametrize
487 def test_streaming_response_list(self, client: OpenAI) -> None:
488 with client.beta.threads.runs.with_streaming_response.list(
489 "string",
490 ) as response:
491 assert not response.is_closed
492 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
493
494 run = response.parse()
495 assert_matches_type(SyncCursorPage[Run], run, path=["response"])
496
497 assert cast(Any, response.is_closed) is True
498
499 @parametrize
500 def test_path_params_list(self, client: OpenAI) -> None:
501 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
502 client.beta.threads.runs.with_raw_response.list(
503 "",
504 )
505
506 @parametrize
507 def test_method_cancel(self, client: OpenAI) -> None:
508 run = client.beta.threads.runs.cancel(
509 "string",
510 thread_id="string",
511 )
512 assert_matches_type(Run, run, path=["response"])
513
514 @parametrize
515 def test_raw_response_cancel(self, client: OpenAI) -> None:
516 response = client.beta.threads.runs.with_raw_response.cancel(
517 "string",
518 thread_id="string",
519 )
520
521 assert response.is_closed is True
522 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
523 run = response.parse()
524 assert_matches_type(Run, run, path=["response"])
525
526 @parametrize
527 def test_streaming_response_cancel(self, client: OpenAI) -> None:
528 with client.beta.threads.runs.with_streaming_response.cancel(
529 "string",
530 thread_id="string",
531 ) as response:
532 assert not response.is_closed
533 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
534
535 run = response.parse()
536 assert_matches_type(Run, run, path=["response"])
537
538 assert cast(Any, response.is_closed) is True
539
540 @parametrize
541 def test_path_params_cancel(self, client: OpenAI) -> None:
542 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
543 client.beta.threads.runs.with_raw_response.cancel(
544 "string",
545 thread_id="",
546 )
547
548 with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
549 client.beta.threads.runs.with_raw_response.cancel(
550 "",
551 thread_id="string",
552 )
553
554 @parametrize
555 def test_method_submit_tool_outputs_overload_1(self, client: OpenAI) -> None:
556 run = client.beta.threads.runs.submit_tool_outputs(
557 "string",
558 thread_id="string",
559 tool_outputs=[{}, {}, {}],
560 )
561 assert_matches_type(Run, run, path=["response"])
562
563 @parametrize
564 def test_method_submit_tool_outputs_with_all_params_overload_1(self, client: OpenAI) -> None:
565 run = client.beta.threads.runs.submit_tool_outputs(
566 "string",
567 thread_id="string",
568 tool_outputs=[
569 {
570 "output": "output",
571 "tool_call_id": "tool_call_id",
572 },
573 {
574 "output": "output",
575 "tool_call_id": "tool_call_id",
576 },
577 {
578 "output": "output",
579 "tool_call_id": "tool_call_id",
580 },
581 ],
582 stream=False,
583 )
584 assert_matches_type(Run, run, path=["response"])
585
586 @parametrize
587 def test_raw_response_submit_tool_outputs_overload_1(self, client: OpenAI) -> None:
588 response = client.beta.threads.runs.with_raw_response.submit_tool_outputs(
589 "string",
590 thread_id="string",
591 tool_outputs=[{}, {}, {}],
592 )
593
594 assert response.is_closed is True
595 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
596 run = response.parse()
597 assert_matches_type(Run, run, path=["response"])
598
599 @parametrize
600 def test_streaming_response_submit_tool_outputs_overload_1(self, client: OpenAI) -> None:
601 with client.beta.threads.runs.with_streaming_response.submit_tool_outputs(
602 "string",
603 thread_id="string",
604 tool_outputs=[{}, {}, {}],
605 ) as response:
606 assert not response.is_closed
607 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
608
609 run = response.parse()
610 assert_matches_type(Run, run, path=["response"])
611
612 assert cast(Any, response.is_closed) is True
613
614 @parametrize
615 def test_path_params_submit_tool_outputs_overload_1(self, client: OpenAI) -> None:
616 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
617 client.beta.threads.runs.with_raw_response.submit_tool_outputs(
618 "string",
619 thread_id="",
620 tool_outputs=[{}, {}, {}],
621 )
622
623 with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
624 client.beta.threads.runs.with_raw_response.submit_tool_outputs(
625 "",
626 thread_id="string",
627 tool_outputs=[{}, {}, {}],
628 )
629
630 @parametrize
631 def test_method_submit_tool_outputs_overload_2(self, client: OpenAI) -> None:
632 run_stream = client.beta.threads.runs.submit_tool_outputs(
633 "string",
634 thread_id="string",
635 stream=True,
636 tool_outputs=[{}, {}, {}],
637 )
638 run_stream.response.close()
639
640 @parametrize
641 def test_raw_response_submit_tool_outputs_overload_2(self, client: OpenAI) -> None:
642 response = client.beta.threads.runs.with_raw_response.submit_tool_outputs(
643 "string",
644 thread_id="string",
645 stream=True,
646 tool_outputs=[{}, {}, {}],
647 )
648
649 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
650 stream = response.parse()
651 stream.close()
652
653 @parametrize
654 def test_streaming_response_submit_tool_outputs_overload_2(self, client: OpenAI) -> None:
655 with client.beta.threads.runs.with_streaming_response.submit_tool_outputs(
656 "string",
657 thread_id="string",
658 stream=True,
659 tool_outputs=[{}, {}, {}],
660 ) as response:
661 assert not response.is_closed
662 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
663
664 stream = response.parse()
665 stream.close()
666
667 assert cast(Any, response.is_closed) is True
668
669 @parametrize
670 def test_path_params_submit_tool_outputs_overload_2(self, client: OpenAI) -> None:
671 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
672 client.beta.threads.runs.with_raw_response.submit_tool_outputs(
673 "string",
674 thread_id="",
675 stream=True,
676 tool_outputs=[{}, {}, {}],
677 )
678
679 with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
680 client.beta.threads.runs.with_raw_response.submit_tool_outputs(
681 "",
682 thread_id="string",
683 stream=True,
684 tool_outputs=[{}, {}, {}],
685 )
686
687
688class TestAsyncRuns:
689 parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
690
691 @parametrize
692 async def test_method_create_overload_1(self, async_client: AsyncOpenAI) -> None:
693 run = await async_client.beta.threads.runs.create(
694 "string",
695 assistant_id="string",
696 )
697 assert_matches_type(Run, run, path=["response"])
698
699 @parametrize
700 async def test_method_create_with_all_params_overload_1(self, async_client: AsyncOpenAI) -> None:
701 run = await async_client.beta.threads.runs.create(
702 "string",
703 assistant_id="string",
704 additional_instructions="string",
705 additional_messages=[
706 {
707 "content": "string",
708 "role": "user",
709 "attachments": [
710 {
711 "file_id": "string",
712 "tools": [
713 {"type": "code_interpreter"},
714 {"type": "code_interpreter"},
715 {"type": "code_interpreter"},
716 ],
717 },
718 {
719 "file_id": "string",
720 "tools": [
721 {"type": "code_interpreter"},
722 {"type": "code_interpreter"},
723 {"type": "code_interpreter"},
724 ],
725 },
726 {
727 "file_id": "string",
728 "tools": [
729 {"type": "code_interpreter"},
730 {"type": "code_interpreter"},
731 {"type": "code_interpreter"},
732 ],
733 },
734 ],
735 "metadata": {},
736 },
737 {
738 "content": "string",
739 "role": "user",
740 "attachments": [
741 {
742 "file_id": "string",
743 "tools": [
744 {"type": "code_interpreter"},
745 {"type": "code_interpreter"},
746 {"type": "code_interpreter"},
747 ],
748 },
749 {
750 "file_id": "string",
751 "tools": [
752 {"type": "code_interpreter"},
753 {"type": "code_interpreter"},
754 {"type": "code_interpreter"},
755 ],
756 },
757 {
758 "file_id": "string",
759 "tools": [
760 {"type": "code_interpreter"},
761 {"type": "code_interpreter"},
762 {"type": "code_interpreter"},
763 ],
764 },
765 ],
766 "metadata": {},
767 },
768 {
769 "content": "string",
770 "role": "user",
771 "attachments": [
772 {
773 "file_id": "string",
774 "tools": [
775 {"type": "code_interpreter"},
776 {"type": "code_interpreter"},
777 {"type": "code_interpreter"},
778 ],
779 },
780 {
781 "file_id": "string",
782 "tools": [
783 {"type": "code_interpreter"},
784 {"type": "code_interpreter"},
785 {"type": "code_interpreter"},
786 ],
787 },
788 {
789 "file_id": "string",
790 "tools": [
791 {"type": "code_interpreter"},
792 {"type": "code_interpreter"},
793 {"type": "code_interpreter"},
794 ],
795 },
796 ],
797 "metadata": {},
798 },
799 ],
800 instructions="string",
801 max_completion_tokens=256,
802 max_prompt_tokens=256,
803 metadata={},
804 model="gpt-4o",
805 parallel_tool_calls=True,
806 response_format="auto",
807 stream=False,
808 temperature=1,
809 tool_choice="none",
810 tools=[{"type": "code_interpreter"}, {"type": "code_interpreter"}, {"type": "code_interpreter"}],
811 top_p=1,
812 truncation_strategy={
813 "type": "auto",
814 "last_messages": 1,
815 },
816 )
817 assert_matches_type(Run, run, path=["response"])
818
819 @parametrize
820 async def test_raw_response_create_overload_1(self, async_client: AsyncOpenAI) -> None:
821 response = await async_client.beta.threads.runs.with_raw_response.create(
822 "string",
823 assistant_id="string",
824 )
825
826 assert response.is_closed is True
827 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
828 run = response.parse()
829 assert_matches_type(Run, run, path=["response"])
830
831 @parametrize
832 async def test_streaming_response_create_overload_1(self, async_client: AsyncOpenAI) -> None:
833 async with async_client.beta.threads.runs.with_streaming_response.create(
834 "string",
835 assistant_id="string",
836 ) as response:
837 assert not response.is_closed
838 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
839
840 run = await response.parse()
841 assert_matches_type(Run, run, path=["response"])
842
843 assert cast(Any, response.is_closed) is True
844
845 @parametrize
846 async def test_path_params_create_overload_1(self, async_client: AsyncOpenAI) -> None:
847 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
848 await async_client.beta.threads.runs.with_raw_response.create(
849 "",
850 assistant_id="string",
851 )
852
853 @parametrize
854 async def test_method_create_overload_2(self, async_client: AsyncOpenAI) -> None:
855 run_stream = await async_client.beta.threads.runs.create(
856 "string",
857 assistant_id="string",
858 stream=True,
859 )
860 await run_stream.response.aclose()
861
862 @parametrize
863 async def test_method_create_with_all_params_overload_2(self, async_client: AsyncOpenAI) -> None:
864 run_stream = await async_client.beta.threads.runs.create(
865 "string",
866 assistant_id="string",
867 stream=True,
868 additional_instructions="string",
869 additional_messages=[
870 {
871 "content": "string",
872 "role": "user",
873 "attachments": [
874 {
875 "file_id": "string",
876 "tools": [
877 {"type": "code_interpreter"},
878 {"type": "code_interpreter"},
879 {"type": "code_interpreter"},
880 ],
881 },
882 {
883 "file_id": "string",
884 "tools": [
885 {"type": "code_interpreter"},
886 {"type": "code_interpreter"},
887 {"type": "code_interpreter"},
888 ],
889 },
890 {
891 "file_id": "string",
892 "tools": [
893 {"type": "code_interpreter"},
894 {"type": "code_interpreter"},
895 {"type": "code_interpreter"},
896 ],
897 },
898 ],
899 "metadata": {},
900 },
901 {
902 "content": "string",
903 "role": "user",
904 "attachments": [
905 {
906 "file_id": "string",
907 "tools": [
908 {"type": "code_interpreter"},
909 {"type": "code_interpreter"},
910 {"type": "code_interpreter"},
911 ],
912 },
913 {
914 "file_id": "string",
915 "tools": [
916 {"type": "code_interpreter"},
917 {"type": "code_interpreter"},
918 {"type": "code_interpreter"},
919 ],
920 },
921 {
922 "file_id": "string",
923 "tools": [
924 {"type": "code_interpreter"},
925 {"type": "code_interpreter"},
926 {"type": "code_interpreter"},
927 ],
928 },
929 ],
930 "metadata": {},
931 },
932 {
933 "content": "string",
934 "role": "user",
935 "attachments": [
936 {
937 "file_id": "string",
938 "tools": [
939 {"type": "code_interpreter"},
940 {"type": "code_interpreter"},
941 {"type": "code_interpreter"},
942 ],
943 },
944 {
945 "file_id": "string",
946 "tools": [
947 {"type": "code_interpreter"},
948 {"type": "code_interpreter"},
949 {"type": "code_interpreter"},
950 ],
951 },
952 {
953 "file_id": "string",
954 "tools": [
955 {"type": "code_interpreter"},
956 {"type": "code_interpreter"},
957 {"type": "code_interpreter"},
958 ],
959 },
960 ],
961 "metadata": {},
962 },
963 ],
964 instructions="string",
965 max_completion_tokens=256,
966 max_prompt_tokens=256,
967 metadata={},
968 model="gpt-4o",
969 parallel_tool_calls=True,
970 response_format="auto",
971 temperature=1,
972 tool_choice="none",
973 tools=[{"type": "code_interpreter"}, {"type": "code_interpreter"}, {"type": "code_interpreter"}],
974 top_p=1,
975 truncation_strategy={
976 "type": "auto",
977 "last_messages": 1,
978 },
979 )
980 await run_stream.response.aclose()
981
982 @parametrize
983 async def test_raw_response_create_overload_2(self, async_client: AsyncOpenAI) -> None:
984 response = await async_client.beta.threads.runs.with_raw_response.create(
985 "string",
986 assistant_id="string",
987 stream=True,
988 )
989
990 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
991 stream = response.parse()
992 await stream.close()
993
994 @parametrize
995 async def test_streaming_response_create_overload_2(self, async_client: AsyncOpenAI) -> None:
996 async with async_client.beta.threads.runs.with_streaming_response.create(
997 "string",
998 assistant_id="string",
999 stream=True,
1000 ) as response:
1001 assert not response.is_closed
1002 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
1003
1004 stream = await response.parse()
1005 await stream.close()
1006
1007 assert cast(Any, response.is_closed) is True
1008
1009 @parametrize
1010 async def test_path_params_create_overload_2(self, async_client: AsyncOpenAI) -> None:
1011 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
1012 await async_client.beta.threads.runs.with_raw_response.create(
1013 "",
1014 assistant_id="string",
1015 stream=True,
1016 )
1017
1018 @parametrize
1019 async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None:
1020 run = await async_client.beta.threads.runs.retrieve(
1021 "string",
1022 thread_id="string",
1023 )
1024 assert_matches_type(Run, run, path=["response"])
1025
1026 @parametrize
1027 async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None:
1028 response = await async_client.beta.threads.runs.with_raw_response.retrieve(
1029 "string",
1030 thread_id="string",
1031 )
1032
1033 assert response.is_closed is True
1034 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
1035 run = response.parse()
1036 assert_matches_type(Run, run, path=["response"])
1037
1038 @parametrize
1039 async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None:
1040 async with async_client.beta.threads.runs.with_streaming_response.retrieve(
1041 "string",
1042 thread_id="string",
1043 ) as response:
1044 assert not response.is_closed
1045 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
1046
1047 run = await response.parse()
1048 assert_matches_type(Run, run, path=["response"])
1049
1050 assert cast(Any, response.is_closed) is True
1051
1052 @parametrize
1053 async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None:
1054 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
1055 await async_client.beta.threads.runs.with_raw_response.retrieve(
1056 "string",
1057 thread_id="",
1058 )
1059
1060 with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
1061 await async_client.beta.threads.runs.with_raw_response.retrieve(
1062 "",
1063 thread_id="string",
1064 )
1065
1066 @parametrize
1067 async def test_method_update(self, async_client: AsyncOpenAI) -> None:
1068 run = await async_client.beta.threads.runs.update(
1069 "string",
1070 thread_id="string",
1071 )
1072 assert_matches_type(Run, run, path=["response"])
1073
1074 @parametrize
1075 async def test_method_update_with_all_params(self, async_client: AsyncOpenAI) -> None:
1076 run = await async_client.beta.threads.runs.update(
1077 "string",
1078 thread_id="string",
1079 metadata={},
1080 )
1081 assert_matches_type(Run, run, path=["response"])
1082
1083 @parametrize
1084 async def test_raw_response_update(self, async_client: AsyncOpenAI) -> None:
1085 response = await async_client.beta.threads.runs.with_raw_response.update(
1086 "string",
1087 thread_id="string",
1088 )
1089
1090 assert response.is_closed is True
1091 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
1092 run = response.parse()
1093 assert_matches_type(Run, run, path=["response"])
1094
1095 @parametrize
1096 async def test_streaming_response_update(self, async_client: AsyncOpenAI) -> None:
1097 async with async_client.beta.threads.runs.with_streaming_response.update(
1098 "string",
1099 thread_id="string",
1100 ) as response:
1101 assert not response.is_closed
1102 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
1103
1104 run = await response.parse()
1105 assert_matches_type(Run, run, path=["response"])
1106
1107 assert cast(Any, response.is_closed) is True
1108
1109 @parametrize
1110 async def test_path_params_update(self, async_client: AsyncOpenAI) -> None:
1111 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
1112 await async_client.beta.threads.runs.with_raw_response.update(
1113 "string",
1114 thread_id="",
1115 )
1116
1117 with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
1118 await async_client.beta.threads.runs.with_raw_response.update(
1119 "",
1120 thread_id="string",
1121 )
1122
1123 @parametrize
1124 async def test_method_list(self, async_client: AsyncOpenAI) -> None:
1125 run = await async_client.beta.threads.runs.list(
1126 "string",
1127 )
1128 assert_matches_type(AsyncCursorPage[Run], run, path=["response"])
1129
1130 @parametrize
1131 async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> None:
1132 run = await async_client.beta.threads.runs.list(
1133 "string",
1134 after="string",
1135 before="string",
1136 limit=0,
1137 order="asc",
1138 )
1139 assert_matches_type(AsyncCursorPage[Run], run, path=["response"])
1140
1141 @parametrize
1142 async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None:
1143 response = await async_client.beta.threads.runs.with_raw_response.list(
1144 "string",
1145 )
1146
1147 assert response.is_closed is True
1148 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
1149 run = response.parse()
1150 assert_matches_type(AsyncCursorPage[Run], run, path=["response"])
1151
1152 @parametrize
1153 async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None:
1154 async with async_client.beta.threads.runs.with_streaming_response.list(
1155 "string",
1156 ) as response:
1157 assert not response.is_closed
1158 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
1159
1160 run = await response.parse()
1161 assert_matches_type(AsyncCursorPage[Run], run, path=["response"])
1162
1163 assert cast(Any, response.is_closed) is True
1164
1165 @parametrize
1166 async def test_path_params_list(self, async_client: AsyncOpenAI) -> None:
1167 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
1168 await async_client.beta.threads.runs.with_raw_response.list(
1169 "",
1170 )
1171
1172 @parametrize
1173 async def test_method_cancel(self, async_client: AsyncOpenAI) -> None:
1174 run = await async_client.beta.threads.runs.cancel(
1175 "string",
1176 thread_id="string",
1177 )
1178 assert_matches_type(Run, run, path=["response"])
1179
1180 @parametrize
1181 async def test_raw_response_cancel(self, async_client: AsyncOpenAI) -> None:
1182 response = await async_client.beta.threads.runs.with_raw_response.cancel(
1183 "string",
1184 thread_id="string",
1185 )
1186
1187 assert response.is_closed is True
1188 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
1189 run = response.parse()
1190 assert_matches_type(Run, run, path=["response"])
1191
1192 @parametrize
1193 async def test_streaming_response_cancel(self, async_client: AsyncOpenAI) -> None:
1194 async with async_client.beta.threads.runs.with_streaming_response.cancel(
1195 "string",
1196 thread_id="string",
1197 ) as response:
1198 assert not response.is_closed
1199 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
1200
1201 run = await response.parse()
1202 assert_matches_type(Run, run, path=["response"])
1203
1204 assert cast(Any, response.is_closed) is True
1205
1206 @parametrize
1207 async def test_path_params_cancel(self, async_client: AsyncOpenAI) -> None:
1208 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
1209 await async_client.beta.threads.runs.with_raw_response.cancel(
1210 "string",
1211 thread_id="",
1212 )
1213
1214 with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
1215 await async_client.beta.threads.runs.with_raw_response.cancel(
1216 "",
1217 thread_id="string",
1218 )
1219
1220 @parametrize
1221 async def test_method_submit_tool_outputs_overload_1(self, async_client: AsyncOpenAI) -> None:
1222 run = await async_client.beta.threads.runs.submit_tool_outputs(
1223 "string",
1224 thread_id="string",
1225 tool_outputs=[{}, {}, {}],
1226 )
1227 assert_matches_type(Run, run, path=["response"])
1228
1229 @parametrize
1230 async def test_method_submit_tool_outputs_with_all_params_overload_1(self, async_client: AsyncOpenAI) -> None:
1231 run = await async_client.beta.threads.runs.submit_tool_outputs(
1232 "string",
1233 thread_id="string",
1234 tool_outputs=[
1235 {
1236 "output": "output",
1237 "tool_call_id": "tool_call_id",
1238 },
1239 {
1240 "output": "output",
1241 "tool_call_id": "tool_call_id",
1242 },
1243 {
1244 "output": "output",
1245 "tool_call_id": "tool_call_id",
1246 },
1247 ],
1248 stream=False,
1249 )
1250 assert_matches_type(Run, run, path=["response"])
1251
1252 @parametrize
1253 async def test_raw_response_submit_tool_outputs_overload_1(self, async_client: AsyncOpenAI) -> None:
1254 response = await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs(
1255 "string",
1256 thread_id="string",
1257 tool_outputs=[{}, {}, {}],
1258 )
1259
1260 assert response.is_closed is True
1261 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
1262 run = response.parse()
1263 assert_matches_type(Run, run, path=["response"])
1264
1265 @parametrize
1266 async def test_streaming_response_submit_tool_outputs_overload_1(self, async_client: AsyncOpenAI) -> None:
1267 async with async_client.beta.threads.runs.with_streaming_response.submit_tool_outputs(
1268 "string",
1269 thread_id="string",
1270 tool_outputs=[{}, {}, {}],
1271 ) as response:
1272 assert not response.is_closed
1273 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
1274
1275 run = await response.parse()
1276 assert_matches_type(Run, run, path=["response"])
1277
1278 assert cast(Any, response.is_closed) is True
1279
1280 @parametrize
1281 async def test_path_params_submit_tool_outputs_overload_1(self, async_client: AsyncOpenAI) -> None:
1282 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
1283 await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs(
1284 "string",
1285 thread_id="",
1286 tool_outputs=[{}, {}, {}],
1287 )
1288
1289 with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
1290 await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs(
1291 "",
1292 thread_id="string",
1293 tool_outputs=[{}, {}, {}],
1294 )
1295
1296 @parametrize
1297 async def test_method_submit_tool_outputs_overload_2(self, async_client: AsyncOpenAI) -> None:
1298 run_stream = await async_client.beta.threads.runs.submit_tool_outputs(
1299 "string",
1300 thread_id="string",
1301 stream=True,
1302 tool_outputs=[{}, {}, {}],
1303 )
1304 await run_stream.response.aclose()
1305
1306 @parametrize
1307 async def test_raw_response_submit_tool_outputs_overload_2(self, async_client: AsyncOpenAI) -> None:
1308 response = await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs(
1309 "string",
1310 thread_id="string",
1311 stream=True,
1312 tool_outputs=[{}, {}, {}],
1313 )
1314
1315 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
1316 stream = response.parse()
1317 await stream.close()
1318
1319 @parametrize
1320 async def test_streaming_response_submit_tool_outputs_overload_2(self, async_client: AsyncOpenAI) -> None:
1321 async with async_client.beta.threads.runs.with_streaming_response.submit_tool_outputs(
1322 "string",
1323 thread_id="string",
1324 stream=True,
1325 tool_outputs=[{}, {}, {}],
1326 ) as response:
1327 assert not response.is_closed
1328 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
1329
1330 stream = await response.parse()
1331 await stream.close()
1332
1333 assert cast(Any, response.is_closed) is True
1334
1335 @parametrize
1336 async def test_path_params_submit_tool_outputs_overload_2(self, async_client: AsyncOpenAI) -> None:
1337 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
1338 await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs(
1339 "string",
1340 thread_id="",
1341 stream=True,
1342 tool_outputs=[{}, {}, {}],
1343 )
1344
1345 with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
1346 await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs(
1347 "",
1348 thread_id="string",
1349 stream=True,
1350 tool_outputs=[{}, {}, {}],
1351 )
1352