Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions astrbot/core/config/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -2731,6 +2731,11 @@
"type": "int",
"hint": "模型最大上下文 Token 大小。如果为 0,则会自动从模型元数据填充(如有)",
},
"reasoning": {
"description": "支持推理能力",
"type": "bool",
"hint": "标记该模型是否支持推理/思考能力。此项为元数据标记,不影响实际 API 调用。",
},
"dify_api_key": {
"description": "API Key",
"type": "string",
Expand Down
16 changes: 13 additions & 3 deletions astrbot/dashboard/services/config_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ def try_cast(value: Any, type_: str):
return float(value)
except (ValueError, TypeError):
return None
elif type_ == "bool" and isinstance(value, str):
lowered = value.strip().lower()
if lowered in ("true", "1"):
return True
if lowered in ("false", "0"):
return False
return None


def _expect_type(value, expected_type, path_key, errors, expected_name=None) -> bool:
Expand Down Expand Up @@ -276,9 +283,12 @@ def validate(data: dict, metadata: dict = schema, path="") -> None:
)
data[key] = casted

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Avoid assigning data[key] = casted when casting fails and returns None.

In the bool branch, data[key] is updated even when casted is None, so invalid values are both logged as errors and overwritten with None. This differs from other types, where the original value is kept on failure. Please only update data[key] when casting succeeds, e.g.:

data[key] = casted if casted is not None else value

or skip assignment when casted is None.

elif meta["type"] == "bool" and not isinstance(value, bool):
errors.append(
f"错误的类型 {path}{key}: 期望是 bool, 得到了 {type(value).__name__}",
)
casted = try_cast(value, "bool")
if casted is None:
errors.append(
f"错误的类型 {path}{key}: 期望是 bool, 得到了 {type(value).__name__}",
)
data[key] = casted
elif meta["type"] in ["string", "text"] and not isinstance(value, str):
errors.append(
f"错误的类型 {path}{key}: 期望是 string, 得到了 {type(value).__name__}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1700,6 +1700,10 @@
"description": "Model context window size",
"hint": "Maximum context tokens. If 0, it auto-fills from model metadata (if available); you can also edit manually."
},
"reasoning": {
"description": "Supports reasoning",
"hint": "Whether this model supports reasoning/thinking capabilities. This is a metadata flag and does not affect actual API calls."
},
"dify_api_key": {
"description": "API Key",
"hint": "Dify API Key. This field is required."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1697,6 +1697,10 @@
"description": "Размер окна контекста модели",
"hint": "Максимальное количество токенов контекста. Если 0 — автозаполнение."
},
"reasoning": {
"description": "Поддерживает рассуждения",
"hint": "Поддерживает ли модель рассуждения/мышление. Это метаданные, не влияет на вызовы API."
},
"dify_api_key": {
"description": "Базовый URL для Coze API. По умолчанию: https://api.coze.cn",
"hint": "API-ключ Dify (обязательно)."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1702,6 +1702,10 @@
"description": "模型上下文窗口大小",
"hint": "模型最大上下文 Token 大小。如果为 0,则会自动从模型元数据填充(如有)。"
},
"reasoning": {
"description": "支持推理能力",
"hint": "标记该模型是否支持推理/思考能力。此项为元数据标记,不影响实际 API 调用。"
},
"dify_api_key": {
"description": "API Key",
"hint": "Dify API Key。此项必填。"
Expand Down
Loading