You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

创建HfAgent时触发AttributeError:transformers.tools无DocumentQuestionAnsweringTool属性

解决HfAgent运行时的AttributeError: DocumentQuestionAnsweringTool不存在问题
  • 错误原因:

    • 你的transformers版本过旧,DocumentQuestionAnsweringTool是较新版本才新增的工具类
    • 导入路径变更,该工具已从transformers.tools根模块移至子模块
  • 解决步骤:

    1. 升级transformers到最新版本
      执行以下命令更新依赖:
      pip install --upgrade transformers
      
    2. 确认正确的导入方式
      升级后,若仍需手动导入,使用子模块路径:
      from transformers.tools.document_question_answering import DocumentQuestionAnsweringTool
      
    3. 直接通过HfAgent调用(推荐)
      无需手动加载工具,直接让Agent自动处理:
      agent.run("回答文档中的问题", document="你的文档内容", question="具体问题")
      

内容的提问来源于stack exchange,提问作者Kyle H

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 05:22:01