update
This commit is contained in:
parent
4b414decdf
commit
355b61aff3
@ -211,12 +211,13 @@ async def chat(request: ChatRequest,
|
|||||||
session: Session = Depends(get_db)):
|
session: Session = Depends(get_db)):
|
||||||
|
|
||||||
# 检查用户是否订阅
|
# 检查用户是否订阅
|
||||||
|
is_member = False
|
||||||
user_subscription_manager = UserSubscriptionManager(session)
|
user_subscription_manager = UserSubscriptionManager(session)
|
||||||
user_subscription = user_subscription_manager.get_subscription_by_user_id(current_user["id"])
|
user_subscription = user_subscription_manager.get_subscription_by_user_id(current_user["id"])
|
||||||
is_member = user_subscription and user_subscription["expire_time"] > datetime.now()
|
if user_subscription:
|
||||||
user_points = current_user["points"]
|
is_member = user_subscription["expire_time"] > datetime.now()
|
||||||
|
|
||||||
if not is_member and user_points < 1:
|
if not is_member:
|
||||||
raise HTTPException(status_code=999, detail="你的免费次数不足,你可以订阅会员。")
|
raise HTTPException(status_code=999, detail="你的免费次数不足,你可以订阅会员。")
|
||||||
|
|
||||||
payload = {
|
payload = {
|
||||||
@ -247,11 +248,6 @@ async def chat(request: ChatRequest,
|
|||||||
detail=f"Failed to get response from Dify API: {response.text}"
|
detail=f"Failed to get response from Dify API: {response.text}"
|
||||||
)
|
)
|
||||||
|
|
||||||
# 扣除用户积分
|
|
||||||
if not is_member:
|
|
||||||
manager = UserManager(session)
|
|
||||||
manager.consume_user_points(current_user["id"], 1)
|
|
||||||
|
|
||||||
# 获取response的stream
|
# 获取response的stream
|
||||||
def stream_response():
|
def stream_response():
|
||||||
for chunk in response.iter_content(chunk_size=1024):
|
for chunk in response.iter_content(chunk_size=1024):
|
||||||
|
|||||||
@ -29,7 +29,7 @@ services:
|
|||||||
cryptoai-api:
|
cryptoai-api:
|
||||||
build: .
|
build: .
|
||||||
container_name: cryptoai-api
|
container_name: cryptoai-api
|
||||||
image: cryptoai-api:0.2.24
|
image: cryptoai-api:0.2.25
|
||||||
restart: always
|
restart: always
|
||||||
ports:
|
ports:
|
||||||
- "8000:8000"
|
- "8000:8000"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user