浏览代码

pref: optimize feature model_load_balancing_enabled value fetch speed… (#4933)

tags/0.6.10
takatost 1年前
父节点
当前提交
b20d173324
没有帐户链接到提交者的电子邮件
共有 1 个文件被更改,包括 10 次插入1 次删除
  1. 10
    1
      api/core/provider_manager.py

+ 10
- 1
api/core/provider_manager.py 查看文件

@@ -27,6 +27,7 @@ from core.model_runtime.entities.provider_entities import (
from core.model_runtime.model_providers import model_provider_factory
from extensions import ext_hosting_provider
from extensions.ext_database import db
from extensions.ext_redis import redis_client
from models.provider import (
LoadBalancingModelConfig,
Provider,
@@ -406,7 +407,15 @@ class ProviderManager:
:param tenant_id: workspace id
:return:
"""
model_load_balancing_enabled = FeatureService.get_features(tenant_id).model_load_balancing_enabled
cache_key = f"tenant:{tenant_id}:model_load_balancing_enabled"
cache_result = redis_client.get(cache_key)
if cache_result is None:
model_load_balancing_enabled = FeatureService.get_features(tenant_id).model_load_balancing_enabled
redis_client.setex(cache_key, 120, str(model_load_balancing_enabled))
else:
cache_result = cache_result.decode('utf-8')
model_load_balancing_enabled = cache_result == 'True'

if not model_load_balancing_enabled:
return dict()


正在加载...
取消
保存