Update api/utils.py
Browse files- api/utils.py +8 -4
api/utils.py
CHANGED
@@ -18,8 +18,7 @@ from api.config import (
|
|
18 |
BASE_URL,
|
19 |
AGENT_MODE,
|
20 |
TRENDING_AGENT_MODE,
|
21 |
-
MODEL_PREFIXES
|
22 |
-
MODEL_REFERERS
|
23 |
)
|
24 |
from api.models import ChatRequest
|
25 |
from api.logger import setup_logger
|
@@ -109,9 +108,14 @@ def strip_model_prefix(content: str, model_prefix: Optional[str] = None) -> str:
|
|
109 |
return content[len(model_prefix):].strip()
|
110 |
return content
|
111 |
|
|
|
|
|
|
|
|
|
|
|
112 |
# Process streaming response with headers from config.py
|
113 |
async def process_streaming_response(request: ChatRequest, request_obj: Request):
|
114 |
-
referer_url = get_referer_url(
|
115 |
logger.info(f"Processing streaming response - Model: {request.model} - URL: {referer_url}")
|
116 |
|
117 |
# Get the IP address and check rate limit
|
@@ -184,7 +188,7 @@ async def process_streaming_response(request: ChatRequest, request_obj: Request)
|
|
184 |
|
185 |
# Process non-streaming response with headers from config.py
|
186 |
async def process_non_streaming_response(request: ChatRequest, request_obj: Request):
|
187 |
-
referer_url = get_referer_url(
|
188 |
logger.info(f"Processing non-streaming response - Model: {request.model} - URL: {referer_url}")
|
189 |
|
190 |
# Get the IP address and check rate limit
|
|
|
18 |
BASE_URL,
|
19 |
AGENT_MODE,
|
20 |
TRENDING_AGENT_MODE,
|
21 |
+
MODEL_PREFIXES
|
|
|
22 |
)
|
23 |
from api.models import ChatRequest
|
24 |
from api.logger import setup_logger
|
|
|
108 |
return content[len(model_prefix):].strip()
|
109 |
return content
|
110 |
|
111 |
+
# Simplified function to get the base referer URL
|
112 |
+
def get_referer_url() -> str:
|
113 |
+
"""Return the base URL for the referer without model-specific logic."""
|
114 |
+
return BASE_URL
|
115 |
+
|
116 |
# Process streaming response with headers from config.py
|
117 |
async def process_streaming_response(request: ChatRequest, request_obj: Request):
|
118 |
+
referer_url = get_referer_url() # Get the base URL without model-specific logic
|
119 |
logger.info(f"Processing streaming response - Model: {request.model} - URL: {referer_url}")
|
120 |
|
121 |
# Get the IP address and check rate limit
|
|
|
188 |
|
189 |
# Process non-streaming response with headers from config.py
|
190 |
async def process_non_streaming_response(request: ChatRequest, request_obj: Request):
|
191 |
+
referer_url = get_referer_url() # Get the base URL without model-specific logic
|
192 |
logger.info(f"Processing non-streaming response - Model: {request.model} - URL: {referer_url}")
|
193 |
|
194 |
# Get the IP address and check rate limit
|