openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.86.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/beta/threads/test_runs.py

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