ValueError: Only one output is supported.

用户在运行 LlamaIndex 的 QueryPipeline 示例笔记本 query_pipeline_memory.ipynb 时,执行循环传入多条用户消息并更新会话记忆。代码中 pipeline.run() 返回了列表(多个响应),但后续尝试通过 response.message 访问单个属

ValueError: Only one output is supported.

ValueError: Only one output is supported.

快速结论:这个报错发生在 LlamaIndex 的 QueryPipeline.run() 返回多个输出(列表)但后续代码试图将其当作单一对象处理时。优先排查 pipeline.run() 是否返回了列表,并确认是否在循环中正确迭代。

问题场景

用户在运行 LlamaIndex 的 QueryPipeline 示例笔记本 query_pipeline_memory.ipynb 时,执行循环传入多条用户消息并更新会话记忆。代码中 pipeline.run() 返回了列表(多个响应),但后续尝试通过 response.message 访问单个属性,导致 AttributeError: 'list' object has no attribute 'message'。尝试迭代列表后,又出现 ValueError: Only one output is supported.

报错原文

{
	"name": "AttributeError",
	"message": "'list' object has no attribute 'message'",
	"stack": "...
---> 42 pipeline_memory.put(response.message)
AttributeError: 'list' object has no attribute 'message'"
}

ValueError                                Traceback (most recent call last)
Cell In[36], [line 18](vscode-notebook-cell:?execution_count=36&line=18)
---> [18](vscode-notebook-cell:?execution_count=36&line=18) response = pipeline.run(
     [19](vscode-notebook-cell:?execution_count=36&line=19)     query_str=msg,
     [20](vscode-notebook-cell:?execution_count=36&line=20)     chat_history=chat_history,
ValueError: Only one output is supported.

原因分析

pipeline.run() 的输出类型取决于管道的配置(例如 query_configs)。如果管道定义了多个输出节点,返回值可能是一个字典或列表,而不是单个带 .message 属性的响应对象。示例笔记本中的输出可能因版本或配置差异导致返回列表,在迭代该列表时调用 pipeline.run() 又会触发 "Only one output is supported",表明某些 run() 调用(如 run_with_intermediates 或未正确处理输出)被错误使用。

环境排查

  • LlamaIndex 版本:用户使用 llama-index ^0.10.38,但示例可能针对更新版本设计,需确认笔记本兼容版本。
  • Python 版本:用户使用 Python >=3.12, <3.13
  • 依赖:检查 llama-index 及其集成包是否与示例要求一致。
  • 管道配置:确认 pipeline 对象的 query_configs 是否正确设置,尤其是输出节点数量。

解决步骤

  1. 首先确认 pipeline.run() 返回的类型:在调用处打印 type(response)print(response),判断是字典、列表还是其他类型。若为字典,应使用 response["response"] 访问文本内容。若为列表,需迭代内部元素。
  2. 如果返回列表,不要直接对列表调用 pipeline.run(),而是先拆解列表:for single_response in response_list: print(single_response["response"])
  3. 确保 query_configs 中没有将多个输出节点配置为单一输出。可尝试重置管道配置,仅保留单个输出节点。
  4. 如果问题持续,参考 LlamaIndex 官方示例笔记本的最新版本,检查 pipeline.run() 的正确用法,并对比 query_pipeline_memory.ipynb 中是否有 run_with_intermediates 或其他变体。
  5. 可优先尝试:response = pipeline.run(...) 改为 response = pipeline.run_with_intermediates(...) 并解包返回的两个值,确保处理中间结果。

验证方法

重新运行循环,确保不再抛出 ValueError: Only one output is supported.AttributeError。同时检查 pipeline_memory.put() 传入的对象类型正确(应为单个 ChatMessage)。多次迭代后,会话历史能正确累积。

参考来源

run-llama/llama_index #14952

GamsGo AI

AI 工具推荐

想把多个 AI 模型放在一个入口?

GamsGo AI 集成 ChatGPT、DeepSeek、Gemini、Claude、Midjourney、Veo 等常用模型,适合写作、绘图、视频和日常 AI 工作流。

了解 GamsGo AI

推广链接:通过此链接购买,我可能获得佣金,不影响你的价格。

celebrityanime
celebrityanime
文章: 11031

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注