Skip to main content
在 GitHub 上打开

Prediction Guard

本页介绍如何在 LangChain 中使用 Prediction Guard 生态系统。 它分为两部分:安装和设置,然后引用特定的 Prediction Guard 包装器。

此集成在 langchain-predictionguard 软件包中维护。

安装和设置

  • 安装 PredictionGuard Langchain 合作伙伴包:
pip install langchain-predictionguard
  • 获取 Prediction Guard API 密钥(如此所述)并将其设置为环境变量 (PREDICTIONGUARD_API_KEY)

Prediction Guard Langchain 集成

应用程序接口描述端点文档进口示例用法
ChatBuild Chat BotsChatfrom langchain_predictionguard import ChatPredictionGuardChatPredictionGuard.ipynb
CompletionsGenerate TextCompletionsfrom langchain_predictionguard import PredictionGuardPredictionGuard.ipynb
Text EmbeddingEmbed String to VectoresEmbeddingsfrom langchain_predictionguard import PredictionGuardEmbeddingsPredictionGuardEmbeddings.ipynb

开始

聊天模型

预测守卫聊天

查看使用示例

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)

LLM

预测卫士 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")