fix: 修复text-to-audio 记得添加 api_token

fix: 修复监控界面刷新每次会先显示半秒余额15后才切换为真实值
fix: 添加使用统计
This commit is contained in:
npc0-hue
2025-11-07 09:59:03 +08:00
committed by FamousMai
parent 52e99cf180
commit bcd2ff4a45
3 changed files with 15 additions and 3 deletions
+1 -1
View File
@@ -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.
@@ -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
)
@@ -5,7 +5,7 @@ import type { UserMoney } from '@/models/common-extend'
import cn from 'classnames'
const AccountMoneyExtend = () => {
const [userMoney, setUserMoney] = useState<UserMoney>({ used_quota: 0, total_quota: 15 })
const [userMoney, setUserMoney] = useState<UserMoney>({ 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)