Update app.py
Browse files
app.py
CHANGED
|
@@ -71,6 +71,10 @@ def normalize_headers(request: Request, original_url: str) -> dict:
|
|
| 71 |
def format_chunk(chunk: bytes, model: str) -> bytes | str | dict:
|
| 72 |
chunk_id = 'chatcmpl-AQ8Lzxlg8eSCB1lgVmboiXwZiexqE'
|
| 73 |
timestamp = int(datetime.now().timestamp())
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
data = {
|
| 75 |
"id": chunk_id,
|
| 76 |
"object": "chat.completion.chunk",
|
|
@@ -81,7 +85,7 @@ def format_chunk(chunk: bytes, model: str) -> bytes | str | dict:
|
|
| 81 |
{
|
| 82 |
"index": 0,
|
| 83 |
"delta": {
|
| 84 |
-
"content":
|
| 85 |
},
|
| 86 |
"finish_reason": None
|
| 87 |
}
|
|
|
|
| 71 |
def format_chunk(chunk: bytes, model: str) -> bytes | str | dict:
|
| 72 |
chunk_id = 'chatcmpl-AQ8Lzxlg8eSCB1lgVmboiXwZiexqE'
|
| 73 |
timestamp = int(datetime.now().timestamp())
|
| 74 |
+
try:
|
| 75 |
+
content = chunk.decode('utf-8')
|
| 76 |
+
except UnicodeDecodeError:
|
| 77 |
+
content = chunk.decode('latin-1', errors='ignore')
|
| 78 |
data = {
|
| 79 |
"id": chunk_id,
|
| 80 |
"object": "chat.completion.chunk",
|
|
|
|
| 85 |
{
|
| 86 |
"index": 0,
|
| 87 |
"delta": {
|
| 88 |
+
"content": content
|
| 89 |
},
|
| 90 |
"finish_reason": None
|
| 91 |
}
|