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

对数据库 提问有问题,找到数据但不回答或数据库没有的什么都不回答 #3288

Closed
cstkn opened this issue Mar 12, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@cstkn
Copy link

cstkn commented Mar 12, 2024

2024-03-12 18:34:25,072 - utils.py[line:38] - ERROR: object of type 'NoneType' has no len()
Traceback (most recent call last):
File "D:\wujiaping\chat\Langchain-Chatchat\server\utils.py", line 36, in wrap_done
await fn
File "D:\wujiaping\chat\Langchain-Chatchat.venv\Lib\site-packages\langchain\chains\base.py", line 385, in acall
raise e
File "D:\wujiaping\chat\Langchain-Chatchat.venv\Lib\site-packages\langchain\chains\base.py", line 379, in acall
await self._acall(inputs, run_manager=run_manager)
File "D:\wujiaping\chat\Langchain-Chatchat.venv\Lib\site-packages\langchain\chains\llm.py", line 275, in _acall
response = await self.agenerate([inputs], run_manager=run_manager)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\wujiaping\chat\Langchain-Chatchat.venv\Lib\site-packages\langchain\chains\llm.py", line 142, in agenerate
return await self.llm.agenerate_prompt(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\wujiaping\chat\Langchain-Chatchat.venv\Lib\site-packages\langchain_core\language_models\chat_models.py", line 554, in agenerate_prompt
return await self.agenerate(
^^^^^^^^^^^^^^^^^^^^^
File "D:\wujiaping\chat\Langchain-Chatchat.venv\Lib\site-packages\langchain_core\language_models\chat_models.py", line 514, in agenerate
raise exceptions[0]
File "D:\wujiaping\chat\Langchain-Chatchat.venv\Lib\site-packages\langchain_core\language_models\chat_models.py", line 617, in _agenerate_with_cache
return await self._agenerate(
^^^^^^^^^^^^^^^^^^^^^^
File "D:\wujiaping\chat\Langchain-Chatchat.venv\Lib\site-packages\langchain_community\chat_models\openai.py", line 522, in _agenerate
return await agenerate_from_stream(stream_iter)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\wujiaping\chat\Langchain-Chatchat.venv\Lib\site-packages\langchain_core\language_models\chat_models.py", line 87, in agenerate_from_stream
async for chunk in stream:
File "D:\wujiaping\chat\Langchain-Chatchat.venv\Lib\site-packages\langchain_community\chat_models\openai.py", line 493, in _astream
if len(chunk["choices"]) == 0:
^^^^^^^^^^^^^^^^^^^^^

@cstkn cstkn added the bug Something isn't working label Mar 12, 2024
Copy link

dosubot bot commented Mar 12, 2024

嗨,@cstkn!很高兴再次见到你。希望你一切都好!

您的错误可能是由于在尝试测量一个为None的对象的长度时发生的。这种错误通常出现在操作期望一个集合(如列表、字符串或元组)但接收到一个None值的情况下。

在提供的上下文中,可能出现这个错误的地方有几处,但一个可能的情况是与处理文档及其内容的file_chat函数有关。具体来说,错误可能发生在这些行:

context = "\n".join([doc.page_content for doc in docs])

如果docs是一个空列表(意味着没有找到相似度得分高于阈值的文档),这一行本身不会直接导致'NoneType' object has no len()错误。然而,后续对contextdocs的使用或操作可能会,特别是如果对context期望是一个非空字符串或对docs期望包含元素。

另一个可能的错误源头可能是在处理history或其他期望列表但可能是None的代码部分。然而,基于提供的上下文,处理文档搜索结果及其内容似乎最有可能。

为解决这个问题,确保所有期望一个集合有长度的操作检查None,或确保变量初始化为空集合(例如,[]对于列表)而不是None。此外,在假设集合中存在元素的代码周围添加检查或try-except块可以防止这个错误。

例如,在连接docs之前:

if docs is not None and len(docs) > 0:
    context = "\n".join([doc.page_content for doc in docs])
else:
    context = ""

这确保了context总是一个字符串,即使docs是空的或None,从而防止对context的操作引发'NoneType' object has no len()错误。

在Langchain-Chatchat代码库的server/chat/knowledge_base_chat.py文件中,'NoneType' object has no len()错误可能是由以下行引起的:

if len(docs) == 0:

这行假设docs总是一个列表或支持len()的集合。然而,如果search_docsreranker_model.compress_documents在找不到文档或发生错误时返回None而不是一个空的列表或集合,那么尝试在None上使用len()将导致'NoneType' object has no len()错误。

参考源码:

希望这些信息能帮助您解决问题。如果您有任何其他问题或需要进一步的澄清,请随时提问。

Sources

About Dosu

This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

@zRzRzRzRzRzRzR zRzRzRzRzRzRzR self-assigned this Mar 14, 2024
@zRzRzRzRzRzRzR
Copy link
Collaborator

这个是大模型端有问题吧,你估计LLM对话也是不通的,检查大模型是否正常

@jinyilun718
Copy link

我LLM对话是通的,但是还是遇到了这个问题是为什么呢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants