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]: "if filename.endswith(".md"):" in utils.py, AttributeError: 'NoneType' object has no attribute 'endswith' #883

Closed
2 tasks done
JohnZ03 opened this issue Sep 12, 2023 · 9 comments
Labels
bug Something isn't working

Comments

@JohnZ03
Copy link
Contributor

JohnZ03 commented Sep 12, 2023

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

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

错误表现

Launched as a localhost. After each prompt, AttributeError is raised.

Traceback

File "C:\Users\*****\Documents\git\ChuanhuChatGPT\modules\models\base_model.py", line 512, in predict
    self.auto_save(chatbot)
  File "C:\Users\*****\Documents\git\ChuanhuChatGPT\modules\models\base_model.py", line 691, in auto_save
    save_file(self.history_file_path, self.system_prompt,
  File "C:\Users\*****\Documents\git\ChuanhuChatGPT\modules\utils.py", line 338, in save_file
    if filename.endswith(".md"):
       ^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'endswith'

The function auto_save under base_model.py is first being called, which triggers save_file in utils.py.
However in this case the filename object passed to save_file is set to None.

Suspected causing issue

filename was passed from self.history_file_path under the BaseLLMModel class.
Where self.history_file_path is initialized as self.history_file_path = get_first_history_name(user).
Looking at the get_first_history_name function,

def get_first_history_name(user_name=""):
    history_names = get_history_names(user_name)
    return history_names[0] if history_names else None

the returned value is None if history_names is not set.
This suggests that the None object used by the save_file function is caused by a false initialization of self.history_file_path.

A quick proof

After changing the line

self.history_file_path = get_first_history_name(user)

to

self.history_file_path = "test.md"

The error is gone. However this might damage the app logic so cannot be taken as a fix.

复现操作

  1. Configured following the steps in the documentation.
  2. First time launch.
  3. Error triggers for every user prompt.

错误日志

File "C:\Users\*****\Documents\git\ChuanhuChatGPT\modules\models\base_model.py", line 512, in predict
    self.auto_save(chatbot)
  File "C:\Users\*****\Documents\git\ChuanhuChatGPT\modules\models\base_model.py", line 691, in auto_save
    save_file(self.history_file_path, self.system_prompt,
  File "C:\Users\*****\Documents\git\ChuanhuChatGPT\modules\utils.py", line 338, in save_file
    if filename.endswith(".md"):
       ^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'endswith'

运行环境

  • OS: Windows 11 Pro English
  • Browser: Chrome
  • Gradio version: 3.43.2
  • Python version: 3.11.4

帮助解决

  • 我愿意协助解决!

补充说明

No response

@JohnZ03 JohnZ03 added the bug Something isn't working label Sep 12, 2023
@GaiZhenbiao
Copy link
Owner

It works alright on my machine... Let me try setting my PC's OS language to English🤧

@XiaolongYang-HZAU
Copy link

遇到了相同的问题

@GaiZhenbiao
Copy link
Owner

I pushed a fix, hopefully that resolves your issue. Let me know if there's still bugs sitting around.

MZhao-ouo added a commit that referenced this issue Sep 12, 2023
@GaiZhenbiao
Copy link
Owner

I'm confident to say that this issue is resolved now. Please pull the latest version. Let me know if there's still bugs sitting around.

GaiZhenbiao added a commit that referenced this issue Sep 16, 2023
@GaiZhenbiao
Copy link
Owner

Now this bug is finally resolved... Sorry for the inconvenience!

@alexxchen
Copy link

alexxchen commented Sep 27, 2023

还是会出现这个错误,我这边hide_history_when_not_logged_in=true ,users : [] 就会出现

@ParkerLyu01
Copy link

还是会出现这个错误,我这边hide_history_when_not_logged_in=true ,users : [] 就会出现

我也是

@GaiZhenbiao
Copy link
Owner

还是会出现这个错误,我这边hide_history_when_not_logged_in=true ,users : [] 就会出现

我也是

我等会儿再调查下

@GaiZhenbiao
Copy link
Owner

@ParkerLyu01 @alexxchen 现在修复了

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

5 participants