Update api/utils.py
Browse files- api/utils.py +4 -4
api/utils.py
CHANGED
@@ -15,7 +15,6 @@ from api.config import (
|
|
15 |
AGENT_MODE,
|
16 |
TRENDING_AGENT_MODE,
|
17 |
MODEL_PREFIXES,
|
18 |
-
MODEL_REFERERS
|
19 |
)
|
20 |
from api.models import ChatRequest
|
21 |
from api.logger import setup_logger
|
@@ -124,17 +123,18 @@ async def process_streaming_response(request: ChatRequest):
|
|
124 |
|
125 |
cleaned_content = strip_model_prefix(content, model_prefix)
|
126 |
|
127 |
-
# Add
|
128 |
response_content += cleaned_content
|
129 |
|
130 |
-
#
|
131 |
yield f"data: {json.dumps(create_chat_completion_data(cleaned_content, request.model, timestamp))}\n\n"
|
132 |
|
133 |
-
# Append advertisement at the end
|
134 |
if ADVERTISEMENT_TEXT and not advertisement_added:
|
135 |
response_content += "\n\n" + ADVERTISEMENT_TEXT
|
136 |
advertisement_added = True
|
137 |
|
|
|
138 |
yield f"data: {json.dumps(create_chat_completion_data(response_content, request.model, timestamp, 'stop'))}\n\n"
|
139 |
yield "data: [DONE]\n\n"
|
140 |
|
|
|
15 |
AGENT_MODE,
|
16 |
TRENDING_AGENT_MODE,
|
17 |
MODEL_PREFIXES,
|
|
|
18 |
)
|
19 |
from api.models import ChatRequest
|
20 |
from api.logger import setup_logger
|
|
|
123 |
|
124 |
cleaned_content = strip_model_prefix(content, model_prefix)
|
125 |
|
126 |
+
# Add chunk to the response content
|
127 |
response_content += cleaned_content
|
128 |
|
129 |
+
# Only yield cleaned content in chunks
|
130 |
yield f"data: {json.dumps(create_chat_completion_data(cleaned_content, request.model, timestamp))}\n\n"
|
131 |
|
132 |
+
# Append advertisement at the end, ensuring it happens only once
|
133 |
if ADVERTISEMENT_TEXT and not advertisement_added:
|
134 |
response_content += "\n\n" + ADVERTISEMENT_TEXT
|
135 |
advertisement_added = True
|
136 |
|
137 |
+
# Final chunk with complete content
|
138 |
yield f"data: {json.dumps(create_chat_completion_data(response_content, request.model, timestamp, 'stop'))}\n\n"
|
139 |
yield "data: [DONE]\n\n"
|
140 |
|