Chat Completions streaming 응답은 순서대로 오는 chunk 로 이루어져. 첫 chunk 에는 보통 delta.role: "assistant" 만 들어 있고, 중간 chunk 의 delta.content 에 새 텍스트가 담겨. 마지막 chunk 는 빈 content 와 finish_reason 을 보낸 뒤 literal data: [DONE] 으로 끝나.
delta.content 는 비어 있을 수 있어
첫 chunk 가 role 만, 마지막 chunk 가 finish_reason 만 담는 건 정상 동작이야. 텍스트를 이어 붙이기 전에 if chunk.choices[0].delta.content: 처럼 값이 있는지 확인해.
tool-calling stream 은 arguments 를 나눠 보내
도구를 사용할 때는 delta.tool_calls[i].function.arguments 에 JSON fragment 가 도착해. 각 fragment 는 완성된 JSON 이 아니므로 모두 이어 붙인 뒤 parsing 해야 해. 다음 lesson 에서 자세히 구현할 거야.
lifecycle 을 그려두면 디버깅이 쉬워져
role, content, finish_reason, [DONE] 이 어느 순서로 오는지 그려봐. content 가 None 인 이유와 stream 이 끝난 시점을 바로 찾을 수 있어.