openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
e09bccaddcdc6bc7046eca1321f0a5dff343a84d

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/chat/test_completions.py

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