openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
fix-api-correct-some-responses-t

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/beta/threads/test_runs.py

1013lines · modecode

1# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
3from __future__ import annotations
4
5import os
6from typing import Any, cast
7
8import pytest
9
10from openai import OpenAI, AsyncOpenAI
11from tests.utils import assert_matches_type
12from openai.pagination import SyncCursorPage, AsyncCursorPage
13from openai.types.beta.threads import (
14 Run,
15)
16
17base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
18
19
20class TestRuns:
21 parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
22
23 @parametrize
24 def test_method_create_overload_1(self, client: OpenAI) -> None:
25 run = client.beta.threads.runs.create(
26 thread_id="thread_id",
27 assistant_id="assistant_id",
28 )
29 assert_matches_type(Run, run, path=["response"])
30
31 @parametrize
32 def test_method_create_with_all_params_overload_1(self, client: OpenAI) -> None:
33 run = client.beta.threads.runs.create(
34 thread_id="thread_id",
35 assistant_id="assistant_id",
36 include=["step_details.tool_calls[*].file_search.results[*].content"],
37 additional_instructions="additional_instructions",
38 additional_messages=[
39 {
40 "content": "string",
41 "role": "user",
42 "attachments": [
43 {
44 "file_id": "file_id",
45 "tools": [{"type": "code_interpreter"}],
46 }
47 ],
48 "metadata": {"foo": "string"},
49 }
50 ],
51 instructions="instructions",
52 max_completion_tokens=256,
53 max_prompt_tokens=256,
54 metadata={"foo": "string"},
55 model="gpt-4o",
56 parallel_tool_calls=True,
57 reasoning_effort="low",
58 response_format="auto",
59 stream=False,
60 temperature=1,
61 tool_choice="none",
62 tools=[{"type": "code_interpreter"}],
63 top_p=1,
64 truncation_strategy={
65 "type": "auto",
66 "last_messages": 1,
67 },
68 )
69 assert_matches_type(Run, run, path=["response"])
70
71 @parametrize
72 def test_raw_response_create_overload_1(self, client: OpenAI) -> None:
73 response = client.beta.threads.runs.with_raw_response.create(
74 thread_id="thread_id",
75 assistant_id="assistant_id",
76 )
77
78 assert response.is_closed is True
79 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
80 run = response.parse()
81 assert_matches_type(Run, run, path=["response"])
82
83 @parametrize
84 def test_streaming_response_create_overload_1(self, client: OpenAI) -> None:
85 with client.beta.threads.runs.with_streaming_response.create(
86 thread_id="thread_id",
87 assistant_id="assistant_id",
88 ) as response:
89 assert not response.is_closed
90 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
91
92 run = response.parse()
93 assert_matches_type(Run, run, path=["response"])
94
95 assert cast(Any, response.is_closed) is True
96
97 @parametrize
98 def test_path_params_create_overload_1(self, client: OpenAI) -> None:
99 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
100 client.beta.threads.runs.with_raw_response.create(
101 thread_id="",
102 assistant_id="assistant_id",
103 )
104
105 @parametrize
106 def test_method_create_overload_2(self, client: OpenAI) -> None:
107 run_stream = client.beta.threads.runs.create(
108 thread_id="thread_id",
109 assistant_id="assistant_id",
110 stream=True,
111 )
112 run_stream.response.close()
113
114 @parametrize
115 def test_method_create_with_all_params_overload_2(self, client: OpenAI) -> None:
116 run_stream = client.beta.threads.runs.create(
117 thread_id="thread_id",
118 assistant_id="assistant_id",
119 stream=True,
120 include=["step_details.tool_calls[*].file_search.results[*].content"],
121 additional_instructions="additional_instructions",
122 additional_messages=[
123 {
124 "content": "string",
125 "role": "user",
126 "attachments": [
127 {
128 "file_id": "file_id",
129 "tools": [{"type": "code_interpreter"}],
130 }
131 ],
132 "metadata": {"foo": "string"},
133 }
134 ],
135 instructions="instructions",
136 max_completion_tokens=256,
137 max_prompt_tokens=256,
138 metadata={"foo": "string"},
139 model="gpt-4o",
140 parallel_tool_calls=True,
141 reasoning_effort="low",
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 thread_id="thread_id",
158 assistant_id="assistant_id",
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 thread_id="thread_id",
170 assistant_id="assistant_id",
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 thread_id="",
186 assistant_id="assistant_id",
187 stream=True,
188 )
189
190 @parametrize
191 def test_method_retrieve(self, client: OpenAI) -> None:
192 run = client.beta.threads.runs.retrieve(
193 run_id="run_id",
194 thread_id="thread_id",
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 run_id="run_id",
202 thread_id="thread_id",
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 run_id="run_id",
214 thread_id="thread_id",
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 run_id="run_id",
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 run_id="",
235 thread_id="thread_id",
236 )
237
238 @parametrize
239 def test_method_update(self, client: OpenAI) -> None:
240 run = client.beta.threads.runs.update(
241 run_id="run_id",
242 thread_id="thread_id",
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 run_id="run_id",
259 thread_id="thread_id",
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 run_id="run_id",
271 thread_id="thread_id",
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 run_id="run_id",
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 run_id="",
292 thread_id="thread_id",
293 )
294
295 @parametrize
296 def test_method_list(self, client: OpenAI) -> None:
297 run = client.beta.threads.runs.list(
298 thread_id="thread_id",
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 thread_id="thread_id",
306 after="after",
307 before="before",
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 thread_id="thread_id",
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 thread_id="thread_id",
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 thread_id="",
342 )
343
344 @parametrize
345 def test_method_cancel(self, client: OpenAI) -> None:
346 run = client.beta.threads.runs.cancel(
347 run_id="run_id",
348 thread_id="thread_id",
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 run_id="run_id",
356 thread_id="thread_id",
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 run_id="run_id",
368 thread_id="thread_id",
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 run_id="run_id",
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 run_id="",
389 thread_id="thread_id",
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 run_id="run_id",
405 thread_id="thread_id",
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 run_id="run_id",
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 run_id="run_id",
464 thread_id="thread_id",
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 run_id="run_id",
474 thread_id="thread_id",
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 run_id="run_id",
487 thread_id="thread_id",
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 run_id="run_id",
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 run_id="",
512 thread_id="thread_id",
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 thread_id="thread_id",
525 assistant_id="assistant_id",
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="instructions",
550 max_completion_tokens=256,
551 max_prompt_tokens=256,
552 metadata={"foo": "string"},
553 model="gpt-4o",
554 parallel_tool_calls=True,
555 reasoning_effort="low",
556 response_format="auto",
557 stream=False,
558 temperature=1,
559 tool_choice="none",
560 tools=[{"type": "code_interpreter"}],
561 top_p=1,
562 truncation_strategy={
563 "type": "auto",
564 "last_messages": 1,
565 },
566 )
567 assert_matches_type(Run, run, path=["response"])
568
569 @parametrize
570 async def test_raw_response_create_overload_1(self, async_client: AsyncOpenAI) -> None:
571 response = await async_client.beta.threads.runs.with_raw_response.create(
572 thread_id="thread_id",
573 assistant_id="assistant_id",
574 )
575
576 assert response.is_closed is True
577 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
578 run = response.parse()
579 assert_matches_type(Run, run, path=["response"])
580
581 @parametrize
582 async def test_streaming_response_create_overload_1(self, async_client: AsyncOpenAI) -> None:
583 async with async_client.beta.threads.runs.with_streaming_response.create(
584 thread_id="thread_id",
585 assistant_id="assistant_id",
586 ) as response:
587 assert not response.is_closed
588 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
589
590 run = await response.parse()
591 assert_matches_type(Run, run, path=["response"])
592
593 assert cast(Any, response.is_closed) is True
594
595 @parametrize
596 async def test_path_params_create_overload_1(self, async_client: AsyncOpenAI) -> None:
597 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
598 await async_client.beta.threads.runs.with_raw_response.create(
599 thread_id="",
600 assistant_id="assistant_id",
601 )
602
603 @parametrize
604 async def test_method_create_overload_2(self, async_client: AsyncOpenAI) -> None:
605 run_stream = await async_client.beta.threads.runs.create(
606 thread_id="thread_id",
607 assistant_id="assistant_id",
608 stream=True,
609 )
610 await run_stream.response.aclose()
611
612 @parametrize
613 async def test_method_create_with_all_params_overload_2(self, async_client: AsyncOpenAI) -> None:
614 run_stream = await async_client.beta.threads.runs.create(
615 thread_id="thread_id",
616 assistant_id="assistant_id",
617 stream=True,
618 include=["step_details.tool_calls[*].file_search.results[*].content"],
619 additional_instructions="additional_instructions",
620 additional_messages=[
621 {
622 "content": "string",
623 "role": "user",
624 "attachments": [
625 {
626 "file_id": "file_id",
627 "tools": [{"type": "code_interpreter"}],
628 }
629 ],
630 "metadata": {"foo": "string"},
631 }
632 ],
633 instructions="instructions",
634 max_completion_tokens=256,
635 max_prompt_tokens=256,
636 metadata={"foo": "string"},
637 model="gpt-4o",
638 parallel_tool_calls=True,
639 reasoning_effort="low",
640 response_format="auto",
641 temperature=1,
642 tool_choice="none",
643 tools=[{"type": "code_interpreter"}],
644 top_p=1,
645 truncation_strategy={
646 "type": "auto",
647 "last_messages": 1,
648 },
649 )
650 await run_stream.response.aclose()
651
652 @parametrize
653 async def test_raw_response_create_overload_2(self, async_client: AsyncOpenAI) -> None:
654 response = await async_client.beta.threads.runs.with_raw_response.create(
655 thread_id="thread_id",
656 assistant_id="assistant_id",
657 stream=True,
658 )
659
660 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
661 stream = response.parse()
662 await stream.close()
663
664 @parametrize
665 async def test_streaming_response_create_overload_2(self, async_client: AsyncOpenAI) -> None:
666 async with async_client.beta.threads.runs.with_streaming_response.create(
667 thread_id="thread_id",
668 assistant_id="assistant_id",
669 stream=True,
670 ) as response:
671 assert not response.is_closed
672 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
673
674 stream = await response.parse()
675 await stream.close()
676
677 assert cast(Any, response.is_closed) is True
678
679 @parametrize
680 async def test_path_params_create_overload_2(self, async_client: AsyncOpenAI) -> None:
681 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
682 await async_client.beta.threads.runs.with_raw_response.create(
683 thread_id="",
684 assistant_id="assistant_id",
685 stream=True,
686 )
687
688 @parametrize
689 async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None:
690 run = await async_client.beta.threads.runs.retrieve(
691 run_id="run_id",
692 thread_id="thread_id",
693 )
694 assert_matches_type(Run, run, path=["response"])
695
696 @parametrize
697 async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None:
698 response = await async_client.beta.threads.runs.with_raw_response.retrieve(
699 run_id="run_id",
700 thread_id="thread_id",
701 )
702
703 assert response.is_closed is True
704 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
705 run = response.parse()
706 assert_matches_type(Run, run, path=["response"])
707
708 @parametrize
709 async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None:
710 async with async_client.beta.threads.runs.with_streaming_response.retrieve(
711 run_id="run_id",
712 thread_id="thread_id",
713 ) as response:
714 assert not response.is_closed
715 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
716
717 run = await response.parse()
718 assert_matches_type(Run, run, path=["response"])
719
720 assert cast(Any, response.is_closed) is True
721
722 @parametrize
723 async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None:
724 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
725 await async_client.beta.threads.runs.with_raw_response.retrieve(
726 run_id="run_id",
727 thread_id="",
728 )
729
730 with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
731 await async_client.beta.threads.runs.with_raw_response.retrieve(
732 run_id="",
733 thread_id="thread_id",
734 )
735
736 @parametrize
737 async def test_method_update(self, async_client: AsyncOpenAI) -> None:
738 run = await async_client.beta.threads.runs.update(
739 run_id="run_id",
740 thread_id="thread_id",
741 )
742 assert_matches_type(Run, run, path=["response"])
743
744 @parametrize
745 async def test_method_update_with_all_params(self, async_client: AsyncOpenAI) -> None:
746 run = await async_client.beta.threads.runs.update(
747 run_id="run_id",
748 thread_id="thread_id",
749 metadata={"foo": "string"},
750 )
751 assert_matches_type(Run, run, path=["response"])
752
753 @parametrize
754 async def test_raw_response_update(self, async_client: AsyncOpenAI) -> None:
755 response = await async_client.beta.threads.runs.with_raw_response.update(
756 run_id="run_id",
757 thread_id="thread_id",
758 )
759
760 assert response.is_closed is True
761 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
762 run = response.parse()
763 assert_matches_type(Run, run, path=["response"])
764
765 @parametrize
766 async def test_streaming_response_update(self, async_client: AsyncOpenAI) -> None:
767 async with async_client.beta.threads.runs.with_streaming_response.update(
768 run_id="run_id",
769 thread_id="thread_id",
770 ) as response:
771 assert not response.is_closed
772 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
773
774 run = await response.parse()
775 assert_matches_type(Run, run, path=["response"])
776
777 assert cast(Any, response.is_closed) is True
778
779 @parametrize
780 async def test_path_params_update(self, async_client: AsyncOpenAI) -> None:
781 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
782 await async_client.beta.threads.runs.with_raw_response.update(
783 run_id="run_id",
784 thread_id="",
785 )
786
787 with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
788 await async_client.beta.threads.runs.with_raw_response.update(
789 run_id="",
790 thread_id="thread_id",
791 )
792
793 @parametrize
794 async def test_method_list(self, async_client: AsyncOpenAI) -> None:
795 run = await async_client.beta.threads.runs.list(
796 thread_id="thread_id",
797 )
798 assert_matches_type(AsyncCursorPage[Run], run, path=["response"])
799
800 @parametrize
801 async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> None:
802 run = await async_client.beta.threads.runs.list(
803 thread_id="thread_id",
804 after="after",
805 before="before",
806 limit=0,
807 order="asc",
808 )
809 assert_matches_type(AsyncCursorPage[Run], run, path=["response"])
810
811 @parametrize
812 async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None:
813 response = await async_client.beta.threads.runs.with_raw_response.list(
814 thread_id="thread_id",
815 )
816
817 assert response.is_closed is True
818 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
819 run = response.parse()
820 assert_matches_type(AsyncCursorPage[Run], run, path=["response"])
821
822 @parametrize
823 async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None:
824 async with async_client.beta.threads.runs.with_streaming_response.list(
825 thread_id="thread_id",
826 ) as response:
827 assert not response.is_closed
828 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
829
830 run = await response.parse()
831 assert_matches_type(AsyncCursorPage[Run], run, path=["response"])
832
833 assert cast(Any, response.is_closed) is True
834
835 @parametrize
836 async def test_path_params_list(self, async_client: AsyncOpenAI) -> None:
837 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
838 await async_client.beta.threads.runs.with_raw_response.list(
839 thread_id="",
840 )
841
842 @parametrize
843 async def test_method_cancel(self, async_client: AsyncOpenAI) -> None:
844 run = await async_client.beta.threads.runs.cancel(
845 run_id="run_id",
846 thread_id="thread_id",
847 )
848 assert_matches_type(Run, run, path=["response"])
849
850 @parametrize
851 async def test_raw_response_cancel(self, async_client: AsyncOpenAI) -> None:
852 response = await async_client.beta.threads.runs.with_raw_response.cancel(
853 run_id="run_id",
854 thread_id="thread_id",
855 )
856
857 assert response.is_closed is True
858 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
859 run = response.parse()
860 assert_matches_type(Run, run, path=["response"])
861
862 @parametrize
863 async def test_streaming_response_cancel(self, async_client: AsyncOpenAI) -> None:
864 async with async_client.beta.threads.runs.with_streaming_response.cancel(
865 run_id="run_id",
866 thread_id="thread_id",
867 ) as response:
868 assert not response.is_closed
869 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
870
871 run = await response.parse()
872 assert_matches_type(Run, run, path=["response"])
873
874 assert cast(Any, response.is_closed) is True
875
876 @parametrize
877 async def test_path_params_cancel(self, async_client: AsyncOpenAI) -> None:
878 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
879 await async_client.beta.threads.runs.with_raw_response.cancel(
880 run_id="run_id",
881 thread_id="",
882 )
883
884 with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
885 await async_client.beta.threads.runs.with_raw_response.cancel(
886 run_id="",
887 thread_id="thread_id",
888 )
889
890 @parametrize
891 async def test_method_submit_tool_outputs_overload_1(self, async_client: AsyncOpenAI) -> None:
892 run = await async_client.beta.threads.runs.submit_tool_outputs(
893 run_id="run_id",
894 thread_id="thread_id",
895 tool_outputs=[{}],
896 )
897 assert_matches_type(Run, run, path=["response"])
898
899 @parametrize
900 async def test_method_submit_tool_outputs_with_all_params_overload_1(self, async_client: AsyncOpenAI) -> None:
901 run = await async_client.beta.threads.runs.submit_tool_outputs(
902 run_id="run_id",
903 thread_id="thread_id",
904 tool_outputs=[
905 {
906 "output": "output",
907 "tool_call_id": "tool_call_id",
908 }
909 ],
910 stream=False,
911 )
912 assert_matches_type(Run, run, path=["response"])
913
914 @parametrize
915 async def test_raw_response_submit_tool_outputs_overload_1(self, async_client: AsyncOpenAI) -> None:
916 response = await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs(
917 run_id="run_id",
918 thread_id="thread_id",
919 tool_outputs=[{}],
920 )
921
922 assert response.is_closed is True
923 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
924 run = response.parse()
925 assert_matches_type(Run, run, path=["response"])
926
927 @parametrize
928 async def test_streaming_response_submit_tool_outputs_overload_1(self, async_client: AsyncOpenAI) -> None:
929 async with async_client.beta.threads.runs.with_streaming_response.submit_tool_outputs(
930 run_id="run_id",
931 thread_id="thread_id",
932 tool_outputs=[{}],
933 ) as response:
934 assert not response.is_closed
935 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
936
937 run = await response.parse()
938 assert_matches_type(Run, run, path=["response"])
939
940 assert cast(Any, response.is_closed) is True
941
942 @parametrize
943 async def test_path_params_submit_tool_outputs_overload_1(self, async_client: AsyncOpenAI) -> None:
944 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
945 await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs(
946 run_id="run_id",
947 thread_id="",
948 tool_outputs=[{}],
949 )
950
951 with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
952 await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs(
953 run_id="",
954 thread_id="thread_id",
955 tool_outputs=[{}],
956 )
957
958 @parametrize
959 async def test_method_submit_tool_outputs_overload_2(self, async_client: AsyncOpenAI) -> None:
960 run_stream = await async_client.beta.threads.runs.submit_tool_outputs(
961 run_id="run_id",
962 thread_id="thread_id",
963 stream=True,
964 tool_outputs=[{}],
965 )
966 await run_stream.response.aclose()
967
968 @parametrize
969 async def test_raw_response_submit_tool_outputs_overload_2(self, async_client: AsyncOpenAI) -> None:
970 response = await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs(
971 run_id="run_id",
972 thread_id="thread_id",
973 stream=True,
974 tool_outputs=[{}],
975 )
976
977 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
978 stream = response.parse()
979 await stream.close()
980
981 @parametrize
982 async def test_streaming_response_submit_tool_outputs_overload_2(self, async_client: AsyncOpenAI) -> None:
983 async with async_client.beta.threads.runs.with_streaming_response.submit_tool_outputs(
984 run_id="run_id",
985 thread_id="thread_id",
986 stream=True,
987 tool_outputs=[{}],
988 ) as response:
989 assert not response.is_closed
990 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
991
992 stream = await response.parse()
993 await stream.close()
994
995 assert cast(Any, response.is_closed) is True
996
997 @parametrize
998 async def test_path_params_submit_tool_outputs_overload_2(self, async_client: AsyncOpenAI) -> None:
999 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
1000 await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs(
1001 run_id="run_id",
1002 thread_id="",
1003 stream=True,
1004 tool_outputs=[{}],
1005 )
1006
1007 with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
1008 await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs(
1009 run_id="",
1010 thread_id="thread_id",
1011 stream=True,
1012 tool_outputs=[{}],
1013 )
1014