Update api/utils.py
Browse files147 unmodified lines1481491501511521531541551561571581596 unmodified lines166167168169170171172147 unmodified lines# Yield the cleaned chunk as part of the streamyield f"data: {json.dumps(create_chat_completion_data(cleaned_content, request.model, timestamp))}\n\n"# Ensure that the advertisement is added after the full response is processedif ADVERTISEMENT_TEXT and not advertisement_added:response_content += "\n\n" + ADVERTISEMENT_TEXT # Add line break hereadvertisement_added = True# Yield the final chunk with the advertisement text appended at the endyield f"data: {json.dumps(create_chat_completion_data(response_content, request.model, timestamp, 'stop'))}\n\n"# Add the final "done" marker6 unmodified lineslogger.error(f"Error occurred during request for Request ID {request_id}: {e}")raise HTTPException(status_code=500, detail=str(e))# Process non-streaming response with headers from config.pyasync def process_non_streaming_response(request: ChatRequest):request_id = f"chatcmpl-{uuid.uuid4()}"147 unmodified lines1481491501511521531541551561571581596 unmodified lines166167168169170171147 unmodified lines# Yield the cleaned chunk as part of the streamyield f"data: {json.dumps(create_chat_completion_data(cleaned_content, request.model, timestamp))}\n\n"# After processing all chunks, add the advertisement once (at the end)if ADVERTISEMENT_TEXT and not advertisement_added:response_content += "\n\n" + ADVERTISEMENT_TEXT # Add line break hereadvertisement_added = True# Yield the final chunk with the advertisement text appended at the end (this is the final response)yield f"data: {json.dumps(create_chat_completion_data(response_content, request.model, timestamp, 'stop'))}\n\n"# Add the final "done" marker6 unmodified lineslogger.error(f"Error occurred during request for Request ID {request_id}: {e}")raise HTTPException(status_code=500, detail=str(e))# Process non-streaming response with headers from config.pyasync def process_non_streaming_response(request: ChatRequest):request_id = f"chatcmpl-{uuid.uuid4()}"
api/utils.py+2-3