openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.23.6

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/beta/threads/test_runs.py

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