openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.23.6

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/beta/test_threads.py

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