创建HfAgent时触发AttributeError:transformers.tools无DocumentQuestionAnsweringTool属性
解决HfAgent运行时的AttributeError: DocumentQuestionAnsweringTool不存在问题
错误原因:
- 你的
transformers版本过旧,DocumentQuestionAnsweringTool是较新版本才新增的工具类 - 导入路径变更,该工具已从
transformers.tools根模块移至子模块
- 你的
解决步骤:
- 升级transformers到最新版本
执行以下命令更新依赖:pip install --upgrade transformers - 确认正确的导入方式
升级后,若仍需手动导入,使用子模块路径:from transformers.tools.document_question_answering import DocumentQuestionAnsweringTool - 直接通过HfAgent调用(推荐)
无需手动加载工具,直接让Agent自动处理:agent.run("回答文档中的问题", document="你的文档内容", question="具体问题")
- 升级transformers到最新版本
内容的提问来源于stack exchange,提问作者Kyle H
相关产品推荐
相关产品推荐

