From bcd2ff4a45fbc7f9d5b9f4a82bfa0ec530dfb407 Mon Sep 17 00:00:00 2001 From: npc0-hue Date: Fri, 7 Nov 2025 09:59:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dtext-to-audio=20?= =?UTF-8?q?=E8=AE=B0=E5=BE=97=E6=B7=BB=E5=8A=A0=20api=5Ftoken=20fix:=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=9B=91=E6=8E=A7=E7=95=8C=E9=9D=A2=E5=88=B7?= =?UTF-8?q?=E6=96=B0=E6=AF=8F=E6=AC=A1=E4=BC=9A=E5=85=88=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E5=8D=8A=E7=A7=92=E4=BD=99=E9=A2=9D15=E5=90=8E=E6=89=8D?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E4=B8=BA=E7=9C=9F=E5=AE=9E=E5=80=BC=20fix:?= =?UTF-8?q?=20=E6=B7=BB=E5=8A=A0=E4=BD=BF=E7=94=A8=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/controllers/service_api/app/audio.py | 2 +- api/controllers/service_api/app/completion.py | 8 ++++++++ web/app/components/header/account-money-extend/index.tsx | 8 ++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/api/controllers/service_api/app/audio.py b/api/controllers/service_api/app/audio.py index dd27c99ee..fe2b72542 100644 --- a/api/controllers/service_api/app/audio.py +++ b/api/controllers/service_api/app/audio.py @@ -106,7 +106,7 @@ class TextApi(Resource): } ) @validate_app_token(fetch_user_arg=FetchUserArg(fetch_from=WhereisUserArg.JSON)) - def post(self, app_model: App, end_user: EndUser): + def post(self, app_model: App, end_user: EndUser, api_token: ApiToken): # 二开部分End - 密钥额度限制,新增api_token """Convert text to audio using text-to-speech. Converts the provided text to audio using the specified voice. diff --git a/api/controllers/service_api/app/completion.py b/api/controllers/service_api/app/completion.py index 7aaa7a32c..3b27d318a 100644 --- a/api/controllers/service_api/app/completion.py +++ b/api/controllers/service_api/app/completion.py @@ -30,6 +30,7 @@ from libs import helper from libs.helper import uuid_value from models.model import ApiToken, App, AppMode, EndUser # 二开部分End - 密钥额度限制,新增ApiToken from services.app_generate_service import AppGenerateService +from services.app_generate_service_extend import AppGenerateServiceExtend from services.errors.app import IsDraftWorkflowError, WorkflowIdFormatError, WorkflowNotFoundError from services.errors.llm import InvokeRateLimitError @@ -204,6 +205,13 @@ class ChatApi(Resource): # # ------------------- 二开部分End - 密钥额度限制 ------------------- try: + # ------------------- 二开部分Begin - 添加使用统计 ------------------- + AppGenerateServiceExtend.calculate_cumulative_usage( + app_model=app_model, + args=args, + ) # Extend: App + # ------------------- 二开部分End - 添加使用统计 ------------------- + response = AppGenerateService.generate( app_model=app_model, user=end_user, args=args, invoke_from=InvokeFrom.SERVICE_API, streaming=streaming ) diff --git a/web/app/components/header/account-money-extend/index.tsx b/web/app/components/header/account-money-extend/index.tsx index 3d8c4da4f..214e99bf7 100644 --- a/web/app/components/header/account-money-extend/index.tsx +++ b/web/app/components/header/account-money-extend/index.tsx @@ -5,7 +5,7 @@ import type { UserMoney } from '@/models/common-extend' import cn from 'classnames' const AccountMoneyExtend = () => { - const [userMoney, setUserMoney] = useState({ used_quota: 0, total_quota: 15 }) + const [userMoney, setUserMoney] = useState({ used_quota: 0, total_quota: 0 }) const [isFetched, setIsFetched] = useState(false) const exchangeRate = 7.26 // 美元转人民币固定汇率 @@ -24,9 +24,13 @@ const AccountMoneyExtend = () => { // 计算额度(确保使用数字类型) const usedQuota = Number(userMoney.used_quota) || 0 - const totalQuota = Number(userMoney.total_quota) || 15 + const totalQuota = Number(userMoney.total_quota) || 0 const remainingQuota = totalQuota - usedQuota + // 当总额度为0时不显示 + if (totalQuota === 0) + return null + // 转换为人民币并保留2位小数 const usedRMB = (usedQuota * exchangeRate).toFixed(2) const totalRMB = (totalQuota * exchangeRate).toFixed(2)