🐛 Bug: Fix the bug where the response ID is the same every time.
Browse files- response.py +6 -1
response.py
CHANGED
|
@@ -186,6 +186,9 @@ async def fetch_vertex_claude_response_stream(client, url, headers, payload, mod
|
|
| 186 |
yield "data: [DONE]" + end_of_line
|
| 187 |
|
| 188 |
async def fetch_gpt_response_stream(client, url, headers, payload):
|
|
|
|
|
|
|
|
|
|
| 189 |
async with client.stream('POST', url, headers=headers, json=payload) as response:
|
| 190 |
error_message = await check_response(response, "fetch_gpt_response_stream")
|
| 191 |
if error_message:
|
|
@@ -199,7 +202,9 @@ async def fetch_gpt_response_stream(client, url, headers, payload):
|
|
| 199 |
line, buffer = buffer.split("\n", 1)
|
| 200 |
# logger.info("line: %s", repr(line))
|
| 201 |
if line and line != "data: " and line != "data:" and not line.startswith(": "):
|
| 202 |
-
|
|
|
|
|
|
|
| 203 |
|
| 204 |
async def fetch_cloudflare_response_stream(client, url, headers, payload, model):
|
| 205 |
timestamp = int(datetime.timestamp(datetime.now()))
|
|
|
|
| 186 |
yield "data: [DONE]" + end_of_line
|
| 187 |
|
| 188 |
async def fetch_gpt_response_stream(client, url, headers, payload):
|
| 189 |
+
timestamp = int(datetime.timestamp(datetime.now()))
|
| 190 |
+
random.seed(timestamp)
|
| 191 |
+
random_str = ''.join(random.choices(string.ascii_letters + string.digits, k=29))
|
| 192 |
async with client.stream('POST', url, headers=headers, json=payload) as response:
|
| 193 |
error_message = await check_response(response, "fetch_gpt_response_stream")
|
| 194 |
if error_message:
|
|
|
|
| 202 |
line, buffer = buffer.split("\n", 1)
|
| 203 |
# logger.info("line: %s", repr(line))
|
| 204 |
if line and line != "data: " and line != "data:" and not line.startswith(": "):
|
| 205 |
+
line = json.loads(line.lstrip("data: "))
|
| 206 |
+
line['id'] = f"chatcmpl-{random_str}"
|
| 207 |
+
yield "data: " + json.dumps(line).strip() + end_of_line
|
| 208 |
|
| 209 |
async def fetch_cloudflare_response_stream(client, url, headers, payload, model):
|
| 210 |
timestamp = int(datetime.timestamp(datetime.now()))
|