Fixed increase_usage for builtin models (#3748)

### What problem does this PR solve?

Fixed increase_usage for builtin models. Close #1803

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
Zhichang Yu 2024-11-29 17:02:49 +08:00 committed by GitHub
parent 0f08b0f053
commit 381219aa41
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -172,12 +172,17 @@ class TenantLLMService(CommonService):
num = 0
try:
for u in cls.query(tenant_id=tenant_id, llm_name=llm_name):
num += cls.model.update(used_tokens=u.used_tokens + used_tokens)\
.where(cls.model.tenant_id == tenant_id, cls.model.llm_name == llm_name)\
tenant_llms = cls.query(tenant_id=tenant_id, llm_name=llm_name)
if tenant_llms:
tenant_llm = tenant_llms[0]
num = cls.model.update(used_tokens=tenant_llm.used_tokens + used_tokens)\
.where(cls.model.tenant_id == tenant_id, cls.model.llm_factory == tenant_llm.llm_factory, cls.model.llm_name == llm_name)\
.execute()
except Exception as e:
pass
else:
llm_factory = llm_name.split("/")[0] if "/" in llm_name else llm_name
num = cls.model.create(tenant_id=tenant_id, llm_factory=llm_factory, llm_name=llm_name, used_tokens=used_tokens)
except Exception:
logging.exception("TenantLLMService.increase_usage got exception")
return num
@classmethod