fix: 修复后台创建用户和工作流

This commit is contained in:
npc0-hue
2025-10-18 18:20:35 +08:00
committed by FamousMai
parent 17832f2424
commit 67cb3b876d
2 changed files with 18 additions and 12 deletions
+4 -3
View File
@@ -1,5 +1,6 @@
from sqlalchemy import or_
from extensions.ext_database import db
from models.account import *
from models.account import TenantAccountJoin
from models.provider import Provider, ProviderModel
@@ -10,7 +11,7 @@ class TenantExtendService:
@staticmethod
def create_default_tenant_member_if_not_exist(tenant_id: str, account_id: str, role: str = "normal") -> bool:
available_ta = (
TenantAccountJoin.query.filter_by(account_id=account_id, tenant_id=tenant_id)
db.session.query(TenantAccountJoin).filter_by(account_id=account_id, tenant_id=tenant_id)
.order_by(TenantAccountJoin.id.asc())
.first()
)
@@ -31,7 +32,7 @@ class TenantExtendService:
@staticmethod
def create_model_sync_config_if_not_exist(model_id: str, is_all: bool = True) -> bool:
available_ta = (
ModelSyncConfigExtend.query.filter_by(model_id=model_id).order_by(ModelSyncConfigExtend.id.asc()).first()
db.session.query(ModelSyncConfigExtend).filter_by(model_id=model_id).order_by(ModelSyncConfigExtend.id.asc()).first()
)
if available_ta:
@@ -91,7 +92,7 @@ class TenantExtendService:
@staticmethod
def create_provider_sync_config_if_not_exist(provider_id: str, is_all: bool = True) -> bool:
available_ta = (
ModelSyncConfigExtend.query.filter_by(model_id=provider_id).order_by(ModelSyncConfigExtend.id.asc()).first()
db.session.query(ModelSyncConfigExtend).filter_by(model_id=provider_id).order_by(ModelSyncConfigExtend.id.asc()).first()
)
if available_ta:
@@ -31,15 +31,23 @@ def update_account_money_when_workflow_node_execution_created_extend(
# 非大模型则跳过
if workflow_node_execution_dict.get("node_type") != NodeType.LLM.value:
return
node_id = workflow_node_execution_dict.get("id")
logging.info(click.style("工作流节点ID {}".format(node_id), fg="cyan"))
# 拿到费用
outputs_str = workflow_node_execution_dict.get("outputs")
outputs = json.loads(outputs_str) if outputs_str else {}
total_price = Decimal(outputs.get("usage", {}).get("total_price", 0))
currency = outputs.get("usage", {}).get("currency", "USD")
# 拿到费用 - 从 outputs 字段获取费用信息(参考原始代码)
outputs = workflow_node_execution_dict.get("outputs", {})
# 如果 outputs 是字符串,则解析 JSON;如果已经是字典,则直接使用
if isinstance(outputs, str):
outputs = json.loads(outputs) if outputs else {}
elif not isinstance(outputs, dict):
outputs = {}
usage = outputs.get("usage", {})
total_price = Decimal(usage.get("total_price", 0))
currency = usage.get("currency", "USD")
if total_price == 0:
return
price = float(total_price) if currency == "USD" else (
@@ -116,6 +124,3 @@ def update_account_money_when_workflow_node_execution_created_extend(
f"{format(price)} 异常报错,60秒后进行重试,", fg="red")
)
raise self.retry(exc=e, countdown=60)