openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
e279088e935519bfef005adfcb180e868a25682d

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/beta/threads/test_runs.py

1349lines · modecode

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