joonspk-research / generative_agents

Generative Agents: Interactive Simulacra of Human Behavior
Apache License 2.0
16.26k stars 2.09k forks source link

Whenever run xxx ends, appears IndexError: list index out of range #111

Open babytdream opened 1 year ago

babytdream commented 1 year ago

like #92 I use my own api_base. Wheneverrun xxxends, this error will appear. Has anyone encountered this problem?

-==- -==- -==- 
Traceback (most recent call last):
  File "/data/generative_agents/reverie/backend_server/reverie.py", line 471, in open_server
    rs.start_server(int_count)
  File "/data/generative_agents/reverie/backend_server/reverie.py", line 379, in start_server
    next_tile, pronunciatio, description = persona.move(
  File "/data/generative_agents/reverie/backend_server/persona/persona.py", line 222, in move
    plan = self.plan(maze, personas, new_day, retrieved)
  File "/data/generative_agents/reverie/backend_server/persona/persona.py", line 148, in plan
    return plan(self, maze, personas, new_day, retrieved)
  File "/data/generative_agents/reverie/backend_server/persona/cognitive_modules/plan.py", line 959, in plan
    _determine_action(persona, maze)
  File "/data/generative_agents/reverie/backend_server/persona/cognitive_modules/plan.py", line 573, in _determine_action
    generate_task_decomp(persona, act_desp, act_dura))
  File "/data/generative_agents/reverie/backend_server/persona/cognitive_modules/plan.py", line 164, in generate_task_decomp
    return run_gpt_prompt_task_decomp(persona, task, duration)[0]
  File "/data/generative_agents/reverie/backend_server/persona/prompt_template/run_gpt_prompt.py", line 439, in run_gpt_prompt_task_decomp
    output = safe_generate_response(prompt, gpt_param, 5, get_fail_safe(),
  File "/data/generative_agents/reverie/backend_server/persona/prompt_template/gpt_structure.py", line 262, in safe_generate_response
    return func_clean_up(curr_gpt_response, prompt=prompt)
  File "/data/generative_agents/reverie/backend_server/persona/prompt_template/run_gpt_prompt.py", line 378, in __func_clean_up
    duration = int(k[1].split(",")[0].strip())
IndexError: list index out of range
Error.
Liu-Yonghu commented 1 year ago

me too, but I did't find the solution. If you have any advancements, be free to contact me, Thanks.

QFFly233 commented 11 months ago

me toooooooooo

chai991014 commented 10 months ago

This problem is due to openai, you need to add payment detail and add at least $5 into the account then problem solved. The free $5 credit is not usable if you never reload credit.

2642543078 commented 10 months ago

不是 这个运行报错了 这个像是走提示模板时发生错误 然后报错体现列表超出范围 我需要看更多的报错信息

wwwzwbz commented 8 months ago

I had the same problem:

image

I'm not using OpenAI api, but instead GPT4All 'orca-mini-3b-gguf2-q4_0.gguf', mac M1... running "run 10" have been fine (I ran it 3 times), but "run 5" and "run 1" both had "index out of bound problems" Anyone had the same issue?

moulshri-7 commented 8 months ago

Liu-Yonghu

It's not working for me even after doing this. Could there be some other issue?

dafrontman commented 4 months ago

I figured this one out. It's just a string parsing issue. The duration variable in line 378 gets messed up because the code earlier in the function is expecting the gpt_response to contain the string "duration in minutes:" but when the error happens the prompt has a string that reads "duration:" only. So the code fails after that because "in minutes" is not there. I just wrote a quick fix to get it working. Checked that "duration in minutes:" was there and if not I parsed it with just "duration:"

  if "duration in minutes" in i: 
    k = [j.strip() for j in i.split("(duration in minutes:")]
  else:
    k = [j.strip() for j in i.split("(duration:")]
dafrontman commented 4 months ago

I figured this one out. It's just a string parsing issue. The duration variable in line 378 gets messed up because the code earlier in the function is expecting the gpt_response to contain the string "duration in minutes:" but when the error happens the prompt has a string that reads "duration:" only. So the code fails after that because "in minutes" is not there. I just wrote a quick fix to get it working. Checked that "duration in minutes:" was there and if not I parsed it with just "duration:"

  if "duration in minutes" in i: 
    k = [j.strip() for j in i.split("(duration in minutes:")]
  else:
    k = [j.strip() for j in i.split("(duration:")]

There was yet another case where the gpt_response had an entry that did not have a "duration" AT ALL. It just contained the task. So I modified the code a bit more. My fix is SUPER ugly. Hopefully someone will write a cleaner code block than me but here's what I did. Not tested yet:

  if "duration in minutes" in i: 
    k = [j.strip() for j in i.split("(duration in minutes:")]
  elif "duration" in i:
    k = [j.strip() for j in i.split("(duration:")]
  else:
    task = i
    duration = 0 #arbitrary value, don't know if 0 minutes will hurt anything
  if "duration" in i:
    task = k[0]
    if task[-1] == ".": 
      task = task[:-1]
    duration = int(k[1].split(",")[0].strip())
  cr += [[task, duration]]
2642543078 commented 2 months ago

我想通了这个。这只是一个字符串解析问题。第 378 行中的 duration 变量搞砸了,因为函数前面的代码期望gpt_response包含字符串 “duration in minutes:”,但是当错误发生时,提示符有一个字符串,仅显示 “duration:”。因此,代码在那之后会失败,因为“几分钟内”不存在。我刚刚写了一个快速修复程序来让它正常工作。检查了“以分钟为单位的持续时间:”是否存在,如果没有,我只使用“持续时间:”进行解析。

  if "duration in minutes" in i: 
    k = [j.strip() for j in i.split("(duration in minutes:")]
  else:
    k = [j.strip() for j in i.split("(duration:")]

还有另一种情况,gpt_response有一个条目根本没有“持续时间”。它只是包含了任务。所以我对代码进行了更多的修改。我的修复是超级丑陋的。希望有人会写出比我更干净的代码块,但这就是我所做的。尚未测试:

  if "duration in minutes" in i: 
    k = [j.strip() for j in i.split("(duration in minutes:")]
  elif "duration" in i:
    k = [j.strip() for j in i.split("(duration:")]
  else:
    task = i
    duration = 0 #arbitrary value, don't know if 0 minutes will hurt anything
  if "duration" in i:
    task = k[0]
    if task[-1] == ".": 
      task = task[:-1]
    duration = int(k[1].split(",")[0].strip())
  cr += [[task, duration]]

这是一种解决方法