openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
dfdcf571ced31f7859cd1871be39e2fb3af6bafa

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/beta/threads/test_runs.py

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