Niansuh commited on
Commit
27288d3
·
verified ·
1 Parent(s): d64a36a

Update api/utils.py

Browse files
Files changed (1) hide show
  1. api/utils.py +2 -17
api/utils.py CHANGED
@@ -1,6 +1,3 @@
1
- # utils.py or your main application file
2
-
3
- import os # Import os to access environment variables
4
  from datetime import datetime
5
  import json
6
  import uuid
@@ -30,9 +27,6 @@ logger = setup_logger(__name__)
30
  # Define the blocked message
31
  BLOCKED_MESSAGE = "Generated by BLACKBOX.AI, try unlimited chat https://www.blackbox.ai"
32
 
33
- # Get the custom message from the environment variable
34
- FREE_USER_MESSAGE = os.getenv('FREE_USER_MESSAGE', 'Thank you for using our service! Upgrade to premium for more features.')
35
-
36
  # Helper function to create chat completion data
37
  def create_chat_completion_data(
38
  content: str, model: str, timestamp: int, finish_reason: Optional[str] = None
@@ -151,12 +145,7 @@ async def process_streaming_response(request: ChatRequest):
151
  cleaned_content = strip_model_prefix(content, model_prefix)
152
  yield f"data: {json.dumps(create_chat_completion_data(cleaned_content, request.model, timestamp))}\n\n"
153
 
154
- # Append the custom message for free users
155
- if request.is_free_user and FREE_USER_MESSAGE:
156
- timestamp = int(datetime.now().timestamp())
157
- yield f"data: {json.dumps(create_chat_completion_data(FREE_USER_MESSAGE, request.model, timestamp, 'stop'))}\n\n"
158
- else:
159
- yield f"data: {json.dumps(create_chat_completion_data('', request.model, timestamp, 'stop'))}\n\n"
160
  yield "data: [DONE]\n\n"
161
  except httpx.HTTPStatusError as e:
162
  logger.error(f"HTTP error occurred for Request ID {request_id}: {e}")
@@ -242,10 +231,6 @@ async def process_non_streaming_response(request: ChatRequest):
242
 
243
  cleaned_full_response = strip_model_prefix(full_response, model_prefix)
244
 
245
- # Append the custom message for free users
246
- if request.is_free_user and FREE_USER_MESSAGE:
247
- cleaned_full_response += f"\n\n{FREE_USER_MESSAGE}"
248
-
249
  return {
250
  "id": f"chatcmpl-{uuid.uuid4()}",
251
  "object": "chat.completion",
@@ -259,4 +244,4 @@ async def process_non_streaming_response(request: ChatRequest):
259
  }
260
  ],
261
  "usage": None,
262
- }
 
 
 
 
1
  from datetime import datetime
2
  import json
3
  import uuid
 
27
  # Define the blocked message
28
  BLOCKED_MESSAGE = "Generated by BLACKBOX.AI, try unlimited chat https://www.blackbox.ai"
29
 
 
 
 
30
  # Helper function to create chat completion data
31
  def create_chat_completion_data(
32
  content: str, model: str, timestamp: int, finish_reason: Optional[str] = None
 
145
  cleaned_content = strip_model_prefix(content, model_prefix)
146
  yield f"data: {json.dumps(create_chat_completion_data(cleaned_content, request.model, timestamp))}\n\n"
147
 
148
+ yield f"data: {json.dumps(create_chat_completion_data('', request.model, timestamp, 'stop'))}\n\n"
 
 
 
 
 
149
  yield "data: [DONE]\n\n"
150
  except httpx.HTTPStatusError as e:
151
  logger.error(f"HTTP error occurred for Request ID {request_id}: {e}")
 
231
 
232
  cleaned_full_response = strip_model_prefix(full_response, model_prefix)
233
 
 
 
 
 
234
  return {
235
  "id": f"chatcmpl-{uuid.uuid4()}",
236
  "object": "chat.completion",
 
244
  }
245
  ],
246
  "usage": None,
247
+ }