🐛 Bug: Fix the bug where the response ID is the same every time.
Browse files- response.py +8 -2
response.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
import json
|
2 |
import httpx
|
|
|
|
|
3 |
from datetime import datetime
|
4 |
|
5 |
from log_config import logger
|
@@ -14,8 +16,10 @@ end_of_line = "\n\n"
|
|
14 |
# end_of_line = "\n"
|
15 |
|
16 |
async def generate_sse_response(timestamp, model, content=None, tools_id=None, function_call_name=None, function_call_content=None, role=None, total_tokens=0, prompt_tokens=0, completion_tokens=0):
|
|
|
|
|
17 |
sample_data = {
|
18 |
-
"id": "chatcmpl-
|
19 |
"object": "chat.completion.chunk",
|
20 |
"created": timestamp,
|
21 |
"model": model,
|
@@ -49,8 +53,10 @@ async def generate_sse_response(timestamp, model, content=None, tools_id=None, f
|
|
49 |
return sse_response
|
50 |
|
51 |
async def generate_no_stream_response(timestamp, model, content=None, tools_id=None, function_call_name=None, function_call_content=None, role=None, total_tokens=0, prompt_tokens=0, completion_tokens=0):
|
|
|
|
|
52 |
sample_data = {
|
53 |
-
"id": "chatcmpl-
|
54 |
"object": "chat.completion",
|
55 |
"created": timestamp,
|
56 |
"model": model,
|
|
|
1 |
import json
|
2 |
import httpx
|
3 |
+
import random
|
4 |
+
import string
|
5 |
from datetime import datetime
|
6 |
|
7 |
from log_config import logger
|
|
|
16 |
# end_of_line = "\n"
|
17 |
|
18 |
async def generate_sse_response(timestamp, model, content=None, tools_id=None, function_call_name=None, function_call_content=None, role=None, total_tokens=0, prompt_tokens=0, completion_tokens=0):
|
19 |
+
random.seed(timestamp)
|
20 |
+
random_str = ''.join(random.choices(string.ascii_letters + string.digits, k=29))
|
21 |
sample_data = {
|
22 |
+
"id": f"chatcmpl-{random_str}",
|
23 |
"object": "chat.completion.chunk",
|
24 |
"created": timestamp,
|
25 |
"model": model,
|
|
|
53 |
return sse_response
|
54 |
|
55 |
async def generate_no_stream_response(timestamp, model, content=None, tools_id=None, function_call_name=None, function_call_content=None, role=None, total_tokens=0, prompt_tokens=0, completion_tokens=0):
|
56 |
+
random.seed(timestamp)
|
57 |
+
random_str = ''.join(random.choices(string.ascii_letters + string.digits, k=29))
|
58 |
sample_data = {
|
59 |
+
"id": f"chatcmpl-{random_str}",
|
60 |
"object": "chat.completion",
|
61 |
"created": timestamp,
|
62 |
"model": model,
|