Σχετικά με την έξοδο ροής
Στη λειτουργία ροής, ισχύει επίσης tool_calls, αλλά υπάρχουν μερικά επιπλέον σημεία που πρέπει να σημειωθούν, όπως απαριθμούνται παρακάτω:
Κατά τη διάρκεια της εξόδου ροής, καθώς finish_reason θα εμφανιστεί στο τελευταίο κομμάτι, συνιστάται να χρησιμοποιήσετε την παρουσία ή την απουσία του πεδίου delta.tool_calls για να προσδιορίσετε εάν η τρέχουσα απάντηση περιέχει μια κλήση εργαλείου. Κατά τη διάρκεια της εξόδου ροής, θα εξάγεται πρώτα το delta.content και μετά το delta.tool_calls, επομένως πρέπει να περιμένετε να ολοκληρωθεί η έξοδος delta.content για να μπορέσετε να κρίνετε και να αναγνωρίσετε tool_calls. Κατά τη διαδικασία εξόδου ροής, θα καθορίσουμε τα tool_call.id και tool_call.function.name της τρέχουσας tool_calls κλήσης στο αρχικό μπλοκ δεδομένων και μόνο το tool_call.function.arguments θα εξάγεται στο επόμενο μπλοκ δεδομένων. Κατά τη διαδικασία εξόδου ροής, εάν το μοντέλο Kimi επιστρέψει πολλές tool_calls ταυτόχρονα, θα χρησιμοποιήσουμε ένα πρόσθετο πεδίο που ονομάζεται ευρετήριο για να προσδιορίσουμε το τρέχον ευρετήριο 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]
|