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]: 循环引用的问题会导致无法使用知识库功能 #1133

Closed
1 of 2 tasks
kasperlmc opened this issue May 22, 2024 · 1 comment
Closed
1 of 2 tasks

[Bug]: 循环引用的问题会导致无法使用知识库功能 #1133

kasperlmc opened this issue May 22, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@kasperlmc
Copy link

这个bug是否已存在现有issue了?

  • 我确认没有已有issue,且已阅读常见问题

错误表现

屏幕截图 2024-05-22 102431
屏幕截图 2024-05-22 102453

因为要使用知识库的功能,必须要调用base_model.py中的handle_file_upload方法,
而handle_file_upload方法会调用到index_func.py中的construct_index函数,
但是index_func.py又使用from modules.utils import *引用了utils中的全部内容,
同时在utils中的1432行出现了from .models.base_model import BaseLLMModel,使得utils又对base_model 进行了引用,进而导致了循环引用的问题,使得base_model.py的from ..index_func import *无法生效,进而导致handle_file_upload方法无法调用到index_func.py中的construct_index函数,导致知识库的功能出错。

复现操作

正常部署了最新版本代码,然后问答正常,但是知识库功能不正常。

错误日志

2024-05-15 13:48:29,424 [INFO] [base_model.py:492] 加载索引中……
Traceback (most recent call last):
  File "/usr/local/python38/lib/python3.8/site-packages/gradio/queueing.py", line 566, in process_events
    response = await route_utils.call_process_api(
  File "/usr/local/python38/lib/python3.8/site-packages/gradio/route_utils.py", line 261, in call_process_api
    output = await app.get_blocks().process_api(
  File "/usr/local/python38/lib/python3.8/site-packages/gradio/blocks.py", line 1786, in process_api
    result = await self.call_function(
  File "/usr/local/python38/lib/python3.8/site-packages/gradio/blocks.py", line 1350, in call_function
    prediction = await utils.async_iteration(iterator)
  File "/usr/local/python38/lib/python3.8/site-packages/gradio/utils.py", line 583, in async_iteration
    return await iterator.__anext__()
  File "/usr/local/python38/lib/python3.8/site-packages/gradio/utils.py", line 576, in __anext__
    return await anyio.to_thread.run_sync(
  File "/usr/local/python38/lib/python3.8/site-packages/anyio/to_thread.py", line 33, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "/usr/local/python38/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 877, in run_sync_in_worker_thread
    return await future
  File "/usr/local/python38/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 807, in run
    result = context.run(func, *args)
  File "/usr/local/python38/lib/python3.8/site-packages/gradio/utils.py", line 559, in run_sync_iterator_async
    return next(iterator)
  File "/usr/local/python38/lib/python3.8/site-packages/gradio/utils.py", line 742, in gen_wrapper
    response = next(iterator)
  File "/home/luxun/ChuanhuChatGPT/modules/utils.py", line 41, in predict
    for i in iter:
  File "/home/luxun/ChuanhuChatGPT/modules/models/base_model.py", line 632, in predict
    ) = self.prepare_inputs(
  File "/home/luxun/ChuanhuChatGPT/modules/models/base_model.py", line 493, in prepare_inputs
    index = construct_index(
NameError: name 'construct_index' is not defined

运行环境

  • OS: centos
  • Browser: Chrome
  • Gradio version: 4.26.0
  • Python version: 3.8.6

帮助解决

  • 我愿意协助解决!

补充说明

No response

@kasperlmc kasperlmc added the bug Something isn't working label May 22, 2024
@ThorinKong
Copy link
Contributor

貌似utils.py引用BaseLLMModel只是为了类型注解
在utils.py中把 from .models.base_model import BaseLLMModel移动到if TYPE_CHECKING:里就行了

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

2 participants