Langchain-Chatchat
Langchain-Chatchat copied to clipboard
报错 No module named 'chatglm_llm'
明明已经安装了包,却在python里吊不出来
centos 环境,
Python 3.10.5 (main, Apr 11 2023, 00:43:05) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
这个是项目中的路径 需要在项目路径下访问调用
wa2003 @.***>于2023年5月4日 周四17:21写道:
明明已经安装了包,却在python里吊不出来 centos 环境, Python 3.10.5 (main, Apr 11 2023, 00:43:05) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux [image: image] https://user-images.githubusercontent.com/11847871/236163110-e4fe1b8e-e2e0-4511-9b31-31b4afc0c467.png
[image: image] https://user-images.githubusercontent.com/11847871/236163312-a4a31eaa-87de-4880-9cbe-4e9ef2bc0e6d.png
— Reply to this email directly, view it on GitHub https://github.com/imClumsyPanda/langchain-ChatGLM/issues/230, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABLH5EXKPQZF5PT55XUTJ63XENYJBANCNFSM6AAAAAAXVQKNRY . You are receiving this because you are subscribed to this thread.Message ID: @.***>
这个是项目中的路径 需要在项目路径下访问调用 wa2003 @.>于2023年5月4日 周四17:21写道: … 明明已经安装了包,却在python里吊不出来 centos 环境, Python 3.10.5 (main, Apr 11 2023, 00:43:05) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux [image: image] https://user-images.githubusercontent.com/11847871/236163110-e4fe1b8e-e2e0-4511-9b31-31b4afc0c467.png [image: image] https://user-images.githubusercontent.com/11847871/236163312-a4a31eaa-87de-4880-9cbe-4e9ef2bc0e6d.png — Reply to this email directly, view it on GitHub <#230>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABLH5EXKPQZF5PT55XUTJ63XENYJBANCNFSM6AAAAAAXVQKNRY . You are receiving this because you are subscribed to this thread.Message ID: @.> 同遇到这个问题,没听懂,是models目录下的chatglm_llm吗?我使用 from models.chatglm_llm import ChatGLM 后出现 ValueError: "ChatGLM" object has no field "history"
同遇到这个问题,没听懂,是models目录下的chatglm_llm吗?我使用 from models.chatglm_llm import ChatGLM 后出现 ValueError: "ChatGLM" object has no field "history" @imClumsyPanda
同遇到这个问题,没听懂,是models目录下的chatglm_llm吗?我使用 from models.chatglm_llm import ChatGLM 后出现 ValueError: "ChatGLM" object has no field "history" @imClumsyPanda
这个我也遇到了,我直接去chatglm_llm中将ChatGLM类下,发现它的history属性被注释了,去掉#后,可以运行,但是执行chatglm("........text..........")时还是会报错,显示 ChatGLM._call() got an unexpected keyword argument 'stop'
同遇到这个问题,没听懂,是models目录下的chatglm_llm吗?我使用 from models.chatglm_llm import ChatGLM 后出现 ValueError: "ChatGLM" object has no field "history" @imClumsyPanda
这个我也遇到了,我直接去chatglm_llm中将ChatGLM类下,发现它的history属性被注释了,去掉#后,可以运行,但是执行chatglm("........text..........")时还是会报错,显示 ChatGLM._call() got an unexpected keyword argument 'stop'
哪一行代码注释?我看只有def chat里有self.history
请问是使用什么模型运行哪个脚本时发生的报错,在当前版本的webui和cli_demo中应该都已经去掉了ChatGLM.history的使用
同遇到这个问题,没听懂,是models目录下的chatglm_llm吗?我使用 from models.chatglm_llm import ChatGLM 后出现 ValueError: "ChatGLM" object has no field "history" @imClumsyPanda
这个我也遇到了,我直接去chatglm_llm中将ChatGLM类下,发现它的history属性被注释了,去掉#后,可以运行,但是执行chatglm("........text..........")时还是会报错,显示 ChatGLM._call() got an unexpected keyword argument 'stop'
请问是使用什么模型运行哪个脚本时发生的报错,在当前版本的webui和cli_demo中应该都已经去掉了ChatGLM.history的使用
def init_cfg(LLM_MODEL, EMBEDDING_MODEL, LLM_HISTORY_LEN, V_SEARCH_TOP_K=6): global chatglm, embeddings, VECTOR_SEARCH_TOP_K VECTOR_SEARCH_TOP_K = V_SEARCH_TOP_K
chatglm = ChatGLM()
chatglm.load_model(model_name_or_path=llm_model_dict[LLM_MODEL])
chatglm.history_len = LLM_HISTORY_LEN
embeddings = HuggingFaceEmbeddings(model_name=embedding_model_dict[EMBEDDING_MODEL],)
embeddings.client = sentence_transformers.SentenceTransformer(embeddings.model_name,
device=DEVICE)
chatglm.history = [] display(Markdown(chatglm(prompt='chatglm-6b 的局限性具体体现在哪里,如何实现改进')))
然后最后一行报错如下: TypeError: ChatGLM._call() got an unexpected keyword argument 'stop'
全部代码为: from langchain.chains import RetrievalQA from langchain.prompts import PromptTemplate from langchain.embeddings.huggingface import HuggingFaceEmbeddings from langchain.vectorstores import FAISS from langchain.document_loaders import UnstructuredFileLoader, DirectoryLoader from models.chatglm_llm import ChatGLM from textsplitter.chinese_text_splitter import ChineseTextSplitter import sentence_transformers import torch import os # import readline
EMBEDDING_MODEL = 'text2vec'
VECTOR_SEARCH_TOP_K = 6
LLM_MODEL = 'chatglm-6b'
LLM_HISTORY_LEN = 3
DEVICE = 'cuda' if torch.cuda.is_available() else 'cpu'
embedding_model_dict = {
'ernie-tiny': 'nghuyong/ernie-3.0-nano-zh',
'ernie-base': 'nghuyong/ernie-3.0-base-zh',
'text2vec': 'D:\project\langchain-ChatGLM-0.1.9\embedding_text2vec',
}
llm_model_dict = {
"chatglm-6b-int4-qe": "THUDM/chatglm-6b-int4-qe",
"chatglm-6b-int4": "THUDM/chatglm-6b-int4",
"chatglm-6b": "D:\project\ChatGLM-6B-main\ChatGLM-6B-main\chatGLM-6B",
}
def init_cfg(LLM_MODEL, EMBEDDING_MODEL, LLM_HISTORY_LEN, V_SEARCH_TOP_K=6):
global chatglm, embeddings, VECTOR_SEARCH_TOP_K
VECTOR_SEARCH_TOP_K = V_SEARCH_TOP_K
chatglm = ChatGLM()
chatglm.load_model(model_name_or_path=llm_model_dict[LLM_MODEL])
chatglm.history_len = LLM_HISTORY_LEN
embeddings = HuggingFaceEmbeddings(model_name=embedding_model_dict[EMBEDDING_MODEL], )
embeddings.client = sentence_transformers.SentenceTransformer(embeddings.model_name, device=DEVICE)
def init_knowledge_vector_store(filepath:str):
docs = []
if not os.path.exists(filepath):
print('路径不存在')
return None
elif os.path.isfile(filepath):
file = os.path.split(filepath)[-1]
try:
loader = UnstructuredFileLoader(filepath, mode='elements')
docs = loader.load()
print(f'{file} 已加载成功')
except:
print(f'{file} 未能成功加载')
return None
elif os.path.isdir(filepath):
try:
loader = DirectoryLoader(filepath, glob='**/*.md')
textsplitter = ChineseTextSplitter()
docs = loader.load_and_split(textsplitter)
print(f'{filepath} 已成功加载')
except Exception as e:
print(f'{filepath} 未能成功加载:{e}')
return None
vector_store = FAISS.from_documents(docs, embeddings)
return vector_store
def get_knowledge_based_answer(query, vector_store, chat_history=[]):
global chatglm, embeddings
prompt_template = """基于以下已知信息,简洁和专业的来回答用户的问题。
如果无法从中得到答案,请说“根据已知信息无法回答该问题” 或 “没有提供足够的相关信息”,不允许在答案中添加编造成分,答案请使用中文。
已知内容:
{context}
问题:
{question}
"""
prompt = PromptTemplate(
template=prompt_template,
input_variables=['context', 'question']
)
chatglm.history = chat_history
knowledge_chain = RetrievalQA.from_llm(
llm=chatglm,
retriever=vector_store.as_retriever(search_kwargs={'k':VECTOR_SEARCH_TOP_K}),
prompt=prompt
)
knowledge_chain.combine_documents_chain.document_prompt=PromptTemplate(
input_variables=['page_content'], template='{page_content}'
)
knowledge_chain.return_source_documents = True
result = knowledge_chain({'query':query})
chatglm.history[-1][0] = query
return result, chatglm.history
from IPython.display import display, Markdown, clear_output
def display_answer(query, vector_store, history=[]):
resp, history = get_knowledge_based_answer(query=query, vector_store=vector_store, chat_history=history)
display(Markdown(resp['result']))
return resp, history
init_cfg(LLM_MODEL, EMBEDDING_MODEL, LLM_HISTORY_LEN)
vector_store = init_knowledge_vector_store('D:\project\langchain-ChatGLM-0.1.9\content\langchain-ChatGLM_README.md')
chatglm.history = []
display(Markdown(chatglm("chatglm-6b 的局限性具体体现在哪里,如何实现改进")))
想问一下是手动更新了项目中部分文件吗?建议重新下载项目代码后再试试看
想问一下是手动更新了项目中部分文件吗?建议重新下载项目代码后再试试看
几乎没变(唯一改动是chatglm_llm.py中CHATGLM类的history属性,把它的注释给去了),而且是chatglm("chatglm-6b 的局限性具体体现在哪里,如何实现改进")出了问题,您的项目代码应该没啥问题,可能是https://www.heywhale.com/mw/project/643977aa446c45f4592a1e59教程出错了
可能是因为上面的代码没有及时跟进更新
同样的问题,希望能同步下教程代码
https://www.heywhale.com/mw/project/643977aa446c45f4592a1e59
所以应该怎么改呀,同样的问题,希望更新下教程代码