Command Palette

Search for a command to run...

Hectal
Phase 5: Streaming and UX
LLM Engineering · Exercise 3 of 5 PreviousNext
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

  1. One call whose arguments arrive in pieces
  2. Two interleaved calls stay separate
  3. Results are ordered by index, not by arrival
  4. 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.