Merge pull request #15 from xpack-ai/feature/0.3-backend
Feature/0.3 backend
This commit is contained in:
5 files changed
+36
-10
No files matched your search
@@ -12,6 +12,8 @@ from services.common.utils.cache_utils import CacheUtils
|
||||
from services.common.redis_keys import RedisKeys
|
||||
from services.admin_service.utils.user_utils import UserUtils
|
||||
from services.common import error_msg
|
||||
from services.common.models.mcp_service import ChargeType
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -199,7 +201,9 @@ def get_mcp_service_list(
|
||||
"auth_header": service.auth_header,
|
||||
"auth_token": service.auth_token,
|
||||
"charge_type": service.charge_type.value if service.charge_type else None,
|
||||
"price": float(service.price) if service.price else 0.0,
|
||||
"price": str(float(service.price)) if service.price and service.charge_type == ChargeType.PER_CALL else "0.00",
|
||||
"input_token_price": str(float(service.input_token_price)) if service.input_token_price and service.charge_type == ChargeType.PER_TOKEN else "0.00",
|
||||
"output_token_price": str(float(service.output_token_price)) if service.output_token_price and service.charge_type == ChargeType.PER_TOKEN else "0.00",
|
||||
"enabled": service.enabled,
|
||||
"tags": parse_tags_to_array(service.tags),
|
||||
"created_at": str(service.created_at) if service.created_at else None,
|
||||
|
||||
@@ -117,6 +117,8 @@ class McpManagerService:
|
||||
existing_service.auth_token = temp_service.auth_token
|
||||
existing_service.charge_type = ChargeType(temp_service.charge_type.value)
|
||||
existing_service.price = temp_service.price
|
||||
existing_service.input_token_price = temp_service.input_token_price
|
||||
existing_service.output_token_price = temp_service.output_token_price
|
||||
existing_service.enabled = temp_service.enabled
|
||||
existing_service.tags = temp_service.tags
|
||||
|
||||
@@ -191,8 +193,15 @@ class McpManagerService:
|
||||
except ValueError:
|
||||
# If the provided value is not a valid ChargeType, default to FREE
|
||||
existing_service.charge_type = ChargeType.FREE
|
||||
if "price" in body and body["price"] is not None:
|
||||
existing_service.price = body["price"]
|
||||
match existing_service.charge_type:
|
||||
case ChargeType.PER_CALL:
|
||||
if "price" in body and body["price"] is not None:
|
||||
existing_service.price = body["price"]
|
||||
case ChargeType.PER_TOKEN:
|
||||
if "input_token_price" in body and body["input_token_price"] is not None:
|
||||
existing_service.input_token_price = body["input_token_price"]
|
||||
if "output_token_price" in body and body["output_token_price"] is not None:
|
||||
existing_service.output_token_price = body["output_token_price"]
|
||||
if "tags" in body and body["tags"] is not None:
|
||||
# If provided as array, convert to string for storage
|
||||
if isinstance(body["tags"], list):
|
||||
@@ -277,7 +286,9 @@ class McpManagerService:
|
||||
"auth_header": service.auth_header,
|
||||
"auth_token": service.auth_token,
|
||||
"charge_type": service.charge_type.value if service.charge_type else None,
|
||||
"price": str(float(service.price)) if service.price else "0.00",
|
||||
"price": str(float(service.price)) if service.price and service.charge_type == ChargeType.PER_CALL else "0.00",
|
||||
"input_token_price": str(float(service.input_token_price)) if service.input_token_price and service.charge_type == ChargeType.PER_TOKEN else "0.00",
|
||||
"output_token_price": str(float(service.output_token_price)) if service.output_token_price and service.charge_type == ChargeType.PER_TOKEN else "0.00",
|
||||
"enabled": service.enabled,
|
||||
"tags": parse_tags_to_array(service.tags),
|
||||
"apis": [{"id": api.id, "name": api.name, "description": api.description,"url":api.path} for api in apis],
|
||||
|
||||
@@ -44,7 +44,13 @@ class McpService(Base):
|
||||
nullable=False,
|
||||
comment="Charge type: free, per_call, per_token",
|
||||
)
|
||||
price: Mapped[float] = mapped_column(Numeric(10, 2), nullable=False, comment="Service price (2 decimal places)")
|
||||
price: Mapped[float] = mapped_column(Numeric(10, 2), nullable=True, comment="Service price (2 decimal places)")
|
||||
input_token_price: Mapped[float] = mapped_column(
|
||||
Numeric(10, 2), nullable=True, comment="Input token price (2 decimal places, for per_token charge type)"
|
||||
)
|
||||
output_token_price: Mapped[float] = mapped_column(
|
||||
Numeric(10, 2), nullable=True, comment="Output token price (2 decimal places, for per_token charge type)"
|
||||
)
|
||||
enabled: Mapped[int] = mapped_column(Integer, nullable=True, comment="Service status: 0=disabled, 1=enabled")
|
||||
tags: Mapped[str] = mapped_column(String, nullable=True, comment="Tags")
|
||||
created_at: Mapped[datetime] = mapped_column(
|
||||
|
||||
@@ -44,7 +44,13 @@ class TempMcpService(Base):
|
||||
nullable=False,
|
||||
comment="Charge type: free, per_call, per_token",
|
||||
)
|
||||
price: Mapped[float] = mapped_column(Numeric(10, 2), nullable=False, comment="Service price (2 decimal places)")
|
||||
price: Mapped[float] = mapped_column(Numeric(10, 2), nullable=True, comment="Service price (2 decimal places)")
|
||||
input_token_price: Mapped[float] = mapped_column(
|
||||
Numeric(10, 2), nullable=True, comment="Input token price (2 decimal places, for per_token charge type)"
|
||||
)
|
||||
output_token_price: Mapped[float] = mapped_column(
|
||||
Numeric(10, 2), nullable=True, comment="Output token price (2 decimal places, for per_token charge type)"
|
||||
)
|
||||
enabled: Mapped[int] = mapped_column(Integer, nullable=True, comment="Service status: 0=disabled, 1=enabled")
|
||||
tags: Mapped[str] = mapped_column(String, nullable=True, comment="Tags")
|
||||
created_at: Mapped[datetime] = mapped_column(
|
||||
|
||||
@@ -37,10 +37,9 @@ class User(Base):
|
||||
default=False,
|
||||
comment="Soft delete flag: 0=active, 1=deleted",
|
||||
)
|
||||
register_type: Mapped[str] = mapped_column(
|
||||
# Enum(RegisterType, values_callable=lambda obj: [e.value for e in obj]),
|
||||
String(36),
|
||||
nullable=False,
|
||||
register_type: Mapped[RegisterType] = mapped_column(
|
||||
Enum(RegisterType, values_callable=lambda obj: [e.value for e in obj]),
|
||||
nullable=False,
|
||||
comment="Registration method"
|
||||
)
|
||||
role_id: Mapped[int] = mapped_column(
|
||||
|
||||
Reference in new issue
Block a user