Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

BadRequestError: max_tokens is too large (14817 > 4096)

未关闭
#492 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
python
领域
api, backend

调研方向

从 camel/model_backend.py 开始,traceback 显示 OpenAI chat completion 请求是在这里发出的,并跟踪 max_tokens 如何变为 14817。复现文档中的 run.py 命令,然后验证请求仍处于所选模型的限制范围内,并且 Snake Game 任务不再因 BadRequestError 失败。

由索引模型根据 Issue 内容生成。

描述

When I tried to run ChatDev with the following command:
python3 run.py --task "[make a simple Snake Game game]" --name "[Snake_Game]"

I get this error:


Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/tenacity/__init__.py", line 382, in __call__
    result = fn(*args, **kwargs)
  File "/Users/yixuan/Documents/GitHub/ChatDev/camel/utils.py", line 160, in wrapper
    return func(self, *args, **kwargs)
  File "/Users/yixuan/Documents/GitHub/ChatDev/camel/agents/chat_agent.py", line 239, in step
    response = self.model_backend.run(messages=openai_messages)
  File "/Users/yixuan/Documents/GitHub/ChatDev/camel/model_backend.py", line 101, in run
    response = client.chat.completions.create(*args, **kwargs, model=self.model_type.value,
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/openai/_utils/_utils.py", line 286, in wrapper
    return func(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/openai/resources/chat/completions/completions.py", line 1147, in create
    return self._post(
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/openai/_base_client.py", line 1259, in post
    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/openai/_base_client.py", line 1047, in request
    raise self._make_status_error_from_response(err.response) from None
openai.BadRequestError: Error code: 400 - {'error': {'message': 'max_tokens is too large: 14817. This model supports at most 4096 completion tokens, whereas you provided 14817.', 'type': 'invalid_request_error', 'param': 'max_tokens', 'code': 'invalid_value'}}

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/yixuan/Documents/GitHub/ChatDev/run.py", line 136, in <module>
    chat_chain.execute_chain()
  File "/Users/yixuan/Documents/GitHub/ChatDev/chatdev/chat_chain.py", line 168, in execute_chain
    self.execute_step(phase_item)
  File "/Users/yixuan/Documents/GitHub/ChatDev/chatdev/chat_chain.py", line 138, in execute_step
    self.chat_env = self.phases[phase].execute(self.chat_env,
  File "/Users/yixuan/Documents/GitHub/ChatDev/chatdev/phase.py", line 295, in execute
    self.chatting(chat_env=chat_env,
  File "/Users/yixuan/Documents/GitHub/ChatDev/chatdev/utils.py", line 79, in wrapper
    return func(*args, **kwargs)
  File "/Users/yixuan/Documents/GitHub/ChatDev/chatdev/phase.py", line 133, in chatting
    assistant_response, user_response = role_play_session.step(input_user_msg, chat_turn_limit == 1)
  File "/Users/yixuan/Documents/GitHub/ChatDev/camel/agents/role_playing.py", line 247, in step
    assistant_response = self.assistant_agent.step(user_msg_rst)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/tenacity/__init__.py", line 289, in wrapped_f
    return self(f, *args, **kw)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/tenacity/__init__.py", line 379, in __call__
    do = self.iter(retry_state=retry_state)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/tenacity/__init__.py", line 326, in iter
    raise retry_exc from fut.exception()
tenacity.RetryError: RetryError[<Future at 0x7f9582503820 state=finished raised BadRequestError>]

Expected Behavior

The program should correctly calculate max_tokens based on the model limits (e.g., gpt-4o supports 4096 tokens).

Actual Behavior

It sets max_tokens=14817, which exceeds the model’s maximum (4096), causing the OpenAI API to return BadRequestError.

主要语言
Python
星标
34.5k
派生
4.3k
PR 合并指标
30 天内没有已合并 PR

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

OpenBMB/ChatDev 的其他 Issue

查看 OpenBMB/ChatDev 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。