Skip to content

Commit e040d22

Browse files
fix(client): avoid mutating user-provided response config object (#2700)
1 parent 307a066 commit e040d22

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/openai/resources/responses/responses.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
from copy import copy
56
from typing import Any, List, Type, Union, Iterable, Optional, cast
67
from functools import partial
78
from typing_extensions import Literal, overload
@@ -1046,6 +1047,7 @@ def stream(
10461047
if "format" in text:
10471048
raise TypeError("Cannot mix and match text.format with text_format")
10481049

1050+
text = copy(text)
10491051
text["format"] = _type_to_text_format_param(text_format)
10501052

10511053
api_request: partial[Stream[ResponseStreamEvent]] = partial(
@@ -1151,7 +1153,7 @@ def parse(
11511153

11521154
if "format" in text:
11531155
raise TypeError("Cannot mix and match text.format with text_format")
1154-
1156+
text = copy(text)
11551157
text["format"] = _type_to_text_format_param(text_format)
11561158

11571159
tools = _make_tools(tools)
@@ -2507,7 +2509,7 @@ def stream(
25072509

25082510
if "format" in text:
25092511
raise TypeError("Cannot mix and match text.format with text_format")
2510-
2512+
text = copy(text)
25112513
text["format"] = _type_to_text_format_param(text_format)
25122514

25132515
api_request = self.create(
@@ -2617,7 +2619,7 @@ async def parse(
26172619

26182620
if "format" in text:
26192621
raise TypeError("Cannot mix and match text.format with text_format")
2620-
2622+
text = copy(text)
26212623
text["format"] = _type_to_text_format_param(text_format)
26222624

26232625
tools = _make_tools(tools)

0 commit comments

Comments
 (0)