ストリーミング作品について
ストリームモードでもこのルールtool_calls適用されますが、以下に挙げるような追加のポイントがあります。
ストリーミング出力中は、最終チャンクに現れるfinish_reasonため、delta.tool_callsフィールドの有無を用いて現在の返信にツールコールが含まれているかどうかを判断することが推奨されます。 ストリーミング出力中はまずdelta.contentが出力され、その後delta.tool_callsが出されるため、delta.contentの出力が完了するまで判断・識別tool_callsなければなりません。 ストリーミング出力の過程で、最初のデータブロックで現在の呼び出しtool_callsのtool_call.idとtool_call.function.nameを指定し、その後のデータブロックで出力されるのはtool_call.function.argumentsのみです。 ストリーミング出力プロセス中に、Kimiモデルが同時に複数のtool_callsを返す場合、indexという追加フィールドを使って現在のtool_callインデックスを特定し、tool_call.function.argumentsパラメータを正しくスティッチできるようにします。
ハイパーリンクのログインが見えます。
ストリーミング応答の例は以下の通りです:
data: {"choices":[{"delta":{"content":null,"tool_calls":[{"function":{"name":"itsvse-get_current_time","arguments":""},"index":0,"id":"call_deb0063d315441b18b50d8","type":"function"}],"role":"assistant"},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1743037194,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-c4e2a989-10a3-9604-bdae-0b58b4f876a7"}
data: {"choices":[{"delta":{"content":null,"tool_calls":[{"function":{"arguments":"{}"},"index":0,"id":"","type":"function"}]},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1743037194,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-c4e2a989-10a3-9604-bdae-0b58b4f876a7"}
data: {"choices":[{"delta":{"content":null,"tool_calls":[{"function":{},"index":0,"id":"","type":"function"}]},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1743037194,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-c4e2a989-10a3-9604-bdae-0b58b4f876a7"}
data: {"choices":[{"delta":{"content":null,"tool_calls":[{"function":{},"index":0,"id":"","type":"function"}]},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1743037194,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-c4e2a989-10a3-9604-bdae-0b58b4f876a7"}
data: {"choices":[{"delta":{"content":null,"tool_calls":[{"function":{},"index":0,"id":"","type":"function"},{"function":{"name":"itsvse-get_current_weather","arguments":""},"index":1,"id":"call_9790fb45e2b7419097d578","type":"function"}]},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1743037194,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-c4e2a989-10a3-9604-bdae-0b58b4f876a7"}
data: {"choices":[{"delta":{"content":null,"tool_calls":[{"function":{"arguments":"{\"location\": \""},"index":1,"id":"","type":"function"}]},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1743037194,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-c4e2a989-10a3-9604-bdae-0b58b4f876a7"}
data: {"choices":[{"delta":{"content":null,"tool_calls":[{"function":{"arguments":"上海市\"}"},"index":1,"id":"","type":"function"}]},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1743037194,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-c4e2a989-10a3-9604-bdae-0b58b4f876a7"}
data: {"choices":[{"delta":{"content":null,"tool_calls":[{"function":{},"index":1,"id":"","type":"function"}]},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1743037194,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-c4e2a989-10a3-9604-bdae-0b58b4f876a7"}
data: {"choices":[{"delta":{"content":null,"tool_calls":[{"function":{},"index":1,"id":"","type":"function"}]},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1743037194,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-c4e2a989-10a3-9604-bdae-0b58b4f876a7"}
data: {"choices":[{"delta":{"content":null,"tool_calls":[{"function":{},"index":1,"id":"","type":"function"}]},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1743037194,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-c4e2a989-10a3-9604-bdae-0b58b4f876a7"}
data: {"choices":[{"delta":{"tool_calls":[{"function":{"arguments":null},"index":1,"id":"","type":"function"},{"function":{"arguments":"{}","name":"itsvse-open_calculator"},"index":2,"id":"call_3ad6478075f04021ab9ea1","type":"function"}]},"index":0}],"object":"chat.completion.chunk","usage":null,"created":1743037194,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-c4e2a989-10a3-9604-bdae-0b58b4f876a7"}
data: {"choices":[{"finish_reason":"tool_calls","delta":{},"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1743037194,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-c4e2a989-10a3-9604-bdae-0b58b4f876a7"}
data: {"choices":[],"object":"chat.completion.chunk","usage":{"prompt_tokens":500,"completion_tokens":53,"total_tokens":553,"prompt_tokens_details":{"cached_tokens":0}},"created":1743037194,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-c4e2a989-10a3-9604-bdae-0b58b4f876a7"}
data: [DONE]
|