openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
13200876f6635286dcb4943e990cc5e279545787

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/beta/threads/test_runs.py

1353lines · modecode

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