openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.61.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/beta/threads/test_runs.py

1011lines · modecode

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