fix(llm_models): 修复模型信息不存在时引发的属性错误
在处理模型信息 `model_info` 为 `None` 的情况下,直接访问 `model_info.name` 会导致 `AttributeError`。 此提交通过以下方式修复了该问题: - 在 `_select_model` 调用后立即将 `model_info.name` 赋值给 `model_name` 变量,确保后续使用时该变量已定义。 - 在 `_handle_error` 方法中,当 `model_info` 可能为 `None` 时,增加了一个条件检查,如果 `model_info` 不存在,则将 `model_name` 设为 "unknown",从而避免了潜在的 `AttributeError`。
This commit is contained in:
@@ -287,6 +287,7 @@ class LLMRequest:
|
|||||||
# 模型选择和请求准备
|
# 模型选择和请求准备
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
model_info, api_provider, client = self._select_model()
|
model_info, api_provider, client = self._select_model()
|
||||||
|
model_name = model_info.name
|
||||||
|
|
||||||
# 检查是否启用反截断
|
# 检查是否启用反截断
|
||||||
use_anti_truncation = getattr(self.model_for_task, "anti_truncation", False)
|
use_anti_truncation = getattr(self.model_for_task, "anti_truncation", False)
|
||||||
@@ -403,7 +404,7 @@ class LLMRequest:
|
|||||||
# 重试失败
|
# 重试失败
|
||||||
if raise_when_empty:
|
if raise_when_empty:
|
||||||
raise RuntimeError(f"经过 {max_empty_retry} 次重试后仍然无法生成有效回复")
|
raise RuntimeError(f"经过 {max_empty_retry} 次重试后仍然无法生成有效回复")
|
||||||
return "生成的响应为空,请检查模型配置或输入内容是否正确", ("", model_info.name, None)
|
return "生成的响应为空,请检查模型配置或输入内容是否正确", ("", model_name, None)
|
||||||
|
|
||||||
async def get_embedding(self, embedding_input: str) -> Tuple[List[float], str]:
|
async def get_embedding(self, embedding_input: str) -> Tuple[List[float], str]:
|
||||||
"""获取嵌入向量
|
"""获取嵌入向量
|
||||||
@@ -565,7 +566,7 @@ class LLMRequest:
|
|||||||
Returns:
|
Returns:
|
||||||
(等待间隔(如果为0则不等待,为-1则不再请求该模型), 新的消息列表(适用于压缩消息))
|
(等待间隔(如果为0则不等待,为-1则不再请求该模型), 新的消息列表(适用于压缩消息))
|
||||||
"""
|
"""
|
||||||
model_name = model_info.name
|
model_name = model_info.name if model_info else "unknown"
|
||||||
|
|
||||||
if isinstance(e, NetworkConnectionError): # 网络连接错误
|
if isinstance(e, NetworkConnectionError): # 网络连接错误
|
||||||
return self._check_retry(
|
return self._check_retry(
|
||||||
|
|||||||
Reference in New Issue
Block a user