GPT4All
本頁面涵蓋如何在 LangChain 中使用 GPT4All
包裝器。本教學課程分為兩個部分:安裝與設定,以及附帶範例的使用方式。
安裝與設定
- 使用
pip install gpt4all
安裝 Python 套件 - 下載 GPT4All 模型 並將其放置在您想要的目錄中
在此範例中,我們使用 mistral-7b-openorca.Q4_0.gguf
mkdir models
wget https://gpt4all.io/models/gguf/mistral-7b-openorca.Q4_0.gguf -O models/mistral-7b-openorca.Q4_0.gguf
使用方式
GPT4All
若要使用 GPT4All 包裝器,您需要提供預先訓練模型檔案的路徑和模型的組態。
from langchain_community.llms import GPT4All
# Instantiate the model. Callbacks support token-wise streaming
model = GPT4All(model="./models/mistral-7b-openorca.Q4_0.gguf", n_threads=8)
# Generate text
response = model.invoke("Once upon a time, ")
API 參考:GPT4All
您也可以自訂生成參數,例如 n_predict
、temp
、top_p
、top_k
和其他參數。
若要串流模型的預測,請加入 CallbackManager。
from langchain_community.llms import GPT4All
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
# There are many CallbackHandlers supported, such as
# from langchain.callbacks.streamlit import StreamlitCallbackHandler
callbacks = [StreamingStdOutCallbackHandler()]
model = GPT4All(model="./models/mistral-7b-openorca.Q4_0.gguf", n_threads=8)
# Generate text. Tokens are streamed through the callback manager.
model.invoke("Once upon a time, ", callbacks=callbacks)
模型檔案
您可以從 GPT4All 用戶端下載模型檔案。您可以從 GPT4All 網站下載用戶端。
如需更詳細的逐步解說,請參閱此筆記本