使用langchain官方的LLMChain样例报404错误
System Info / 系統信息
cuda:V11.8.89 python:3.8.10 transformers:4.36.0
Who can help? / 谁可以帮助到您?
No response
Information / 问题信息
- [x] The official example scripts / 官方的示例脚本
- [ ] My own modified scripts / 我自己修改的脚本和任务
Reproduction / 复现过程
- 正常启动openai_api_demo
- 使用langchain官方使用LLMChain连接ChatGLM样例运行程序,代码与该url中的代码相同:https://python.langchain.com/docs/integrations/llms/chatglm 代码如下:
from langchain.chains import LLMChain
from langchain.llms import ChatGLM
from langchain.prompts import PromptTemplate
# import os
template = """{question}"""
prompt = PromptTemplate(template=template, input_variables=["question"])
# default endpoint_url for a local deployed ChatGLM api server
endpoint_url = "http://127.0.0.1:8000"
# direct access endpoint in a proxied environment
# os.environ['NO_PROXY'] = '127.0.0.1'
llm = ChatGLM(
endpoint_url=endpoint_url,
max_token=80000,
history=[
["我将从美国到中国来旅游,出行前希望了解中国的城市", "欢迎问我任何问题。"]
],
top_p=0.9,
model_kwargs={"sample_model_args": False},
)
# turn on with_history only when you want the LLM object to keep track of the conversation history
# and send the accumulated context to the backend model api, which make it stateful. By default it is stateless.
# llm.with_history = True
llm_chain = LLMChain(prompt=prompt, llm=llm)
question = "北京和上海两座城市有什么不同?"
llm_chain.run(question)
- 运行报错如下:
Traceback (most recent call last):
File "test1.py", line 35, in <module>
llm_chain.run(question)
File "/root/miniconda3/lib/python3.8/site-packages/langchain/chains/base.py", line 507, in run
return self(args[0], callbacks=callbacks, tags=tags, metadata=metadata)[
File "/root/miniconda3/lib/python3.8/site-packages/langchain/chains/base.py", line 312, in __call__
raise e
File "/root/miniconda3/lib/python3.8/site-packages/langchain/chains/base.py", line 306, in __call__
self._call(inputs, run_manager=run_manager)
File "/root/miniconda3/lib/python3.8/site-packages/langchain/chains/llm.py", line 103, in _call
response = self.generate([inputs], run_manager=run_manager)
File "/root/miniconda3/lib/python3.8/site-packages/langchain/chains/llm.py", line 115, in generate
return self.llm.generate_prompt(
File "/root/miniconda3/lib/python3.8/site-packages/langchain_core/language_models/llms.py", line 516, in generate_prompt
return self.generate(prompt_strings, stop=stop, callbacks=callbacks, **kwargs)
File "/root/miniconda3/lib/python3.8/site-packages/langchain_core/language_models/llms.py", line 666, in generate
output = self._generate_helper(
File "/root/miniconda3/lib/python3.8/site-packages/langchain_core/language_models/llms.py", line 553, in _generate_helper
raise e
File "/root/miniconda3/lib/python3.8/site-packages/langchain_core/language_models/llms.py", line 540, in _generate_helper
self._generate(
File "/root/miniconda3/lib/python3.8/site-packages/langchain_core/language_models/llms.py", line 1069, in _generate
self._call(prompt, stop=stop, run_manager=run_manager, **kwargs)
File "/root/miniconda3/lib/python3.8/site-packages/langchain_community/llms/chatglm.py", line 104, in _call
raise ValueError(f"Failed with response: {response}")
ValueError: Failed with response: <Response [404]>
Expected behavior / 期待表现
正常返回运行结果
endpoint_url = "http://127.0.0.1:8000/v1"
endpoint_url = "http://127.0.0.1:8000/v1"
这样修改也还是不行,错误一样
ChatGLM是啥函数,我记得我们用的是GLM3,而不是langchain官方的
同问,应该怎么在Langchain的这段代码中调用chatglm?
ChatGLM是啥函数,我记得我们用的是GLM3,而不是langchain官方的
那就是LangChain那边的适配没有跟上吧,您可以看下我提供的LangChain官方文档链接,他们的确是怎么写的。
https://python.langchain.com/docs/integrations/llms/chatglm 确实是没有chatglm3的
遇到同样的错误,表示关注。
俺也是。。如何解决
同样问题
GLM3
GLM3的地址请发一下了
langchian用的是我们自己载入的方法,LLMchain是可以用的呀,404是没有请求到么
鉴于目前langchain调用chatglm的模块有问题,这里对相关内容进行修改,实现一个可用的模块
https://github.com/jsxyhelu/langchain_chatglm3
from langchain_chatglm3 import ChatGLM3
……
llm = ChatGLM3(endpoint_url = "http://192.168.196.211:6006/")
retriever = db.as_retriever()
memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
qa = ConversationalRetrievalChain.from_llm(llm, retriever, memory=memory)
response = qa({"question": "大潮分为那几个阶段?"})
answer = response["answer"]
print("RAG回答:", answer)
鉴于目前langchain调用chatglm的模块有问题,这里对相关内容进行修改,实现一个可用的模块
https://github.com/jsxyhelu/langchain_chatglm3
from langchain_chatglm3 import ChatGLM3 …… llm = ChatGLM3(endpoint_url = "http://192.168.196.211:6006/") retriever = db.as_retriever() memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True) qa = ConversationalRetrievalChain.from_llm(llm, retriever, memory=memory) response = qa({"question": "大潮分为那几个阶段?"}) answer = response["answer"] print("RAG回答:", answer)
大佬你好, 请问这段代码中 langchain 版本是哪个, 另外想将ConversationalRetrievalChain.from_llm(llm, ....)方法中的 llm 替换为 ChatGLM4 的 http 请求, 不知道是否可行, 可行的话具体应该怎么改写, 谢谢
鉴于目前langchain调用chatglm的模块有问题,这里对相关内容进行修改,实现一个可用的模块 https://github.com/jsxyhelu/langchain_chatglm3
from langchain_chatglm3 import ChatGLM3 …… llm = ChatGLM3(endpoint_url = "http://192.168.196.211:6006/") retriever = db.as_retriever() memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True) qa = ConversationalRetrievalChain.from_llm(llm, retriever, memory=memory) response = qa({"question": "大潮分为那几个阶段?"}) answer = response["answer"] print("RAG回答:", answer)大佬你好, 请问这段代码中 langchain 版本是哪个, 另外想将
ConversationalRetrievalChain.from_llm(llm, ....)方法中的 llm 替换为 ChatGLM4 的 http 请求, 不知道是否可行, 可行的话具体应该怎么改写, 谢谢
langchain应该就是直接版本;然后ChatGLM4的使用,我建议可以看看zhipuai,它应该有相关东西的。我这里就是调用的chatglm3
看一下源码 在chatglm3中,我的是chatglm36b 里面有个文件是langchain_openai_api.py ,里面就说了作为客户端 endpoint_url = "http://127.0.0.1:8000/v1/chat/completions" 你改成这个就可以了