Skip to content
Open
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
6 changes: 6 additions & 0 deletions astrbot/core/config/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,7 @@
"key": [],
"api_base": "https://api.openai.com/v1",
"timeout": 120,
"max_retries": 10,
Comment thread
Blueteemo marked this conversation as resolved.
"proxy": "",
"custom_headers": {},
},
Expand Down Expand Up @@ -2510,6 +2511,11 @@
"type": "int",
"hint": "超时时间,单位为秒。",
},
"max_retries": {
"description": "最大重试次数",
"type": "int",
"hint": "API 调用失败时的最大重试次数,范围 1-50,默认为 10。",
},
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
"mimo-stt-system-prompt": {
"description": "系统提示词",
"type": "string",
Expand Down
29 changes: 27 additions & 2 deletions astrbot/core/provider/sources/openai_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,31 @@ def __init__(self, provider_config, provider_settings) -> None:
self.set_model(model)

self.reasoning_key = "reasoning_content"
self.max_retries = self._get_max_retries()

_MAX_RETRIES_DEFAULT = 10
_MAX_RETRIES_UPPER_BOUND = 50

def _get_max_retries(self) -> int:
"""获取并验证最大重试次数,确保为 1 到 _MAX_RETRIES_UPPER_BOUND 之间的整数。"""
raw = self.provider_config.get("max_retries", self._MAX_RETRIES_DEFAULT)
try:
value = int(raw)
except (TypeError, ValueError):
logger.warning(
"max_retries 配置无效 (%s),使用默认值 %d。",
raw,
self._MAX_RETRIES_DEFAULT,
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
)
return self._MAX_RETRIES_DEFAULT
clamped = max(1, min(value, self._MAX_RETRIES_UPPER_BOUND))
if clamped != value:
logger.warning(
"max_retries 配置值 %d 超出范围,已调整为 %d。",
value,
clamped,
)
return clamped

def _ollama_disable_thinking_enabled(self) -> bool:
value = self.provider_config.get("ollama_disable_thinking", False)
Expand Down Expand Up @@ -1189,7 +1214,7 @@ async def text_chat(
payloads["tool_choice"] = tool_choice

llm_response = None
max_retries = 10
max_retries = self.max_retries
available_api_keys = self.api_keys.copy()
chosen_key = random.choice(available_api_keys)
image_fallback_used = False
Expand Down Expand Up @@ -1260,7 +1285,7 @@ async def text_chat_stream(
if func_tool and not func_tool.empty():
payloads["tool_choice"] = tool_choice

max_retries = 10
max_retries = self.max_retries
available_api_keys = self.api_keys.copy()
chosen_key = random.choice(available_api_keys)
image_fallback_used = False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,11 @@
"description": "Timeout",
"hint": "Timeout in seconds."
},
"max_retries": {
"description": "Max Retries",
"type": "int",
"hint": "Maximum number of retries when API call fails, range 1-50, default is 10."
},
"mimo-stt-system-prompt": {
"description": "System prompt",
"hint": "System prompt used to guide MiMo STT transcription behavior."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,11 @@
"description": "Таймаут (сек)",
"hint": "Максимальное время ожидания ответа."
},
"max_retries": {
"description": "Макс. попыток",
"type": "int",
"hint": "Максимальное количество повторных попыток при ошибке API, диапазон 1-50, по умолчанию 10."
},
"mimo-stt-system-prompt": {
"description": "Системный промпт",
"hint": "System prompt, который управляет поведением MiMo STT при распознавании."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1516,6 +1516,11 @@
"description": "超时时间",
"hint": "超时时间,单位为秒。"
},
"max_retries": {
"description": "最大重试次数",
"type": "int",
"hint": "API 调用失败时的最大重试次数,范围 1-50,默认为 10。"
},
"mimo-stt-system-prompt": {
"description": "系统提示词",
"hint": "用于指导 MiMo STT 转录行为的 system prompt。"
Expand Down
Loading