Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] [Module Name] Bug title await queue.put("[DONE]") AttributeError: 'NoneType' object has no attribute 'put' #2332

Open
4 of 15 tasks
uniquecdmx opened this issue Feb 7, 2025 · 0 comments
Labels
bug Something isn't working Waiting for reply

Comments

@uniquecdmx
Copy link

Search before asking

  • I had searched in the issues and found no similar issues.

Operating system information

Linux

Python version information

3.10

DB-GPT version

latest release

Related scenes

  • Chat Data
  • Chat Excel
  • Chat DB
  • Chat Knowledge
  • Model Management
  • Dashboard
  • Plugins

Installation Information

Device information

gpu
2 counts
80G*2

Models information

LLM:glm-4-9b-chat
embedding:text2vec

What happened

调用单一Agent应用的api时出现报错,但前端对话方式无问题,之前同样的调用方式在0.6.1版本可以实现成功调用,但后来升级0.6.3之后出现这个问题,后续降级版本也未解决
代码:
from dbgpt.client import Client

DBGPT_API_KEY = "dbgpt"
APP_ID="xxx"

client = Client(api_key=DBGPT_API_KEY)

async for data in client.chat_stream(
messages="等太久了",
model="glm-4-9b-chat",
chat_mode="chat_app",
chat_param=APP_ID,

):
print(data)
# if "大类" in data:

报错:
2025-02-07 17:39:41 gpu-node dbgpt.serve.agent.agents.controller[1248478] INFO agent_chat_v2 conv_id:5fb1d034-95fa-4371-988e-e011f11f44aa,gpts_name:d66a1cf8-a581-11ef-8487-9cc2c455fa2d,user_query:等太久了
2025-02-07 17:39:41 gpu-node dbgpt.serve.agent.agents.controller[1248478] INFO gpts_conversations count:5fb1d034-95fa-4371-988e-e011f11f44aa,0
INFO: 127.0.0.1:59450 - "POST /api/v2/chat/completions HTTP/1.1" 200 OK
2025-02-07 17:39:42 gpu-node dbgpt.serve.rag.connector[1248478] INFO VectorStore:<class 'dbgpt.storage.vector_store.chroma_store.ChromaStore'>


User (to Aristotle)-[]:

"等太久了"


2025-02-07 17:39:42 gpu-node dbgpt.agent.core.base_agent[1248478] INFO generate agent reply!sender=profile=ProfileConfig(profile_id=0, name='User', role='Human', goal=<dbgpt.util.configure.base.ConfigInfo object at 0x7fdbc30f5540>, retry_goal=<dbgpt.util.configure.base.ConfigInfo object at 0x7fdbc30f5510>, constraints=<dbgpt.util.configure.base.ConfigInfo object at 0x7fdbc30f5570>, retry_constraints=<dbgpt.util.configure.base.ConfigInfo object at 0x7fdbc30f5990>, desc=<dbgpt.util.configure.base.ConfigInfo object at 0x7fdbc30f5a20>, expand_prompt=<dbgpt.util.configure.base.ConfigInfo object at 0x7fdbc30f5ab0>, examples=<dbgpt.util.configure.base.ConfigInfo object at 0x7fdbc30f5b10>, system_prompt_template=<dbgpt.util.configure.base.ConfigInfo object at 0x7fdbc30f5b70>, user_prompt_template=<dbgpt.util.configure.base.ConfigInfo object at 0x7fdbc30f5bd0>, write_memory_template=<dbgpt.util.configure.base.ConfigInfo object at 0x7fdbc30f5c30>, factory=None) memory=<dbgpt.agent.core.memory.agent_memory.AgentMemory object at 0x7fdae850b1f0> fixed_subgoal=None language='zh' is_human=True is_team=False template_env=<jinja2.sandbox.SandboxedEnvironment object at 0x7fdae8508100> agent_context=AgentContext(conv_id='5fb1d034-95fa-4371-988e-e011f11f44aa_1', gpts_app_code='d66a1cf8-a581-11ef-8487-9cc2c455fa2d', gpts_app_name='差评分类', language='zh', max_chat_round=100, max_retry_round=10, max_new_tokens=1024, temperature=0.5, allow_format_str_template=False, verbose=False, app_link_start=False, enable_vis_message=True) actions=[] resource=None llm_config=None bind_prompt=None max_retry_count=3 llm_client=None stream_out=True show_reference=False executor=<concurrent.futures.thread.ThreadPoolExecutor object at 0x7fdae850bc10> ask_user=False, rely_messages_len=None
2025-02-07 17:39:42 gpu-node dbgpt.agent.core.base_agent[1248478] INFO Depends on the number of historical messages:0!
Client disconnected
2025-02-07 17:39:42 gpu-node dbgpt.serve.agent.agents.controller[1248478] INFO Chat to App d66a1cf8-a581-11ef-8487-9cc2c455fa2d:5fb1d034-95fa-4371-988e-e011f11f44aa_1 Cancel!
2025-02-07 17:39:42 gpu-node dbgpt.serve.agent.agents.controller[1248478] INFO save agent chat info!5fb1d034-95fa-4371-988e-e011f11f44aa
2025-02-07 17:39:42 gpu-node asyncio[1248478] ERROR Task exception was never retrieved
future: <Task finished name='Task-7841' coro=<MultiAgents.agent_team_chat_new() done, defined at /data/soft/DB-GPT/dbgpt/serve/agent/agents/controller.py:409> exception=AttributeError("'NoneType' object has no attribute 'put'")>
Traceback (most recent call last):
File "/data/soft/DB-GPT/dbgpt/serve/agent/agents/controller.py", line 526, in agent_team_chat_new
await user_proxy.initiate_chat(
File "/data/soft/DB-GPT/dbgpt/agent/core/base_agent.py", line 651, in initiate_chat
await self.send(
File "/data/soft/DB-GPT/dbgpt/agent/core/base_agent.py", line 226, in send
await recipient.receive(
File "/data/soft/DB-GPT/dbgpt/agent/core/base_agent.py", line 269, in receive
reply = await self.generate_reply(
File "/data/soft/DB-GPT/dbgpt/agent/core/base_agent.py", line 363, in generate_reply
thinking_messages, resource_info = await self._load_thinking_messages(
File "/data/soft/DB-GPT/dbgpt/agent/core/base_agent.py", line 991, in _load_thinking_messages
resource_prompt_str, resource_references = await self.load_resource(
File "/data/soft/DB-GPT/dbgpt/agent/expand/summary_assistant_agent.py", line 108, in load_resource
resource_prompt, resource_reference = await self.resource.get_prompt(
File "/data/soft/DB-GPT/dbgpt/util/cache_utils.py", line 77, in wrapper
val = await func(*args, **kwargs)
File "/data/soft/DB-GPT/dbgpt/agent/resource/knowledge.py", line 69, in get_prompt
chunks = await self.retrieve(question)
File "/data/soft/DB-GPT/dbgpt/agent/resource/knowledge.py", line 152, in retrieve
return await self.retriever.aretrieve_with_scores(query, score, filters)
File "/data/soft/DB-GPT/dbgpt/rag/retriever/base.py", line 100, in aretrieve_with_scores
return await self._aretrieve_with_score(query, score_threshold, filters)
File "/data/soft/DB-GPT/dbgpt/serve/rag/retriever/knowledge_space.py", line 158, in _aretrieve_with_score
return await self._retriever_chain.aretrieve_with_scores(
File "/data/soft/DB-GPT/dbgpt/rag/retriever/base.py", line 100, in aretrieve_with_scores
return await self._aretrieve_with_score(query, score_threshold, filters)
File "/data/soft/DB-GPT/dbgpt/serve/rag/retriever/retriever_chain.py", line 90, in _aretrieve_with_score
candidates_with_scores = await retriever.aretrieve_with_scores(
File "/data/soft/DB-GPT/dbgpt/rag/retriever/base.py", line 100, in aretrieve_with_scores
return await self._aretrieve_with_score(query, score_threshold, filters)
File "/data/soft/DB-GPT/dbgpt/serve/rag/retriever/qa_retriever.py", line 181, in _aretrieve_with_score
candidates_with_score = await blocking_func_to_async(
File "/data/soft/DB-GPT/dbgpt/util/executor_utils.py", line 67, in blocking_func_to_async
return await loop.run_in_executor(executor, run_with_context)
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/data/soft/DB-GPT/dbgpt/serve/agent/agents/controller.py", line 546, in agent_team_chat_new
await self.memory.complete(conv_uid)
File "/data/soft/DB-GPT/dbgpt/agent/core/memory/gpts/gpts_memory.py", line 117, in complete
await queue.put("[DONE]")
AttributeError: 'NoneType' object has no attribute 'put'

What you expected to happen

问ai返回下面信息,不确定是否是Pydantic 版本问题导致的,当前pip版本
pydantic 2.10.0
pydantic_core 2.27.0
pydantic-settings 2.7.0

从错误信息来看,问题主要出现在以下几个方面:
ChatCompletionStreamResponse缺少字段:根据错误信息,Pydantic 模型验证失败,缺少字段 usage。这意味着返回的数据没有完全符合模型的要求,usage 字段是必填项。
NoneType对象没有put方法:这是由于尝试在 None 对象上调用 put 方法。这个错误通常意味着在某些情况下,队列对象没有正确初始化,或者在调用时对象不存在。
根据这些信息,我建议你检查以下几点:

  1. 确保 SSE 数据结构正确
    错误指示SSE数据中的字段不完整,可能是返回的 API 数据结构与预期的不匹配。你需要确认 ChatCompletionStreamResponse 类的定义,确保其正确匹配 API 返回的数据格式。如果没有 usage 字段,可能需要检查 API 是否有变化,或者手动添加缺失的字段。
  2. 处理NoneType对象
    出现 NoneType 错误可能与内存管理或消息处理部分的逻辑有关。检查队列或代理的初始化是否正确,确保在执行操作之前对象已被正确创建和传递。
  3. 确保client.chat_stream调用的参数正确
    你传入 client.chat_stream 的参数可能导致了响应格式问题。确保messages, model, chat_mode, chat_param 等参数格式正确,且与你的 API 服务的要求相符。
    调试步骤:
    检查 API 数据返回格式:你可以打印或调试 sse_data,看看返回数据中是否有遗漏字段。
    修复 usage 字段缺失:根据 Pydantic 错误,补充 usage 字段的处理或检查返回数据的源头。
    检查对象初始化:确保所有使用的对象,如队列、代理等,在使用之前已经正确初始化。
    如果问题依然存在,建议你查看相关文档或联系 API 提供方,以确认 API 是否发生了更改,或者是否有新的参数要求。
    这个错误信息表明在执行 client.chat_stream 时,发生了两个问题:
    NoneType object has no attribute 'put':
    这个错误意味着代码在尝试调用 queue.put("[DONE]") 时,queue 是 None 类型,导致无法执行 put 方法。这个问题通常是因为初始化的 queue 对象没有正确赋值,或者在代码中没有创建 queue。
    asyncio.exceptions.CancelledError:
    这是异步操作被取消时抛出的异常。通常在并发操作中,某些任务被取消可能会引发此异常。
    可能的解决方案:
  4. 检查 queue 初始化:
    在错误日志中,queue.put("[DONE]") 被调用时,queue 是 None,这通常是因为 queue 没有被正确初始化。你需要检查以下几点:
    确保在使用 queue 前已经创建并初始化了 queue 对象。
    如果 queue 是在某个地方动态创建的,确保它在出错的地方是有效的,并且没有被提前销毁或置为 None。
    检查如下代码:

确保初始化队列

queue = asyncio.Queue()
2. 检查异步操作的取消:
asyncio.exceptions.CancelledError 通常表示某个异步任务被取消。你需要确保在执行异步任务时,没有其他地方取消了它。
如果你手动取消任务,确保有合适的异常处理。
确保异步任务的 await 操作没有被其他逻辑中断。
示例:
try:
await some_async_function()
except asyncio.CancelledError:
# 在任务被取消时执行的代码
print("Task was cancelled.")
3. 检查连接和 API 调用:
由于错误日志涉及到 client.chat_stream 调用,可能需要检查 API 调用部分,确保所有参数(例如 messages、model 等)都是正确的,且服务端能够正常响应。如果服务端返回了连接中断或取消任务的消息,你也可能遇到这种异常。
4. 日志详细分析:
日志中显示了很多与 memory 和 agent 相关的操作,可能是因为某些资源在任务执行过程中被取消,导致某些操作未能完成。可以检查涉及 memory 和 agent 管理的部分,看看是否存在资源管理上的问题。
总结:
确保初始化了 queue。
处理异步任务被取消的情况。
检查 API 请求的正确性和稳定性。
如果问题仍然存在,可以提供更多代码细节,帮助进一步分析问题。

How to reproduce

出现这个问题之后降级过0.5.9 0.5.10 .0.6.2等版本 都有不同的报错 最后0.6.0版本以上基本属于这种报错

Additional context

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!
@uniquecdmx uniquecdmx added bug Something isn't working Waiting for reply labels Feb 7, 2025
@uniquecdmx uniquecdmx changed the title [Bug] [Module Name] Bug title [Bug] [Module Name] Bug title await queue.put("[DONE]") AttributeError: 'NoneType' object has no attribute 'put' Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Waiting for reply
Projects
None yet
Development

No branches or pull requests

1 participant