Intermediate
Join streamed tool calls
Write join_tool_calls(events). Each event is a JSON chunk string. Tool-call fragments are in choices[0].delta.tool_calls, each with an index. The first fragment of an index also has function.name; every fragment may have function.arguments (a piece of JSON text).
Return a list of (name, arguments) pairs ordered by index, where arguments is the parsed dictionary of the joined argument text. Return [] when there are no tool calls.
What Check tests
- One call whose arguments arrive in pieces
- Two interleaved calls stay separate
- Results are ordered by index, not by arrival
- No tool calls gives an empty list
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
main.py
Sign in to run your code.
Output
Press Run to see what your program prints.