From 11264d302d231f2bc34a187f49dae9e07090e36b Mon Sep 17 00:00:00 2001 From: Liujian <824010343@qq.com> Date: Wed, 30 Jul 2025 15:57:10 +0800 Subject: [PATCH] fix mcp service --- services/api_service/services/billing_service.py | 3 +++ services/api_service/services/mcp_server_factory.py | 12 ++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/services/api_service/services/billing_service.py b/services/api_service/services/billing_service.py index 10448ef..2791d50 100644 --- a/services/api_service/services/billing_service.py +++ b/services/api_service/services/billing_service.py @@ -130,6 +130,9 @@ class BillingService: api_id=call_log.api_id, tool_name=call_log.tool_name, input_params=call_log.input_params, + input_token=call_log.input_token, + output_token=call_log.output_token, + charge_type=call_log.charge_type, call_success=call_success, unit_price=call_log.unit_price, call_start_time=call_log.call_start_time, diff --git a/services/api_service/services/mcp_server_factory.py b/services/api_service/services/mcp_server_factory.py index e9ead51..f283663 100644 --- a/services/api_service/services/mcp_server_factory.py +++ b/services/api_service/services/mcp_server_factory.py @@ -133,6 +133,9 @@ class McpServerFactory: unit_price=pre_deduct_result.service_price, call_start_time=call_start_time, call_end_time=datetime.now(timezone.utc), + input_token=Decimal("0"), + output_token=Decimal("0"), + charge_type=pre_deduct_result.charge_type, apikey_id=apikey_id, ) await self.billing_service.send_billing_message(call_log, False, datetime.now(timezone.utc)) @@ -148,8 +151,8 @@ class McpServerFactory: # calculate input token amount input_token_amount = Decimal("0") output_token_amount = Decimal("0") - input_token = 0 - output_token = 0 + input_token = Decimal("0") + output_token = Decimal("0") # Calculate input token amount based on charge type if pre_deduct_result.charge_type == "per_token": @@ -212,8 +215,9 @@ class McpServerFactory: tool_name=name, input_params=json.dumps(arguments), unit_price=input_token_amount + output_token_amount, - input_token=input_token, - output_token=output_token, + input_token=Decimal(str(input_token)), + output_token=Decimal(str(output_token)), + charge_type=pre_deduct_result.charge_type, call_start_time=call_start_time, call_end_time=call_end_time, apikey_id=apikey_id,