Skip to content

Commit c7fc0a3

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

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
@@ -3534,10 +3534,13 @@ def _make_tools(tools: Iterable[ParseableToolParam] | Omit) -> List[ToolParam] |
35343534
if not is_given(tools):
35353535
return omit
35363536

3537-
validate_tools(tools)
3537+
# Materialise once so that validation doesn't consume a one-shot iterator
3538+
tools_list = list(tools) if not isinstance(tools, list) else tools
3539+
3540+
validate_tools(tools_list)
35383541

35393542
converted_tools: List[ToolParam] = []
3540-
for tool in tools:
3543+
for tool in tools_list:
35413544
if tool["type"] != "function":
35423545
converted_tools.append(tool)
35433546
continue

0 commit comments

Comments
 (0)