Skip to content

Commit e24a1a6

Browse files
author
giulio-leone
committed
fix: preserve iterable tools before validation and reject trailing slashes
1 parent e00fb8b commit e24a1a6

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

src/openai/lib/_validation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from typing import Any, Iterable, Optional
1111

1212
_PROTOCOL_RE = re.compile(r"^https?://", re.IGNORECASE)
13-
_PATH_RE = re.compile(r"/.")
13+
_PATH_RE = re.compile(r"/.*$")
1414

1515

1616
def validate_network_policy_allowlist(

src/openai/resources/responses/responses.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3538,10 +3538,13 @@ def _make_tools(tools: Iterable[ParseableToolParam] | Omit) -> List[ToolParam] |
35383538
if not is_given(tools):
35393539
return omit
35403540

3541-
validate_tools(tools)
3541+
# Materialise once so that validation doesn't consume a one-shot iterator
3542+
tools_list = list(tools) if not isinstance(tools, list) else tools
3543+
3544+
validate_tools(tools_list)
35423545

35433546
converted_tools: List[ToolParam] = []
3544-
for tool in tools:
3547+
for tool in tools_list:
35453548
if tool["type"] != "function":
35463549
converted_tools.append(tool)
35473550
continue

0 commit comments

Comments
 (0)