Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,14 @@ async def create_stream(
# Determine the content and thought based on what was collected
if full_tool_calls:
# This is a tool call response
content = list(full_tool_calls.values())
content = [
FunctionCall(
id=tool_call.id,
arguments=tool_call.arguments,
name=normalize_name(tool_call.name),
)
for tool_call in full_tool_calls.values()
]
if content_deltas:
# Store any text alongside tool calls as thoughts
thought = "".join(content_deltas)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1591,8 +1591,14 @@ async def mock_create(
assert create_result.finish_reason == "function_calls"


@pytest.mark.parametrize(
("raw_tool_name", "expected_tool_name"),
[("get weather!", "get_weather_"), ("x" * 70, "x" * 64)],
)
@pytest.mark.asyncio
async def test_tool_calling_with_stream(monkeypatch: pytest.MonkeyPatch) -> None:
async def test_tool_calling_with_stream(
monkeypatch: pytest.MonkeyPatch, raw_tool_name: str, expected_tool_name: str
) -> None:
async def _mock_create_stream(*args: Any, **kwargs: Any) -> AsyncGenerator[ChatCompletionChunk, None]:
model = resolve_model(kwargs.get("model", "gpt-4o"))
mock_chunks_content = ["Hello", " Another Hello", " Yet Another Hello"]
Expand Down Expand Up @@ -1625,7 +1631,7 @@ async def _mock_create_stream(*args: Any, **kwargs: Any) -> AsyncGenerator[ChatC
id="1",
type="function",
function=ChoiceDeltaToolCallFunction(
name="_pass_function",
name=raw_tool_name,
arguments=json.dumps({"input": "task"}),
),
)
Expand Down Expand Up @@ -1665,7 +1671,7 @@ async def _mock_create(*args: Any, **kwargs: Any) -> ChatCompletion | AsyncGener
assert chunks[1] == " Another Hello"
assert chunks[2] == " Yet Another Hello"
assert isinstance(chunks[-1], CreateResult)
assert chunks[-1].content == [FunctionCall(id="1", arguments=r'{"input": "task"}', name="_pass_function")]
assert chunks[-1].content == [FunctionCall(id="1", arguments=r'{"input": "task"}', name=expected_tool_name)]
assert chunks[-1].finish_reason == "function_calls"
assert chunks[-1].thought == "Hello Another Hello Yet Another Hello"

Expand Down