geekan / MetaGPT

🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
https://deepwisdom.ai/
MIT License
44.03k stars 5.24k forks source link

AttributeError: 'list' object has no attribute 'keys' #1229

Open Yue-Rain opened 5 months ago

Yue-Rain commented 5 months ago

Bug description Traceback (most recent call last): File "/root/workspace/jjyue/MetaGPT-main/metagpt/utils/common.py", line 640, in wrapper return await func(self, *args, **kwargs) File "/root/workspace/jjyue/MetaGPT-main/metagpt/roles/role.py", line 555, in run rsp = await self.react() File "/root/workspace/jjyue/MetaGPT-main/metagpt/roles/researcher.py", line 130, in react msg = await super().react() File "/root/workspace/jjyue/MetaGPT-main/metagpt/roles/role.py", line 524, in react rsp = await self._act_by_order() File "/root/workspace/jjyue/MetaGPT-main/metagpt/roles/role.py", line 478, in _act_by_order rsp = await self._act() File "/root/workspace/jjyue/MetaGPT-main/metagpt/roles/researcher.py", line 74, in _act links = await todo.run(topic, 4, 4) File "/root/workspace/jjyue/MetaGPT-main/metagpt/actions/research.py", line 123, in run results = await asyncio.gather( File "/root/workspace/jjyue/MetaGPT-main/metagpt/tools/search_engine.py", line 164, in run raise e File "/root/workspace/jjyue/MetaGPT-main/metagpt/tools/search_engine.py", line 159, in run return await self.run_func(query, max_results=max_results, as_string=as_string) File "/root/workspace/jjyue/MetaGPT-main/metagpt/tools/search_engine_serpapi.py", line 55, in run return self._process_response(result, as_string=as_string) File "/root/workspace/jjyue/MetaGPT-main/metagpt/tools/search_engine_serpapi.py", line 103, in _process_response if "answer_box" in res.keys() and "answer" in res["answer_box"].keys(): AttributeError: 'list' object has no attribute 'keys'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/root/workspace/jjyue/MetaGPT-main/entry.py", line 23, in asyncio.run(main()) File "/root/miniconda3/envs/llm_nlp/lib/python3.10/asyncio/runners.py", line 44, in run return loop.run_until_complete(main) File "/root/miniconda3/envs/llm_nlp/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete return future.result() File "/root/workspace/jjyue/MetaGPT-main/entry.py", line 18, in main await role.run(topic) File "/root/workspace/jjyue/MetaGPT-main/metagpt/utils/common.py", line 662, in wrapper raise Exception(format_trackback_info(limit=None)) Exception: Traceback (most recent call last): File "/root/workspace/jjyue/MetaGPT-main/metagpt/utils/common.py", line 640, in wrapper return await func(self, *args, **kwargs) File "/root/workspace/jjyue/MetaGPT-main/metagpt/roles/role.py", line 555, in run rsp = await self.react() File "/root/workspace/jjyue/MetaGPT-main/metagpt/roles/researcher.py", line 130, in react msg = await super().react() File "/root/workspace/jjyue/MetaGPT-main/metagpt/roles/role.py", line 524, in react rsp = await self._act_by_order() File "/root/workspace/jjyue/MetaGPT-main/metagpt/roles/role.py", line 478, in _act_by_order rsp = await self._act() File "/root/workspace/jjyue/MetaGPT-main/metagpt/roles/researcher.py", line 74, in _act links = await todo.run(topic, 4, 4) File "/root/workspace/jjyue/MetaGPT-main/metagpt/actions/research.py", line 123, in run results = await asyncio.gather( File "/root/workspace/jjyue/MetaGPT-main/metagpt/tools/search_engine.py", line 164, in run raise e File "/root/workspace/jjyue/MetaGPT-main/metagpt/tools/search_engine.py", line 159, in run return await self.run_func(query, max_results=max_results, as_string=as_string) File "/root/workspace/jjyue/MetaGPT-main/metagpt/tools/search_engine_serpapi.py", line 55, in run return self._process_response(result, as_string=as_string) File "/root/workspace/jjyue/MetaGPT-main/metagpt/tools/search_engine_serpapi.py", line 103, in _process_response if "answer_box" in res.keys() and "answer" in res["answer_box"].keys(): AttributeError: 'list' object has no attribute 'keys'

Bug solved method

Environment information

Screenshots or logs bug2 bug1

seehi commented 5 months ago

It seems res["answer_box"] is a list not a dict. Is it reproduced? could you post the value of res which in this func

Yue-Rain commented 5 months ago

yes it is. res["answer_box"] is a list, but the content is a dict,see below.

[
   {
      "position":1,
      "title":"桥梁施工方法",
      "link":"http://nourl.ubs.baidu.com/278",
      "type":"ai_content",
      "snippet":"桥梁施工方法多样,主要包括以下几种:\n钻孔灌注桩施工。包括测量放样、设置护简、钻孔、清孔、放钢筋笼和浇筑混凝土。\n扩大基础施工。包括基坑开挖、基坑排水、基底处理以及砌筑或浇筑基础结构物。\n承台墩身施工。涉及安装模板、钢筋绑扎和分层浇筑混凝土。\n梁板预制施工。包括地基处理、浇筑台座、安装板梁、绑扎钢筋、浇筑混凝土和养护。\n先简支后连续施工。包括设置临时支座、安装梁板、安装底模、浇筑现浇段、张拉预应力连续束和压浆。\n桥面工程施工。包括安装泄水管、浇筑护栏混凝土、铺设钢筋网和浇筑桥面混凝土。\n悬臂施工法A。适用于较大的桥梁,通过逐渐延伸的臂架进行施工。\n顶推施工法A。在桥梁的一端施力,使其沿轨道逐渐移动直至完成。\n移动模架逐孔施工法A。使用移动模架逐个完成每孔梁的施工。\n支架现浇法A。通过搭建脚手架或其他支撑结构,在现场直接浇筑混凝土。\n预制安装法A。在工厂预制梁体,然后运输至现场进行安装。\n每种方法都有其适用场景和优势,选择哪种方法取决于具体的桥梁设计、地理位置、环境条件等因素。",
      "snippet_links":[],
      "references":[]
   }
]
Yue-Rain commented 5 months ago

the value of res: image

seehi commented 5 months ago

The type of the field may have changed, or there is a special situation. FYI: @shenchucheng

shenchucheng commented 4 months ago

@Yue-Rain Could you please provide the params you use? The default values are:

{
    "engine": "google",
    "google_domain": "google.com",
    "gl": "us",
    "hl": "en"
}