Merge branch 'refs/heads/release/v0.2.3' into fix/release_memory_bug
This commit is contained in:
@@ -182,27 +182,35 @@ def _get_ontology_service(
|
|||||||
detail=f"找不到指定的LLM模型: {llm_id}"
|
detail=f"找不到指定的LLM模型: {llm_id}"
|
||||||
)
|
)
|
||||||
|
|
||||||
# 验证模型配置了API密钥
|
# 通过 Repository 获取可用的 API Key(负载均衡逻辑由 Repository 处理)
|
||||||
if not model_config.api_keys:
|
from app.repositories.model_repository import ModelApiKeyRepository
|
||||||
logger.error(f"Model {llm_id} has no API key configuration")
|
api_keys = ModelApiKeyRepository.get_by_model_config(db, model_config.id)
|
||||||
|
if not api_keys:
|
||||||
|
logger.error(f"Model {llm_id} has no active API key")
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=400,
|
status_code=400,
|
||||||
detail="指定的LLM模型没有配置API密钥"
|
detail="指定的LLM模型没有可用的API密钥"
|
||||||
)
|
)
|
||||||
|
api_key_config = api_keys[0]
|
||||||
|
|
||||||
api_key_config = model_config.api_keys[0]
|
is_composite = getattr(model_config, 'is_composite', False)
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
f"Using specified model - user: {current_user.id}, "
|
f"Using specified model - user: {current_user.id}, "
|
||||||
f"model_id: {llm_id}, model_name: {api_key_config.model_name}"
|
f"model_id: {llm_id}, model_name: {api_key_config.model_name}, "
|
||||||
|
f"is_composite: {is_composite}, api_key_id: {api_key_config.id}"
|
||||||
)
|
)
|
||||||
|
|
||||||
# 创建模型配置对象
|
# 创建模型配置对象
|
||||||
from app.core.models.base import RedBearModelConfig
|
from app.core.models.base import RedBearModelConfig
|
||||||
|
|
||||||
|
# 对于组合模型,使用 API Key 的 provider;否则使用 model_config 的 provider
|
||||||
|
actual_provider = api_key_config.provider if is_composite else (
|
||||||
|
getattr(model_config, 'provider', None) or "openai"
|
||||||
|
)
|
||||||
|
|
||||||
llm_model_config = RedBearModelConfig(
|
llm_model_config = RedBearModelConfig(
|
||||||
model_name=api_key_config.model_name,
|
model_name=api_key_config.model_name,
|
||||||
provider=model_config.provider if hasattr(model_config, 'provider') else "openai",
|
provider=actual_provider,
|
||||||
api_key=api_key_config.api_key,
|
api_key=api_key_config.api_key,
|
||||||
base_url=api_key_config.api_base,
|
base_url=api_key_config.api_base,
|
||||||
max_retries=3,
|
max_retries=3,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import base64
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
|
import urllib.parse
|
||||||
from string import Template
|
from string import Template
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
from typing import Any
|
from typing import Any
|
||||||
@@ -101,6 +102,7 @@ class CodeNode(BaseNode):
|
|||||||
code = base64.b64decode(
|
code = base64.b64decode(
|
||||||
self.typed_config.code
|
self.typed_config.code
|
||||||
).decode("utf-8")
|
).decode("utf-8")
|
||||||
|
code = urllib.parse.unquote(code, encoding='utf-8')
|
||||||
|
|
||||||
input_variable_dict = base64.b64encode(
|
input_variable_dict = base64.b64encode(
|
||||||
json.dumps(input_variable_dict).encode("utf-8")
|
json.dumps(input_variable_dict).encode("utf-8")
|
||||||
|
|||||||
@@ -188,6 +188,6 @@ class AppStatisticsService:
|
|||||||
daily_tokens[date_str] += int(tokens)
|
daily_tokens[date_str] += int(tokens)
|
||||||
|
|
||||||
daily_data = [{"date": date, "count": tokens} for date, tokens in sorted(daily_tokens.items()) if tokens != 0]
|
daily_data = [{"date": date, "count": tokens} for date, tokens in sorted(daily_tokens.items()) if tokens != 0]
|
||||||
total = sum(row["tokens"] for row in daily_data)
|
total = sum(row["count"] for row in daily_data)
|
||||||
|
|
||||||
return {"daily": daily_data, "total": total}
|
return {"daily": daily_data, "total": total}
|
||||||
|
|||||||
Reference in New Issue
Block a user