generative_agents icon indicating copy to clipboard operation
generative_agents copied to clipboard

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

Open babytdream opened this issue 2 years ago • 10 comments

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.

babytdream avatar Sep 22 '23 02:09 babytdream

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

Liu-Yonghu avatar Sep 22 '23 08:09 Liu-Yonghu

me toooooooooo

QFFly233 avatar Oct 19 '23 03:10 QFFly233

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.

chai991014 avatar Nov 07 '23 19:11 chai991014

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

2642543078 avatar Nov 16 '23 07:11 2642543078

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?

wwwzwbz avatar Jan 24 '24 12:01 wwwzwbz

Liu-Yonghu

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

moulshri-7 avatar Jan 27 '24 01:01 moulshri-7

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 avatar May 24 '24 21:05 dafrontman

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]]

dafrontman avatar May 25 '24 18:05 dafrontman

我想通了这个。这只是一个字符串解析问题。第 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]]

这是一种解决方法

2642543078 avatar Jul 05 '24 02:07 2642543078

I have also met IndexError: list index out of range, but not at the same place.

File "/.../reverie/backend_server/persona/prompt_template/run_gpt_prompt.py", line 526, in run_gpt_prompt_task_decomp fin_output[-1][1] += (duration - ftime_sum) IndexError: list index out of range

Image

This temperately fixes the issue I met.

Neuro987 avatar Feb 06 '25 06:02 Neuro987