Update api/utils.py
Browse files- api/utils.py +7 -7
api/utils.py
CHANGED
|
@@ -5,6 +5,7 @@ import asyncio
|
|
| 5 |
import random
|
| 6 |
import string
|
| 7 |
from typing import Any, Dict, Optional
|
|
|
|
| 8 |
|
| 9 |
import httpx
|
| 10 |
from fastapi import HTTPException
|
|
@@ -80,15 +81,14 @@ def strip_model_prefix(content: str, model_prefix: Optional[str] = None) -> str:
|
|
| 80 |
return content[len(model_prefix):].strip()
|
| 81 |
return content
|
| 82 |
|
| 83 |
-
#
|
| 84 |
def remove_message_between_special_tags(content: str) -> str:
|
| 85 |
-
"""Remove any
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
return ""
|
| 89 |
return content
|
| 90 |
|
| 91 |
-
#
|
| 92 |
async def process_streaming_response(request: ChatRequest):
|
| 93 |
# Generate a unique ID for this request
|
| 94 |
request_id = f"chatcmpl-{uuid.uuid4()}"
|
|
@@ -187,7 +187,7 @@ async def process_streaming_response(request: ChatRequest):
|
|
| 187 |
)
|
| 188 |
raise HTTPException(status_code=500, detail=str(e))
|
| 189 |
|
| 190 |
-
#
|
| 191 |
async def process_non_streaming_response(request: ChatRequest):
|
| 192 |
# Generate a unique ID for this request
|
| 193 |
request_id = f"chatcmpl-{uuid.uuid4()}"
|
|
|
|
| 5 |
import random
|
| 6 |
import string
|
| 7 |
from typing import Any, Dict, Optional
|
| 8 |
+
import re
|
| 9 |
|
| 10 |
import httpx
|
| 11 |
from fastapi import HTTPException
|
|
|
|
| 81 |
return content[len(model_prefix):].strip()
|
| 82 |
return content
|
| 83 |
|
| 84 |
+
# Function to remove content between '$~~~$' tags
|
| 85 |
def remove_message_between_special_tags(content: str) -> str:
|
| 86 |
+
"""Remove any content that starts with '$~~~$' and ends with '$~~~$', including the tags."""
|
| 87 |
+
# Use regex to remove the entire block between '$~~~$' tags
|
| 88 |
+
content = re.sub(r'\$~~~\$.*?\$~~~\$', '', content, flags=re.DOTALL)
|
|
|
|
| 89 |
return content
|
| 90 |
|
| 91 |
+
# Process streaming response with headers from config.py
|
| 92 |
async def process_streaming_response(request: ChatRequest):
|
| 93 |
# Generate a unique ID for this request
|
| 94 |
request_id = f"chatcmpl-{uuid.uuid4()}"
|
|
|
|
| 187 |
)
|
| 188 |
raise HTTPException(status_code=500, detail=str(e))
|
| 189 |
|
| 190 |
+
# Process non-streaming response with headers from config.py
|
| 191 |
async def process_non_streaming_response(request: ChatRequest):
|
| 192 |
# Generate a unique ID for this request
|
| 193 |
request_id = f"chatcmpl-{uuid.uuid4()}"
|