Update api/utils.py
Browse files- api/utils.py +7 -5
api/utils.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
| 1 |
from datetime import datetime
|
| 2 |
import json
|
| 3 |
import uuid
|
|
@@ -13,7 +15,7 @@ from api.config import (
|
|
| 13 |
AGENT_MODE,
|
| 14 |
TRENDING_AGENT_MODE,
|
| 15 |
MODEL_PREFIXES,
|
| 16 |
-
|
| 17 |
)
|
| 18 |
from api.models import ChatRequest
|
| 19 |
from api.logger import setup_logger
|
|
@@ -124,7 +126,7 @@ async def process_streaming_response(request: ChatRequest):
|
|
| 124 |
async with client.stream(
|
| 125 |
"POST",
|
| 126 |
f"{BASE_URL}/api/chat",
|
| 127 |
-
headers=
|
| 128 |
json=json_data,
|
| 129 |
timeout=100,
|
| 130 |
) as response:
|
|
@@ -135,7 +137,7 @@ async def process_streaming_response(request: ChatRequest):
|
|
| 135 |
if "https://www.blackbox.ai" in line:
|
| 136 |
# Refresh hid and inform the user
|
| 137 |
validate.getHid(True)
|
| 138 |
-
content = "
|
| 139 |
yield (
|
| 140 |
f"data: {json.dumps(create_chat_completion_data(content, request.model, int(datetime.now().timestamp())))}\n\n"
|
| 141 |
)
|
|
@@ -205,7 +207,7 @@ async def process_non_streaming_response(request: ChatRequest):
|
|
| 205 |
try:
|
| 206 |
response = await client.post(
|
| 207 |
url=f"{BASE_URL}/api/chat",
|
| 208 |
-
headers=
|
| 209 |
json=json_data,
|
| 210 |
)
|
| 211 |
response.raise_for_status()
|
|
@@ -220,7 +222,7 @@ async def process_non_streaming_response(request: ChatRequest):
|
|
| 220 |
if "https://www.blackbox.ai" in full_response:
|
| 221 |
# Refresh hid and inform the user
|
| 222 |
validate.getHid(True)
|
| 223 |
-
full_response = "
|
| 224 |
if full_response.startswith("$@$v=undefined-rv1$@$"):
|
| 225 |
full_response = full_response[21:]
|
| 226 |
|
|
|
|
| 1 |
+
# api/utils.py
|
| 2 |
+
|
| 3 |
from datetime import datetime
|
| 4 |
import json
|
| 5 |
import uuid
|
|
|
|
| 15 |
AGENT_MODE,
|
| 16 |
TRENDING_AGENT_MODE,
|
| 17 |
MODEL_PREFIXES,
|
| 18 |
+
api_headers,
|
| 19 |
)
|
| 20 |
from api.models import ChatRequest
|
| 21 |
from api.logger import setup_logger
|
|
|
|
| 126 |
async with client.stream(
|
| 127 |
"POST",
|
| 128 |
f"{BASE_URL}/api/chat",
|
| 129 |
+
headers=api_headers,
|
| 130 |
json=json_data,
|
| 131 |
timeout=100,
|
| 132 |
) as response:
|
|
|
|
| 137 |
if "https://www.blackbox.ai" in line:
|
| 138 |
# Refresh hid and inform the user
|
| 139 |
validate.getHid(True)
|
| 140 |
+
content = "hid已刷新,重新对话即可"
|
| 141 |
yield (
|
| 142 |
f"data: {json.dumps(create_chat_completion_data(content, request.model, int(datetime.now().timestamp())))}\n\n"
|
| 143 |
)
|
|
|
|
| 207 |
try:
|
| 208 |
response = await client.post(
|
| 209 |
url=f"{BASE_URL}/api/chat",
|
| 210 |
+
headers=api_headers,
|
| 211 |
json=json_data,
|
| 212 |
)
|
| 213 |
response.raise_for_status()
|
|
|
|
| 222 |
if "https://www.blackbox.ai" in full_response:
|
| 223 |
# Refresh hid and inform the user
|
| 224 |
validate.getHid(True)
|
| 225 |
+
full_response = "hid已刷新,重新对话即可"
|
| 226 |
if full_response.startswith("$@$v=undefined-rv1$@$"):
|
| 227 |
full_response = full_response[21:]
|
| 228 |
|