Langchain-Chatchat
Langchain-Chatchat copied to clipboard
ValidationError: 1 validation error for HuggingFaceEmbeddings model_kwargs extra fields not permitted (type=value_error.extra)
ValidationError: 1 validation error for HuggingFaceEmbeddings model_kwargs extra fields not permitted (type=value_error.extra)
Loading checkpoint shards: 100%|███████████████████████████████████████████████████████████████████████████████████████████| 8/8 [00:12<00:00, 1.62s/it]
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /root/autodl-tmp/chatglm20220419/langchain-ChatGLM-master/cli_demo.py:19 in
I have the same problem. Have you solved it?
update langchain as suggested in requirements.txt
it’s a new feature in langchain newer than 0.0.146
不知道你是不是拷贝的案例到别的机器上运行,我这边是这样的,所以修改langchain版本无效,导致这个问题的原因是chatglm_llm.py版本不一致
chatglm_llm.py 使用如下历史版本即可
https://github.com/imClumsyPanda/langchain-ChatGLM/blob/4ec339777c20aa738df2dd4653d3fad6c9642ed6/chatglm_llm.py
` from langchain.llms.base import LLM from typing import Optional, List from langchain.llms.utils import enforce_stop_tokens from transformers import AutoTokenizer, AutoModel import torch
DEVICE = "cuda" if torch.cuda.is_available() else "mps" if torch.backends.mps.is_available() else "cpu" DEVICE_ID = "0" if torch.cuda.is_available() else None CUDA_DEVICE = f"{DEVICE}:{DEVICE_ID}" if DEVICE_ID else DEVICE
def torch_gc(): if torch.cuda.is_available(): with torch.cuda.device(CUDA_DEVICE): torch.cuda.empty_cache() torch.cuda.ipc_collect()
class ChatGLM(LLM): max_token: int = 10000 temperature: float = 0.01 top_p = 0.9 history = [] tokenizer: object = None model: object = None history_len: int = 10
def __init__(self):
super().__init__()
@property
def _llm_type(self) -> str:
return "ChatGLM"
def _call(self,
prompt: str,
stop: Optional[List[str]] = None) -> str:
response, _ = self.model.chat(
self.tokenizer,
prompt,
history=self.history[-self.history_len:],
max_length=self.max_token,
temperature=self.temperature,
)
torch_gc()
if stop is not None:
response = enforce_stop_tokens(response, stop)
self.history = self.history+[[None, response]]
return response
def load_model(self, model_name_or_path: str = "THUDM/chatglm-6b"):
self.tokenizer = AutoTokenizer.from_pretrained(
model_name_or_path,
trust_remote_code=True
)
if torch.cuda.is_available():
self.model = (
AutoModel.from_pretrained(
model_name_or_path,
trust_remote_code=True)
.half()
.cuda()
)
elif torch.backends.mps.is_available():
self.model = (
AutoModel.from_pretrained(
model_name_or_path,
trust_remote_code=True)
.float()
.to('mps')
)
else:
self.model = (
AutoModel.from_pretrained(
model_name_or_path,
trust_remote_code=True)
.float()
)
self.model = self.model.eval()
`
Had this issue, it was caused by missing sentence_transformer ( pip install sentence_transformers )
我最后这样解决了: pip install sentence_transformers pip install langchain==0.0.174 -i https://pypi.doubanio.com/simple/ --trusted-host pypi.doubanio.com
from langchain_community.document_loaders import PyPDFLoader , DirectoryLoader , PDFMinerLoader from langchain.text_splitter import RecursiveCharacterTextSplitter from langchain_community.embeddings import SentenceTransformerEmbeddings from langchain_community.vectorstores.chroma import Chroma import os from constants import CHROMA_SETTINGS
persist_directory = 'db'
def main(): for root , dirs , files in os.walk('docs'): for file in files: if file.endswith('.pdf'): print(file) loader = PDFMinerLoader(os.path.join(root,file)) documents = loader.load() text_splitter = RecursiveCharacterTextSplitter(chunk_size = 500 , chunk_overlap = 200) texts = text_splitter.split_documents(documents)
embeddings = SentenceTransformerEmbeddings(model ='all-MiniLM-L6-v2' )
db =Chroma.from_documents(texts , embeddings , persist_directory=persist_directory,client_settings=CHROMA_SETTINGS)
db.persist()
db = None
if name == 'main': main()
###################
Traceback (most recent call last):
File "F:\MydataScience\NLP\Chat_With_multiple_pdf\ingest.py", line 27, in
(pdf) F:\MydataScience\NLP\Chat_With_multiple_pdf>python ingest.py
bdcon.pdf
Traceback (most recent call last):
File "F:\MydataScience\NLP\Chat_With_multiple_pdf\ingest.py", line 27, in
why getting this error can't figure it out ..
could anyone help me here, iam getting this error pydantic.v1.error_wrappers.ValidationError: 1 validation error for HuggingFaceEndpoint root Could not authenticate with huggingface_hub. Please check your API token. (type=value_error)
I am getting this error could anyone help me in solving this?
ValidationError: 1 validation error for HuggingFaceEndpoint root Could not authenticate with huggingface_hub. Please check your API token. (type=value_error)
Traceback:
File "C:\Desktop\langchain\lang1\Lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 584, in _run_script
exec(code, module.dict)
File "C:\Desktop\langchain\main2_demo.py", line 25, in
Getting this error ValidationError: 1 validation error for HuggingFaceEmbeddings model extra fields not permitted (type=value_error.extra) with sentence-transformers/all-MiniLM-L6-v2 model