Prediction Guard
本頁面涵蓋如何在 LangChain 中使用 Prediction Guard 生態系統。它分為兩個部分:安裝與設定,以及 Prediction Guard 封裝器的相關參考。
此整合維護在 langchain-predictionguard 套件中。
安裝與設定
- 安裝 PredictionGuard Langchain 合作夥伴套件
pip install langchain-predictionguard
- 取得 Prediction Guard API 金鑰 (如此處所述) 並將其設定為環境變數 (
PREDICTIONGUARD_API_KEY
)
Prediction Guard Langchain 整合
API | 描述 | 端點文件 | 導入 | 範例用法 |
---|---|---|---|---|
聊天 | 建立聊天機器人 | 聊天 | from langchain_predictionguard import ChatPredictionGuard | ChatPredictionGuard.ipynb |
完成 | 產生文字 | 完成 | from langchain_predictionguard import PredictionGuard | PredictionGuard.ipynb |
文字嵌入 | 將字串嵌入為向量 | 嵌入 | from langchain_predictionguard import PredictionGuardEmbeddings | PredictionGuardEmbeddings.ipynb |
開始使用
聊天模型
Prediction Guard 聊天
請參閱使用範例
from langchain_predictionguard import ChatPredictionGuard
用法
# If predictionguard_api_key is not passed, default behavior is to use the `PREDICTIONGUARD_API_KEY` environment variable.
chat = ChatPredictionGuard(model="Hermes-3-Llama-3.1-8B")
chat.invoke("Tell me a joke")
嵌入模型
Prediction Guard 嵌入
請參閱使用範例
from langchain_predictionguard import PredictionGuardEmbeddings
用法
# If predictionguard_api_key is not passed, default behavior is to use the `PREDICTIONGUARD_API_KEY` environment variable.
embeddings = PredictionGuardEmbeddings(model="bridgetower-large-itm-mlm-itc")
text = "This is an embedding example."
output = embeddings.embed_query(text)
LLMs
Prediction Guard LLM
請參閱使用範例
from langchain_predictionguard import PredictionGuard
用法
# If predictionguard_api_key is not passed, default behavior is to use the `PREDICTIONGUARD_API_KEY` environment variable.
llm = PredictionGuard(model="Hermes-2-Pro-Llama-3-8B")
llm.invoke("Tell me a joke about bears")