mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 17:30:23 +08:00
refactor: 移除 Provider/Endpoint 级别的 timeout 配置,改用全局环境变量
- 废弃 Provider.timeout 和 ProviderEndpoint.timeout 字段(保留数据库列以兼容) - 非流式请求超时由 HTTP_REQUEST_TIMEOUT 环境变量控制(默认 300 秒) - 流式请求首字节超时由 STREAM_FIRST_BYTE_TIMEOUT 环境变量控制(默认 30 秒) - 移除前端表单中的超时配置输入框 - 简化 settings.py 中的 TTFB 超时解析逻辑 - 更新 API 请求/响应模型,移除 timeout 字段 - 更新导入导出功能,不再包含 timeout 配置
This commit is contained in:
@@ -477,7 +477,7 @@ class ChatHandlerBase(BaseMessageHandler, ABC):
|
||||
|
||||
# 配置 HTTP 超时
|
||||
# 注意:read timeout 用于检测连接断开,不是整体请求超时
|
||||
# 整体请求超时由 asyncio.wait_for 控制,使用 provider.timeout
|
||||
# 整体请求超时由 asyncio.wait_for 控制,使用全局配置
|
||||
timeout_config = httpx.Timeout(
|
||||
connect=config.http_connect_timeout,
|
||||
read=config.http_read_timeout, # 使用全局配置,用于检测连接断开
|
||||
@@ -485,8 +485,8 @@ class ChatHandlerBase(BaseMessageHandler, ABC):
|
||||
pool=config.http_pool_timeout,
|
||||
)
|
||||
|
||||
# provider.timeout 作为整体请求超时(建立连接 + 获取首字节)
|
||||
request_timeout = float(provider.timeout or 300)
|
||||
# 流式请求使用 stream_first_byte_timeout 作为首字节超时
|
||||
request_timeout = config.stream_first_byte_timeout
|
||||
|
||||
# 创建 HTTP 客户端(支持代理配置,从 Provider 读取)
|
||||
from src.clients.http_client import HTTPClientPool
|
||||
@@ -528,7 +528,7 @@ class ChatHandlerBase(BaseMessageHandler, ABC):
|
||||
|
||||
try:
|
||||
# 使用 asyncio.wait_for 包裹整个"建立连接 + 获取首字节"阶段
|
||||
# provider.timeout 控制整体超时,避免上游长时间无响应
|
||||
# stream_first_byte_timeout 控制首字节超时,避免上游长时间无响应
|
||||
await asyncio.wait_for(_connect_and_prefetch(), timeout=request_timeout)
|
||||
|
||||
except asyncio.TimeoutError:
|
||||
@@ -717,7 +717,8 @@ class ChatHandlerBase(BaseMessageHandler, ABC):
|
||||
# 注意:使用 get_proxy_client 复用连接池,不再每次创建新客户端
|
||||
from src.clients.http_client import HTTPClientPool
|
||||
|
||||
request_timeout = float(provider.timeout or 300)
|
||||
# 非流式请求使用 http_request_timeout 作为整体超时
|
||||
request_timeout = config.http_request_timeout
|
||||
http_client = await HTTPClientPool.get_proxy_client(
|
||||
proxy_config=provider.proxy,
|
||||
)
|
||||
|
||||
@@ -490,8 +490,8 @@ class CliMessageHandlerBase(BaseMessageHandler):
|
||||
pool=config.http_pool_timeout,
|
||||
)
|
||||
|
||||
# provider.timeout 作为整体请求超时(建立连接 + 获取首字节)
|
||||
request_timeout = float(provider.timeout or 300)
|
||||
# 流式请求使用 stream_first_byte_timeout 作为首字节超时
|
||||
request_timeout = config.stream_first_byte_timeout
|
||||
|
||||
logger.debug(
|
||||
f" └─ [{self.request_id}] 发送流式请求: "
|
||||
@@ -539,7 +539,7 @@ class CliMessageHandlerBase(BaseMessageHandler):
|
||||
|
||||
try:
|
||||
# 使用 asyncio.wait_for 包裹整个"建立连接 + 获取首字节"阶段
|
||||
# provider.timeout 控制整体超时,避免上游长时间无响应
|
||||
# stream_first_byte_timeout 控制首字节超时,避免上游长时间无响应
|
||||
await asyncio.wait_for(_connect_and_prefetch(), timeout=request_timeout)
|
||||
|
||||
except asyncio.TimeoutError:
|
||||
@@ -1633,7 +1633,8 @@ class CliMessageHandlerBase(BaseMessageHandler):
|
||||
# 注意:使用 get_proxy_client 复用连接池,不再每次创建新客户端
|
||||
from src.clients.http_client import HTTPClientPool
|
||||
|
||||
request_timeout = float(provider.timeout or 300)
|
||||
# 非流式请求使用 http_request_timeout 作为整体超时
|
||||
request_timeout = config.http_request_timeout
|
||||
http_client = await HTTPClientPool.get_proxy_client(
|
||||
proxy_config=provider.proxy,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user