(
req_id: str,
model: str,
reason: str = "stop",
usage: Optional[Dict[str, int]] = None,
)
| 15 | |
| 16 | |
| 17 | def 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 | |
| 35 | def generate_sse_error_chunk( |
no outgoing calls