Spaces:
Runtime error
Runtime error
远兮
commited on
Commit
·
dfa9a8a
1
Parent(s):
0cd8d81
添加优先消耗免费次数
Browse files- chatgpt-next-web/service.py +23 -12
chatgpt-next-web/service.py
CHANGED
@@ -265,8 +265,11 @@ def proxy_chat_completions():
|
|
265 |
# 获取 OpenAI API 的响应数据
|
266 |
result = response.iter_content(chunk_size=8192)
|
267 |
|
268 |
-
|
269 |
-
|
|
|
|
|
|
|
270 |
|
271 |
# 返回 OpenAI API 的响应给客户端
|
272 |
return Response(result, content_type=response.headers['content-type'])
|
@@ -278,8 +281,11 @@ def proxy_chat_completions():
|
|
278 |
# 获取 OpenAI API 的响应数据
|
279 |
result = response.json()
|
280 |
|
281 |
-
|
282 |
-
|
|
|
|
|
|
|
283 |
|
284 |
# 返回 OpenAI API 的响应给客户端
|
285 |
return result, response.status_code
|
@@ -452,17 +458,16 @@ def get_package_expiration(user_id):
|
|
452 |
# 检查用户聊天次数是否超过限制
|
453 |
def exceeded_chat_limit(user_id, package, model):
|
454 |
if model == 'gpt-3.5-turbo':
|
455 |
-
|
456 |
-
basic_chat_limit
|
457 |
-
|
458 |
-
|
|
|
459 |
return True
|
460 |
|
461 |
if model == 'gpt-4':
|
462 |
-
|
463 |
-
advanced_chat_limit
|
464 |
-
b'advanced_chat_limit', 0).decode('utf-8'))
|
465 |
-
if advanced_chat_limit >= 0 and int(redis.get(user_advanced_chat_key) or 0) >= advanced_chat_limit:
|
466 |
return True
|
467 |
|
468 |
return False
|
@@ -546,5 +551,11 @@ def pick_up_free_chat_count(user_id):
|
|
546 |
return True
|
547 |
|
548 |
|
|
|
|
|
|
|
|
|
|
|
|
|
549 |
if __name__ == '__main__':
|
550 |
app.run(debug=True)
|
|
|
265 |
# 获取 OpenAI API 的响应数据
|
266 |
result = response.iter_content(chunk_size=8192)
|
267 |
|
268 |
+
if get_free_count(user_id) > 0 and model == 'gpt-3.5-turbo':
|
269 |
+
redis.hincrby(f'user:{user_id}:free', 'basic_chat_count', -1)
|
270 |
+
else:
|
271 |
+
user_package_key = f'user:{user_id}:package'
|
272 |
+
redis.hincrby(user_package_key, 'basic_chat_limit', -1)
|
273 |
|
274 |
# 返回 OpenAI API 的响应给客户端
|
275 |
return Response(result, content_type=response.headers['content-type'])
|
|
|
281 |
# 获取 OpenAI API 的响应数据
|
282 |
result = response.json()
|
283 |
|
284 |
+
if get_free_count(user_id) > 0 and model == 'gpt-3.5-turbo':
|
285 |
+
redis.hincrby(f'user:{user_id}:free', 'basic_chat_count', -1)
|
286 |
+
else:
|
287 |
+
user_package_key = f'user:{user_id}:package'
|
288 |
+
redis.hincrby(user_package_key, 'basic_chat_limit', -1)
|
289 |
|
290 |
# 返回 OpenAI API 的响应给客户端
|
291 |
return result, response.status_code
|
|
|
458 |
# 检查用户聊天次数是否超过限制
|
459 |
def exceeded_chat_limit(user_id, package, model):
|
460 |
if model == 'gpt-3.5-turbo':
|
461 |
+
basic_chat_limit = int(package.get(b'basic_chat_limit', 0))
|
462 |
+
print('basic_chat_limit:', basic_chat_limit)
|
463 |
+
if get_free_count(user_id) > 0:
|
464 |
+
return False
|
465 |
+
if basic_chat_limit <= 0:
|
466 |
return True
|
467 |
|
468 |
if model == 'gpt-4':
|
469 |
+
advanced_chat_limit = int(package.get(b'advanced_chat_limit', 0))
|
470 |
+
if advanced_chat_limit <= 0:
|
|
|
|
|
471 |
return True
|
472 |
|
473 |
return False
|
|
|
551 |
return True
|
552 |
|
553 |
|
554 |
+
def get_free_count(user_id):
|
555 |
+
free_data = get_user_free_data(user_id)
|
556 |
+
basic_chat_count = free_data.get(b'basic_chat_count', 0)
|
557 |
+
return int(basic_chat_count)
|
558 |
+
|
559 |
+
|
560 |
if __name__ == '__main__':
|
561 |
app.run(debug=True)
|