Update api/utils.py
Browse files- api/utils.py +3 -2
api/utils.py
CHANGED
@@ -148,9 +148,9 @@ async def process_streaming_response(request: ChatRequest):
|
|
148 |
# Yield the cleaned chunk as part of the stream
|
149 |
yield f"data: {json.dumps(create_chat_completion_data(cleaned_content, request.model, timestamp))}\n\n"
|
150 |
|
151 |
-
#
|
152 |
if ADVERTISEMENT_TEXT and not advertisement_added:
|
153 |
-
response_content += "\n\n" + ADVERTISEMENT_TEXT #
|
154 |
advertisement_added = True
|
155 |
|
156 |
# Yield the final chunk with the advertisement text appended at the end
|
@@ -166,6 +166,7 @@ async def process_streaming_response(request: ChatRequest):
|
|
166 |
logger.error(f"Error occurred during request for Request ID {request_id}: {e}")
|
167 |
raise HTTPException(status_code=500, detail=str(e))
|
168 |
|
|
|
169 |
# Process non-streaming response with headers from config.py
|
170 |
async def process_non_streaming_response(request: ChatRequest):
|
171 |
request_id = f"chatcmpl-{uuid.uuid4()}"
|
|
|
148 |
# Yield the cleaned chunk as part of the stream
|
149 |
yield f"data: {json.dumps(create_chat_completion_data(cleaned_content, request.model, timestamp))}\n\n"
|
150 |
|
151 |
+
# Ensure that the advertisement is added after the full response is processed
|
152 |
if ADVERTISEMENT_TEXT and not advertisement_added:
|
153 |
+
response_content += "\n\n" + ADVERTISEMENT_TEXT # Add line break here
|
154 |
advertisement_added = True
|
155 |
|
156 |
# Yield the final chunk with the advertisement text appended at the end
|
|
|
166 |
logger.error(f"Error occurred during request for Request ID {request_id}: {e}")
|
167 |
raise HTTPException(status_code=500, detail=str(e))
|
168 |
|
169 |
+
|
170 |
# Process non-streaming response with headers from config.py
|
171 |
async def process_non_streaming_response(request: ChatRequest):
|
172 |
request_id = f"chatcmpl-{uuid.uuid4()}"
|