Update api/utils.py
Browse files4 unmodified lines567891069 unmodified lines80818283848586878889909192939492 unmodified lines1871881891901911921934 unmodified linesimport randomimport stringfrom typing import Any, Dict, Optionalimport httpxfrom fastapi import HTTPException69 unmodified linesreturn content[len(model_prefix):].strip()return content# Helper function to remove message between special tagsdef remove_message_between_special_tags(content: str) -> str:"""Remove any message that starts with '$~~~$' and ends with '$~~~$'."""if content.startswith('$~~~$') and content.endswith('$~~~$'):# Remove the entire message between the tagsreturn ""return content# Modify the streaming response processingasync def process_streaming_response(request: ChatRequest):# Generate a unique ID for this requestrequest_id = f"chatcmpl-{uuid.uuid4()}"92 unmodified lines)raise HTTPException(status_code=500, detail=str(e))# Modify the non-streaming response processingasync def process_non_streaming_response(request: ChatRequest):# Generate a unique ID for this requestrequest_id = f"chatcmpl-{uuid.uuid4()}"4 unmodified lines56789101169 unmodified lines818283848586878889909192939492 unmodified lines1871881891901911921934 unmodified linesimport randomimport stringfrom typing import Any, Dict, Optionalimport reimport httpxfrom fastapi import HTTPException69 unmodified linesreturn content[len(model_prefix):].strip()return content# Function to remove content between '$~~~$' tagsdef remove_message_between_special_tags(content: str) -> str:"""Remove any content that starts with '$~~~$' and ends with '$~~~$', including the tags."""# Use regex to remove the entire block between '$~~~$' tagscontent = re.sub(r'\$~~~\$.*?\$~~~\$', '', content, flags=re.DOTALL)return content# Process streaming response with headers from config.pyasync def process_streaming_response(request: ChatRequest):# Generate a unique ID for this requestrequest_id = f"chatcmpl-{uuid.uuid4()}"92 unmodified lines)raise HTTPException(status_code=500, detail=str(e))# Process non-streaming response with headers from config.pyasync def process_non_streaming_response(request: ChatRequest):# Generate a unique ID for this requestrequest_id = f"chatcmpl-{uuid.uuid4()}"
api/utils.py+7-7