openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
62069d2f3304c74374e8de99c69217f9f03e98c3

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/beta/test_threads.py

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