• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

deepset-ai / haystack / 14794014302

02 May 2025 11:06AM UTC coverage: 90.448% (-0.07%) from 90.513%
14794014302

Pull #9290

github

web-flow
Merge de5d77f03 into e3f9da13d
Pull Request #9290: feat: enable streaming ToolCall/Result from Agent

10899 of 12050 relevant lines covered (90.45%)

0.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

30.0
haystack/components/generators/utils.py
1
# SPDX-FileCopyrightText: 2022-present deepset GmbH <info@deepset.ai>
2
#
3
# SPDX-License-Identifier: Apache-2.0
4

5
from openai.types.chat.chat_completion_chunk import ChoiceDeltaToolCall
1✔
6

7
from haystack.dataclasses import StreamingChunk
1✔
8

9

10
def print_streaming_chunk(chunk: StreamingChunk) -> None:
1✔
11
    """
12
    Default callback function for streaming responses.
13

14
    Prints the tokens of the first completion to stdout as soon as they are received.
15
    Also prints the tool calls in the meta data of the chunk.
16
    """
17
    if chunk.meta.get("tool_calls"):
×
18
        for tool_call in chunk.meta["tool_calls"]:
×
19
            if isinstance(tool_call, ChoiceDeltaToolCall) and tool_call.function:
×
20
                # pick the name of the function, otherwise the arguments
21
                output = tool_call.function.name or tool_call.function.arguments
×
22
                if output:
×
23
                    print(output, flush=True, end="")
×
24

25
    print(chunk.content, flush=True, end="")
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc