openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
c5481ef180d874513cfe85c20ec6cd2cfdd0ce47

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/chat/test_completions.py

868lines · 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.chat import (
14 ChatCompletion,
15 ChatCompletionDeleted,
16)
17
18base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
19
20
21class TestCompletions:
22 parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
23
24 @parametrize
25 def test_method_create_overload_1(self, client: OpenAI) -> None:
26 completion = client.chat.completions.create(
27 messages=[
28 {
29 "content": "string",
30 "role": "developer",
31 }
32 ],
33 model="gpt-4o",
34 )
35 assert_matches_type(ChatCompletion, completion, path=["response"])
36
37 @parametrize
38 def test_method_create_with_all_params_overload_1(self, client: OpenAI) -> None:
39 completion = client.chat.completions.create(
40 messages=[
41 {
42 "content": "string",
43 "role": "developer",
44 "name": "name",
45 }
46 ],
47 model="gpt-4o",
48 audio={
49 "format": "wav",
50 "voice": "ash",
51 },
52 frequency_penalty=-2,
53 function_call="none",
54 functions=[
55 {
56 "name": "name",
57 "description": "description",
58 "parameters": {"foo": "bar"},
59 }
60 ],
61 logit_bias={"foo": 0},
62 logprobs=True,
63 max_completion_tokens=0,
64 max_tokens=0,
65 metadata={"foo": "string"},
66 modalities=["text"],
67 n=1,
68 parallel_tool_calls=True,
69 prediction={
70 "content": "string",
71 "type": "content",
72 },
73 presence_penalty=-2,
74 prompt_cache_key="prompt-cache-key-1234",
75 prompt_cache_retention="in-memory",
76 reasoning_effort="none",
77 response_format={"type": "text"},
78 safety_identifier="safety-identifier-1234",
79 seed=-9007199254740991,
80 service_tier="auto",
81 stop="\n",
82 store=True,
83 stream=False,
84 stream_options={
85 "include_obfuscation": True,
86 "include_usage": True,
87 },
88 temperature=1,
89 tool_choice="none",
90 tools=[
91 {
92 "function": {
93 "name": "name",
94 "description": "description",
95 "parameters": {"foo": "bar"},
96 "strict": True,
97 },
98 "type": "function",
99 }
100 ],
101 top_logprobs=0,
102 top_p=1,
103 user="user-1234",
104 verbosity="low",
105 web_search_options={
106 "search_context_size": "low",
107 "user_location": {
108 "approximate": {
109 "city": "city",
110 "country": "country",
111 "region": "region",
112 "timezone": "timezone",
113 },
114 "type": "approximate",
115 },
116 },
117 )
118 assert_matches_type(ChatCompletion, completion, path=["response"])
119
120 @parametrize
121 def test_raw_response_create_overload_1(self, client: OpenAI) -> None:
122 response = client.chat.completions.with_raw_response.create(
123 messages=[
124 {
125 "content": "string",
126 "role": "developer",
127 }
128 ],
129 model="gpt-4o",
130 )
131
132 assert response.is_closed is True
133 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
134 completion = response.parse()
135 assert_matches_type(ChatCompletion, completion, path=["response"])
136
137 @parametrize
138 def test_streaming_response_create_overload_1(self, client: OpenAI) -> None:
139 with client.chat.completions.with_streaming_response.create(
140 messages=[
141 {
142 "content": "string",
143 "role": "developer",
144 }
145 ],
146 model="gpt-4o",
147 ) as response:
148 assert not response.is_closed
149 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
150
151 completion = response.parse()
152 assert_matches_type(ChatCompletion, completion, path=["response"])
153
154 assert cast(Any, response.is_closed) is True
155
156 @parametrize
157 def test_method_create_overload_2(self, client: OpenAI) -> None:
158 completion_stream = client.chat.completions.create(
159 messages=[
160 {
161 "content": "string",
162 "role": "developer",
163 }
164 ],
165 model="gpt-4o",
166 stream=True,
167 )
168 completion_stream.response.close()
169
170 @parametrize
171 def test_method_create_with_all_params_overload_2(self, client: OpenAI) -> None:
172 completion_stream = client.chat.completions.create(
173 messages=[
174 {
175 "content": "string",
176 "role": "developer",
177 "name": "name",
178 }
179 ],
180 model="gpt-4o",
181 stream=True,
182 audio={
183 "format": "wav",
184 "voice": "ash",
185 },
186 frequency_penalty=-2,
187 function_call="none",
188 functions=[
189 {
190 "name": "name",
191 "description": "description",
192 "parameters": {"foo": "bar"},
193 }
194 ],
195 logit_bias={"foo": 0},
196 logprobs=True,
197 max_completion_tokens=0,
198 max_tokens=0,
199 metadata={"foo": "string"},
200 modalities=["text"],
201 n=1,
202 parallel_tool_calls=True,
203 prediction={
204 "content": "string",
205 "type": "content",
206 },
207 presence_penalty=-2,
208 prompt_cache_key="prompt-cache-key-1234",
209 prompt_cache_retention="in-memory",
210 reasoning_effort="none",
211 response_format={"type": "text"},
212 safety_identifier="safety-identifier-1234",
213 seed=-9007199254740991,
214 service_tier="auto",
215 stop="\n",
216 store=True,
217 stream_options={
218 "include_obfuscation": True,
219 "include_usage": True,
220 },
221 temperature=1,
222 tool_choice="none",
223 tools=[
224 {
225 "function": {
226 "name": "name",
227 "description": "description",
228 "parameters": {"foo": "bar"},
229 "strict": True,
230 },
231 "type": "function",
232 }
233 ],
234 top_logprobs=0,
235 top_p=1,
236 user="user-1234",
237 verbosity="low",
238 web_search_options={
239 "search_context_size": "low",
240 "user_location": {
241 "approximate": {
242 "city": "city",
243 "country": "country",
244 "region": "region",
245 "timezone": "timezone",
246 },
247 "type": "approximate",
248 },
249 },
250 )
251 completion_stream.response.close()
252
253 @parametrize
254 def test_raw_response_create_overload_2(self, client: OpenAI) -> None:
255 response = client.chat.completions.with_raw_response.create(
256 messages=[
257 {
258 "content": "string",
259 "role": "developer",
260 }
261 ],
262 model="gpt-4o",
263 stream=True,
264 )
265
266 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
267 stream = response.parse()
268 stream.close()
269
270 @parametrize
271 def test_streaming_response_create_overload_2(self, client: OpenAI) -> None:
272 with client.chat.completions.with_streaming_response.create(
273 messages=[
274 {
275 "content": "string",
276 "role": "developer",
277 }
278 ],
279 model="gpt-4o",
280 stream=True,
281 ) as response:
282 assert not response.is_closed
283 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
284
285 stream = response.parse()
286 stream.close()
287
288 assert cast(Any, response.is_closed) is True
289
290 @parametrize
291 def test_method_retrieve(self, client: OpenAI) -> None:
292 completion = client.chat.completions.retrieve(
293 "completion_id",
294 )
295 assert_matches_type(ChatCompletion, completion, path=["response"])
296
297 @parametrize
298 def test_raw_response_retrieve(self, client: OpenAI) -> None:
299 response = client.chat.completions.with_raw_response.retrieve(
300 "completion_id",
301 )
302
303 assert response.is_closed is True
304 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
305 completion = response.parse()
306 assert_matches_type(ChatCompletion, completion, path=["response"])
307
308 @parametrize
309 def test_streaming_response_retrieve(self, client: OpenAI) -> None:
310 with client.chat.completions.with_streaming_response.retrieve(
311 "completion_id",
312 ) as response:
313 assert not response.is_closed
314 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
315
316 completion = response.parse()
317 assert_matches_type(ChatCompletion, completion, path=["response"])
318
319 assert cast(Any, response.is_closed) is True
320
321 @parametrize
322 def test_path_params_retrieve(self, client: OpenAI) -> None:
323 with pytest.raises(ValueError, match=r"Expected a non-empty value for `completion_id` but received ''"):
324 client.chat.completions.with_raw_response.retrieve(
325 "",
326 )
327
328 @parametrize
329 def test_method_update(self, client: OpenAI) -> None:
330 completion = client.chat.completions.update(
331 completion_id="completion_id",
332 metadata={"foo": "string"},
333 )
334 assert_matches_type(ChatCompletion, completion, path=["response"])
335
336 @parametrize
337 def test_raw_response_update(self, client: OpenAI) -> None:
338 response = client.chat.completions.with_raw_response.update(
339 completion_id="completion_id",
340 metadata={"foo": "string"},
341 )
342
343 assert response.is_closed is True
344 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
345 completion = response.parse()
346 assert_matches_type(ChatCompletion, completion, path=["response"])
347
348 @parametrize
349 def test_streaming_response_update(self, client: OpenAI) -> None:
350 with client.chat.completions.with_streaming_response.update(
351 completion_id="completion_id",
352 metadata={"foo": "string"},
353 ) as response:
354 assert not response.is_closed
355 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
356
357 completion = response.parse()
358 assert_matches_type(ChatCompletion, completion, path=["response"])
359
360 assert cast(Any, response.is_closed) is True
361
362 @parametrize
363 def test_path_params_update(self, client: OpenAI) -> None:
364 with pytest.raises(ValueError, match=r"Expected a non-empty value for `completion_id` but received ''"):
365 client.chat.completions.with_raw_response.update(
366 completion_id="",
367 metadata={"foo": "string"},
368 )
369
370 @parametrize
371 def test_method_list(self, client: OpenAI) -> None:
372 completion = client.chat.completions.list()
373 assert_matches_type(SyncCursorPage[ChatCompletion], completion, path=["response"])
374
375 @parametrize
376 def test_method_list_with_all_params(self, client: OpenAI) -> None:
377 completion = client.chat.completions.list(
378 after="after",
379 limit=0,
380 metadata={"foo": "string"},
381 model="model",
382 order="asc",
383 )
384 assert_matches_type(SyncCursorPage[ChatCompletion], completion, path=["response"])
385
386 @parametrize
387 def test_raw_response_list(self, client: OpenAI) -> None:
388 response = client.chat.completions.with_raw_response.list()
389
390 assert response.is_closed is True
391 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
392 completion = response.parse()
393 assert_matches_type(SyncCursorPage[ChatCompletion], completion, path=["response"])
394
395 @parametrize
396 def test_streaming_response_list(self, client: OpenAI) -> None:
397 with client.chat.completions.with_streaming_response.list() as response:
398 assert not response.is_closed
399 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
400
401 completion = response.parse()
402 assert_matches_type(SyncCursorPage[ChatCompletion], completion, path=["response"])
403
404 assert cast(Any, response.is_closed) is True
405
406 @parametrize
407 def test_method_delete(self, client: OpenAI) -> None:
408 completion = client.chat.completions.delete(
409 "completion_id",
410 )
411 assert_matches_type(ChatCompletionDeleted, completion, path=["response"])
412
413 @parametrize
414 def test_raw_response_delete(self, client: OpenAI) -> None:
415 response = client.chat.completions.with_raw_response.delete(
416 "completion_id",
417 )
418
419 assert response.is_closed is True
420 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
421 completion = response.parse()
422 assert_matches_type(ChatCompletionDeleted, completion, path=["response"])
423
424 @parametrize
425 def test_streaming_response_delete(self, client: OpenAI) -> None:
426 with client.chat.completions.with_streaming_response.delete(
427 "completion_id",
428 ) as response:
429 assert not response.is_closed
430 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
431
432 completion = response.parse()
433 assert_matches_type(ChatCompletionDeleted, completion, path=["response"])
434
435 assert cast(Any, response.is_closed) is True
436
437 @parametrize
438 def test_path_params_delete(self, client: OpenAI) -> None:
439 with pytest.raises(ValueError, match=r"Expected a non-empty value for `completion_id` but received ''"):
440 client.chat.completions.with_raw_response.delete(
441 "",
442 )
443
444
445class TestAsyncCompletions:
446 parametrize = pytest.mark.parametrize(
447 "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
448 )
449
450 @parametrize
451 async def test_method_create_overload_1(self, async_client: AsyncOpenAI) -> None:
452 completion = await async_client.chat.completions.create(
453 messages=[
454 {
455 "content": "string",
456 "role": "developer",
457 }
458 ],
459 model="gpt-4o",
460 )
461 assert_matches_type(ChatCompletion, completion, path=["response"])
462
463 @parametrize
464 async def test_method_create_with_all_params_overload_1(self, async_client: AsyncOpenAI) -> None:
465 completion = await async_client.chat.completions.create(
466 messages=[
467 {
468 "content": "string",
469 "role": "developer",
470 "name": "name",
471 }
472 ],
473 model="gpt-4o",
474 audio={
475 "format": "wav",
476 "voice": "ash",
477 },
478 frequency_penalty=-2,
479 function_call="none",
480 functions=[
481 {
482 "name": "name",
483 "description": "description",
484 "parameters": {"foo": "bar"},
485 }
486 ],
487 logit_bias={"foo": 0},
488 logprobs=True,
489 max_completion_tokens=0,
490 max_tokens=0,
491 metadata={"foo": "string"},
492 modalities=["text"],
493 n=1,
494 parallel_tool_calls=True,
495 prediction={
496 "content": "string",
497 "type": "content",
498 },
499 presence_penalty=-2,
500 prompt_cache_key="prompt-cache-key-1234",
501 prompt_cache_retention="in-memory",
502 reasoning_effort="none",
503 response_format={"type": "text"},
504 safety_identifier="safety-identifier-1234",
505 seed=-9007199254740991,
506 service_tier="auto",
507 stop="\n",
508 store=True,
509 stream=False,
510 stream_options={
511 "include_obfuscation": True,
512 "include_usage": True,
513 },
514 temperature=1,
515 tool_choice="none",
516 tools=[
517 {
518 "function": {
519 "name": "name",
520 "description": "description",
521 "parameters": {"foo": "bar"},
522 "strict": True,
523 },
524 "type": "function",
525 }
526 ],
527 top_logprobs=0,
528 top_p=1,
529 user="user-1234",
530 verbosity="low",
531 web_search_options={
532 "search_context_size": "low",
533 "user_location": {
534 "approximate": {
535 "city": "city",
536 "country": "country",
537 "region": "region",
538 "timezone": "timezone",
539 },
540 "type": "approximate",
541 },
542 },
543 )
544 assert_matches_type(ChatCompletion, completion, path=["response"])
545
546 @parametrize
547 async def test_raw_response_create_overload_1(self, async_client: AsyncOpenAI) -> None:
548 response = await async_client.chat.completions.with_raw_response.create(
549 messages=[
550 {
551 "content": "string",
552 "role": "developer",
553 }
554 ],
555 model="gpt-4o",
556 )
557
558 assert response.is_closed is True
559 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
560 completion = response.parse()
561 assert_matches_type(ChatCompletion, completion, path=["response"])
562
563 @parametrize
564 async def test_streaming_response_create_overload_1(self, async_client: AsyncOpenAI) -> None:
565 async with async_client.chat.completions.with_streaming_response.create(
566 messages=[
567 {
568 "content": "string",
569 "role": "developer",
570 }
571 ],
572 model="gpt-4o",
573 ) as response:
574 assert not response.is_closed
575 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
576
577 completion = await response.parse()
578 assert_matches_type(ChatCompletion, completion, path=["response"])
579
580 assert cast(Any, response.is_closed) is True
581
582 @parametrize
583 async def test_method_create_overload_2(self, async_client: AsyncOpenAI) -> None:
584 completion_stream = await async_client.chat.completions.create(
585 messages=[
586 {
587 "content": "string",
588 "role": "developer",
589 }
590 ],
591 model="gpt-4o",
592 stream=True,
593 )
594 await completion_stream.response.aclose()
595
596 @parametrize
597 async def test_method_create_with_all_params_overload_2(self, async_client: AsyncOpenAI) -> None:
598 completion_stream = await async_client.chat.completions.create(
599 messages=[
600 {
601 "content": "string",
602 "role": "developer",
603 "name": "name",
604 }
605 ],
606 model="gpt-4o",
607 stream=True,
608 audio={
609 "format": "wav",
610 "voice": "ash",
611 },
612 frequency_penalty=-2,
613 function_call="none",
614 functions=[
615 {
616 "name": "name",
617 "description": "description",
618 "parameters": {"foo": "bar"},
619 }
620 ],
621 logit_bias={"foo": 0},
622 logprobs=True,
623 max_completion_tokens=0,
624 max_tokens=0,
625 metadata={"foo": "string"},
626 modalities=["text"],
627 n=1,
628 parallel_tool_calls=True,
629 prediction={
630 "content": "string",
631 "type": "content",
632 },
633 presence_penalty=-2,
634 prompt_cache_key="prompt-cache-key-1234",
635 prompt_cache_retention="in-memory",
636 reasoning_effort="none",
637 response_format={"type": "text"},
638 safety_identifier="safety-identifier-1234",
639 seed=-9007199254740991,
640 service_tier="auto",
641 stop="\n",
642 store=True,
643 stream_options={
644 "include_obfuscation": True,
645 "include_usage": True,
646 },
647 temperature=1,
648 tool_choice="none",
649 tools=[
650 {
651 "function": {
652 "name": "name",
653 "description": "description",
654 "parameters": {"foo": "bar"},
655 "strict": True,
656 },
657 "type": "function",
658 }
659 ],
660 top_logprobs=0,
661 top_p=1,
662 user="user-1234",
663 verbosity="low",
664 web_search_options={
665 "search_context_size": "low",
666 "user_location": {
667 "approximate": {
668 "city": "city",
669 "country": "country",
670 "region": "region",
671 "timezone": "timezone",
672 },
673 "type": "approximate",
674 },
675 },
676 )
677 await completion_stream.response.aclose()
678
679 @parametrize
680 async def test_raw_response_create_overload_2(self, async_client: AsyncOpenAI) -> None:
681 response = await async_client.chat.completions.with_raw_response.create(
682 messages=[
683 {
684 "content": "string",
685 "role": "developer",
686 }
687 ],
688 model="gpt-4o",
689 stream=True,
690 )
691
692 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
693 stream = response.parse()
694 await stream.close()
695
696 @parametrize
697 async def test_streaming_response_create_overload_2(self, async_client: AsyncOpenAI) -> None:
698 async with async_client.chat.completions.with_streaming_response.create(
699 messages=[
700 {
701 "content": "string",
702 "role": "developer",
703 }
704 ],
705 model="gpt-4o",
706 stream=True,
707 ) as response:
708 assert not response.is_closed
709 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
710
711 stream = await response.parse()
712 await stream.close()
713
714 assert cast(Any, response.is_closed) is True
715
716 @parametrize
717 async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None:
718 completion = await async_client.chat.completions.retrieve(
719 "completion_id",
720 )
721 assert_matches_type(ChatCompletion, completion, path=["response"])
722
723 @parametrize
724 async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None:
725 response = await async_client.chat.completions.with_raw_response.retrieve(
726 "completion_id",
727 )
728
729 assert response.is_closed is True
730 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
731 completion = response.parse()
732 assert_matches_type(ChatCompletion, completion, path=["response"])
733
734 @parametrize
735 async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None:
736 async with async_client.chat.completions.with_streaming_response.retrieve(
737 "completion_id",
738 ) as response:
739 assert not response.is_closed
740 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
741
742 completion = await response.parse()
743 assert_matches_type(ChatCompletion, completion, path=["response"])
744
745 assert cast(Any, response.is_closed) is True
746
747 @parametrize
748 async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None:
749 with pytest.raises(ValueError, match=r"Expected a non-empty value for `completion_id` but received ''"):
750 await async_client.chat.completions.with_raw_response.retrieve(
751 "",
752 )
753
754 @parametrize
755 async def test_method_update(self, async_client: AsyncOpenAI) -> None:
756 completion = await async_client.chat.completions.update(
757 completion_id="completion_id",
758 metadata={"foo": "string"},
759 )
760 assert_matches_type(ChatCompletion, completion, path=["response"])
761
762 @parametrize
763 async def test_raw_response_update(self, async_client: AsyncOpenAI) -> None:
764 response = await async_client.chat.completions.with_raw_response.update(
765 completion_id="completion_id",
766 metadata={"foo": "string"},
767 )
768
769 assert response.is_closed is True
770 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
771 completion = response.parse()
772 assert_matches_type(ChatCompletion, completion, path=["response"])
773
774 @parametrize
775 async def test_streaming_response_update(self, async_client: AsyncOpenAI) -> None:
776 async with async_client.chat.completions.with_streaming_response.update(
777 completion_id="completion_id",
778 metadata={"foo": "string"},
779 ) as response:
780 assert not response.is_closed
781 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
782
783 completion = await response.parse()
784 assert_matches_type(ChatCompletion, completion, path=["response"])
785
786 assert cast(Any, response.is_closed) is True
787
788 @parametrize
789 async def test_path_params_update(self, async_client: AsyncOpenAI) -> None:
790 with pytest.raises(ValueError, match=r"Expected a non-empty value for `completion_id` but received ''"):
791 await async_client.chat.completions.with_raw_response.update(
792 completion_id="",
793 metadata={"foo": "string"},
794 )
795
796 @parametrize
797 async def test_method_list(self, async_client: AsyncOpenAI) -> None:
798 completion = await async_client.chat.completions.list()
799 assert_matches_type(AsyncCursorPage[ChatCompletion], completion, path=["response"])
800
801 @parametrize
802 async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> None:
803 completion = await async_client.chat.completions.list(
804 after="after",
805 limit=0,
806 metadata={"foo": "string"},
807 model="model",
808 order="asc",
809 )
810 assert_matches_type(AsyncCursorPage[ChatCompletion], completion, path=["response"])
811
812 @parametrize
813 async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None:
814 response = await async_client.chat.completions.with_raw_response.list()
815
816 assert response.is_closed is True
817 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
818 completion = response.parse()
819 assert_matches_type(AsyncCursorPage[ChatCompletion], completion, path=["response"])
820
821 @parametrize
822 async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None:
823 async with async_client.chat.completions.with_streaming_response.list() as response:
824 assert not response.is_closed
825 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
826
827 completion = await response.parse()
828 assert_matches_type(AsyncCursorPage[ChatCompletion], completion, path=["response"])
829
830 assert cast(Any, response.is_closed) is True
831
832 @parametrize
833 async def test_method_delete(self, async_client: AsyncOpenAI) -> None:
834 completion = await async_client.chat.completions.delete(
835 "completion_id",
836 )
837 assert_matches_type(ChatCompletionDeleted, completion, path=["response"])
838
839 @parametrize
840 async def test_raw_response_delete(self, async_client: AsyncOpenAI) -> None:
841 response = await async_client.chat.completions.with_raw_response.delete(
842 "completion_id",
843 )
844
845 assert response.is_closed is True
846 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
847 completion = response.parse()
848 assert_matches_type(ChatCompletionDeleted, completion, path=["response"])
849
850 @parametrize
851 async def test_streaming_response_delete(self, async_client: AsyncOpenAI) -> None:
852 async with async_client.chat.completions.with_streaming_response.delete(
853 "completion_id",
854 ) as response:
855 assert not response.is_closed
856 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
857
858 completion = await response.parse()
859 assert_matches_type(ChatCompletionDeleted, completion, path=["response"])
860
861 assert cast(Any, response.is_closed) is True
862
863 @parametrize
864 async def test_path_params_delete(self, async_client: AsyncOpenAI) -> None:
865 with pytest.raises(ValueError, match=r"Expected a non-empty value for `completion_id` but received ''"):
866 await async_client.chat.completions.with_raw_response.delete(
867 "",
868 )