MCPcopy Create free account
hub / github.com/CJackHwang/AIstudioProxyAPI / generate_sse_stop_chunk

Function generate_sse_stop_chunk

api_utils/sse.py:17–32  ·  view source on GitHub ↗
(
    req_id: str,
    model: str,
    reason: str = "stop",
    usage: Optional[Dict[str, int]] = None,
)

Source from the content-addressed store, hash-verified

15
16
17def generate_sse_stop_chunk(
18 req_id: str,
19 model: str,
20 reason: str = "stop",
21 usage: Optional[Dict[str, int]] = None,
22) -> str:
23 stop_chunk_data: Dict[str, Any] = {
24 "id": f"chatcmpl-{req_id}",
25 "object": "chat.completion.chunk",
26 "created": int(time.time()),
27 "model": model,
28 "choices": [{"index": 0, "delta": {}, "finish_reason": reason}],
29 }
30 if usage:
31 stop_chunk_data["usage"] = usage
32 return f"data: {json.dumps(stop_chunk_data)}\n\ndata: [DONE]\n\n"
33
34
35def generate_sse_error_chunk(

Calls

no outgoing calls