??本篇主要內(nèi)容為介紹ChatGLM3的安裝使用,后續(xù)才會涉及到使用LangChain實現(xiàn)本地知識庫的內(nèi)容;
??ChatGLM為智譜與清華大學(xué)開源的一個大語言模型,支持多輪對話、內(nèi)容創(chuàng)作等,ChatGLM3-6B為ChatGLM3系列中門檻相對較低的一個,本地部署提供兼容OpenAI的API;
??LangChain用于快速開發(fā)基于大語言模型應(yīng)用程序的框架,提供了一整套工具、組件、接口等使得程序與大語言模型輕松交互組件快速組合、集成;如在模型上外掛本地知識庫等;
ChatGLM3安裝
??這里將安裝使用int4量化版本的ChatGLM3-6B推理程序ChatGLM.cpp項目地址為:
??https://github.com/li-plus/chatglm.cpp 這里有詳細(xì)的安裝流程,安裝完成并下載好預(yù)訓(xùn)練模型后即可在Python代碼通過ChatGLM.cpp推理程序調(diào)用預(yù)訓(xùn)練模型;
示例如下:
import chatglm_cpp
pipeline = chatglm_cpp.Pipeline("/mnt/d/software/dev/gpt/chatglm.cpp/chatglm3-ggml.bin")
p = pipeline.chat([chatglm_cpp.ChatMessage(role="user", content="海南在哪里")])
print(p.content)
API Server模式:
安裝組件:pip install 'chatglm-cpp[api]'
啟動基于LangChain Api的接口服務(wù)程序:
MODEL=./chatglm2-ggml.bin uvicorn chatglm_cpp.langchain_api:app --host 127.0.0.1 --port 8000
curl http請求調(diào)用:
curl http://127.0.0.1:8000 -H 'Content-Type: application/json' -d '{"prompt": "你好"}'
LangChain調(diào)用:
from langchain.llms import ChatGLM
llm = ChatGLM(endpoint_url="http://127.0.0.1:8000")
llm.predict("你好")
'你好!我是人工智能助手,很高興見到你,歡迎問我任何問題。'
結(jié)合gradio使用:
import gradio as gr
import chatglm_cpp
def chat(quetion,history):
pipeline = chatglm_cpp.Pipeline("/mnt/d/software/dev/gpt/chatglm.cpp/chatglm3-ggml.bin")
p = pipeline.chat([chatglm_cpp.ChatMessage(role="user", content=quetion)])
return p.content
demo = gr.ChatInterface(chat)
demo.launch(inbrowser=True)
文章來源:http://www.zghlxwxcb.cn/news/detail-747400.html
??雖然只是60億參數(shù)規(guī)模的模型,還只是int4量化版的,但從輸出內(nèi)容看算得上一個玩具;在與LangChain結(jié)合后可玩性將會提高;文章來源地址http://www.zghlxwxcb.cn/news/detail-747400.html
到了這里,關(guān)于使用LangChain與ChatGLM實現(xiàn)本地知識庫(一)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!