跑privategpt中报错none is not an allowed value (type=type-爱代码爱编程
原文链接:https://github.com/imartinez/privateGPT
报错信息:
root@autodl-container-67c3119208-4195ee62:~/autodl-tmp/privateGPT# python ingest.py
Traceback (most recent call last):
File "ingest.py", line 24, in <module>
from constants import CHROMA_SETTINGS
File "/root/autodl-tmp/privateGPT/constants.py", line 11, in <module>
CHROMA_SETTINGS = Settings(
File "pydantic/env_settings.py", line 39, in pydantic.env_settings.BaseSettings.__init__
File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for Settings
persist_directory
none is not an allowed value (type=type_error.none.not_allowed)
原因查找:
一开始以为是环境的原因,毕竟他给的那个环境安起来很麻烦……
然后发现好像没那么复杂,单纯可能是load_dotenv没找到环境,于是在constanst.py的这两行代码打了个print
load_dotenv()
# Define the folder for storing database
PERSIST_DIRECTORY = os.environ.get('PERSIST_DIRECTORY')
#检测bug
print(PERSIST_DIRECTORY)
# Define the Chroma settings
CHROMA_SETTINGS = Settings(
果不其然,打出来的全是none……load_dotenv()虽然说明是自动检测,但我在云服务器里实验,发现检测不到env
把load_dotenv()改成下面这样就解决了:
from dotenv import load_dotenv, find_dotenv
from pathlib import Path
load_dotenv(find_dotenv(Path.cwd().joinpath('xxx.env')))
第二个问题:
SyntaxError: invalid syntax
语法错误,为什么语法错误呢……因为这里的privateGPT.py采用了python的switch-case语句,但是这个语法是python3.10才增加的,所以要么改成if...else,要么更新python版本。