From 4f45567ea92c76a50db7581c570b94553af5975c Mon Sep 17 00:00:00 2001 From: takatost Date: Fri, 20 Oct 2023 00:08:11 +0800 Subject: [PATCH] feat: adjust anthropic trial rule --- api/core/model_providers/model_provider_factory.py | 12 ++++++------ api/core/model_providers/rules/anthropic.json | 3 ++- api/services/provider_service.py | 13 ------------- 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/api/core/model_providers/model_provider_factory.py b/api/core/model_providers/model_provider_factory.py index c2c3aa1b6951e0..77f77573475a1c 100644 --- a/api/core/model_providers/model_provider_factory.py +++ b/api/core/model_providers/model_provider_factory.py @@ -183,12 +183,12 @@ def _get_preferred_provider(cls, tenant_id: str, model_provider_name: str): model_provider_rules = ModelProviderFactory.get_provider_rule(model_provider_name) for quota_type_enum in ProviderQuotaType: quota_type = quota_type_enum.value - if quota_type in quota_type_to_provider_dict.keys(): - provider = quota_type_to_provider_dict[quota_type] - if provider.is_valid and provider.quota_limit > provider.quota_used: - return provider - elif quota_type == ProviderQuotaType.TRIAL.value: - if quota_type in model_provider_rules['system_config']['supported_quota_types']: + if quota_type in model_provider_rules['system_config']['supported_quota_types']: + if quota_type in quota_type_to_provider_dict.keys(): + provider = quota_type_to_provider_dict[quota_type] + if provider.is_valid and provider.quota_limit > provider.quota_used: + return provider + elif quota_type == ProviderQuotaType.TRIAL.value: try: provider = Provider( tenant_id=tenant_id, diff --git a/api/core/model_providers/rules/anthropic.json b/api/core/model_providers/rules/anthropic.json index d12ae3659c6176..e617842b94d9c0 100644 --- a/api/core/model_providers/rules/anthropic.json +++ b/api/core/model_providers/rules/anthropic.json @@ -5,7 +5,8 @@ ], "system_config": { "supported_quota_types": [ - "paid" + "paid", + "trial" ], "quota_unit": "tokens", "quota_limit": 0 diff --git a/api/services/provider_service.py b/api/services/provider_service.py index c01b1f6735980c..f9acedf8c24f54 100644 --- a/api/services/provider_service.py +++ b/api/services/provider_service.py @@ -135,19 +135,6 @@ def get_provider_list(self, tenant_id: str): provider_parameter_dict[key]['quota_limit'] = provider.quota_limit provider_parameter_dict[key]['last_used'] = int(provider.last_used.timestamp()) \ if provider.last_used else None - else: - provider_parameter_dict[key] = { - "provider_name": model_provider_name, - "provider_type": ProviderType.SYSTEM.value, - "config": None, - "is_valid": provider.is_valid, - "quota_type": quota_type, - "quota_unit": model_provider_rule['system_config']['quota_unit'], # need update - "quota_limit": provider.quota_limit, - "quota_used": provider.quota_used, - "last_used": int(provider.last_used.timestamp()) \ - if provider.last_used else None - } elif provider.provider_type == ProviderType.CUSTOM.value \ and ProviderType.CUSTOM.value in provider_parameter_dict: # if custom