-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Open
Labels
P2Medium priority, add to the next sprint if no P1 availableMedium priority, add to the next sprint if no P1 availabletopic:streaming
Description
Problem
While updating the chat generators for the new StreamingChunk, we’ve found that the current use of multiple index
fields during streaming is confusing and potentially redundant.
In some cases, 3–4 different index
values are passed within the same chunk, for example:
- Index of the StreamingChunk
- Index of the ToolCallDelta
- Index in the meta of the original response chunk from the API
- Index in the ToolCall from the API
Example chunk from OpenAIChatGenerator
StreamingChunk(
content="",
meta={
"model": "gpt-4o-mini-2024-07-18",
"index": 0, # (3) API response chunk index
"tool_calls": [
ChoiceDeltaToolCall(
index=1, # (4) ToolCallDelta index from API
id="call_C88m67V16CrETq6jbNXjdZI9",
function=ChoiceDeltaToolCallFunction(arguments="", name="weather"),
type="function",
)
],
"finish_reason": None,
"received_at": ANY,
"usage": None,
},
index=1, # (1) StreamingChunk index
tool_calls=[
ToolCallDelta(
tool_name="weather",
id="call_C88m67V16CrETq6jbNXjdZI9",
index=1 # (2) ToolCallDelta index
)
],
start=True,
)
Why This is a Problem
- Hard to read and maintain
- It’s not immediately obvious which index is relevant for tracing content blocks vs. tool calls.
- The current meta payload may be carrying redundant information from the raw API response.
Possible Directions for Solution:
- Consider removing index keys from
meta
if they dont serve a purpose. - Rename our
index
keys to make them explicit (e.g.,chunk_index
,tool_call_index
) We have nestedindex
inToolCallDelta
ofStreamingChunk
. - Rethink storing the entire raw chunk in
meta
if it adds noise without value.
Metadata
Metadata
Assignees
Labels
P2Medium priority, add to the next sprint if no P1 availableMedium priority, add to the next sprint if no P1 availabletopic:streaming