openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.63.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

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