From 849d9eb463c22849ec619824e86c7d5305d2958e Mon Sep 17 00:00:00 2001 From: Kevin Hu Date: Fri, 14 Feb 2025 11:10:49 +0800 Subject: [PATCH] Ignore tenant not found error while increasing token usage. (#4950) ### What problem does this PR solve? #4940 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- api/db/services/llm_service.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/api/db/services/llm_service.py b/api/db/services/llm_service.py index da14f8c21..efca4339d 100644 --- a/api/db/services/llm_service.py +++ b/api/db/services/llm_service.py @@ -173,7 +173,8 @@ class TenantLLMService(CommonService): def increase_usage(cls, tenant_id, llm_type, used_tokens, llm_name=None): e, tenant = TenantService.get_by_id(tenant_id) if not e: - raise LookupError("Tenant not found") + logging.error(f"Tenant not found: {tenant_id}") + return 0 llm_map = { LLMType.EMBEDDING.value: tenant.embd_id, @@ -186,7 +187,8 @@ class TenantLLMService(CommonService): mdlnm = llm_map.get(llm_type) if mdlnm is None: - raise ValueError("LLM type error") + logging.error(f"LLM type error: {llm_type}") + return 0 llm_name, llm_factory = TenantLLMService.split_model_name_and_factory(mdlnm)