openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.21.2

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/beta/threads/test_runs.py

1203lines · modecode

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