> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-docs-zh.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Prediction guard 集成

> 使用 LangChain Python 与 Prediction guard 集成。

本页面介绍了如何在 LangChain 中使用 Prediction Guard 生态系统。
内容分为两部分：安装和设置，以及针对特定 Prediction Guard 包装器的参考。

该集成维护在 [langchain-predictionguard](https://github.com/predictionguard/langchain-predictionguard) 包中。

## 安装和设置

* 安装 PredictionGuard LangChain 合作伙伴包：

```bash pip theme={null}
pip install langchain-predictionguard
```

```bash uv theme={null}
uv add langchain-predictionguard
```

* 获取 Prediction Guard API 密钥（如 [Prediction Guard 文档](https://docs.predictionguard.com/) 中所述）并将其设置为环境变量（`PREDICTIONGUARD_API_KEY`）

## Prediction guard LangChain 集成

| API | 描述 | 端点文档 | 导入 | 示例用法 |
| - | - | - | - | - |
| Chat | 构建聊天机器人 | [Chat](https://docs.predictionguard.com/api-reference/api-reference/chat-completions) | `from langchain_predictionguard import ChatPredictionGuard` | [`langchain-predictionguard`](https://github.com/predictionguard/langchain-predictionguard) |
| Completions | 生成文本 | [Completions](https://docs.predictionguard.com/api-reference/api-reference/completions) | `from langchain_predictionguard import PredictionGuard` | [PredictionGuard.ipynb](https://langchain-docs-zh.mintlify.site/langchain/oss/python/integrations/llms/predictionguard.md) |
| Text Embedding | 将字符串嵌入到向量 | [Embeddings](https://docs.predictionguard.com/api-reference/api-reference/embeddings) | `from langchain_predictionguard import PredictionGuardEmbeddings` | [PredictionGuard 嵌入](https://docs.predictionguard.com/api-reference/api-reference/embeddings) |

## 入门指南

## 对话模型

### Prediction guard 对话

查看 [使用示例](https://github.com/predictionguard/langchain-predictionguard)

```python theme={null}
from langchain_predictionguard import ChatPredictionGuard
```

#### 使用

```python theme={null}
# 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 嵌入

查看 [使用示例](https://docs.predictionguard.com/api-reference/api-reference/embeddings)

```python theme={null}
from langchain_predictionguard import PredictionGuardEmbeddings
```

#### 使用

```python theme={null}
# 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)
```

## 大语言模型

### Prediction guard 大语言模型

查看 [使用示例](https://langchain-docs-zh.mintlify.site/langchain/oss/python/integrations/llms/predictionguard.md)

```python theme={null}
from langchain_predictionguard import PredictionGuard
```

#### 使用

```python theme={null}
# 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")
```

***

> 官方原文：[src/oss/python/integrations/providers/predictionguard.mdx](https://github.com/langchain-ai/docs/blob/main/src/oss/python/integrations/providers/predictionguard.mdx) · 非官方翻译，译文由 AI 生成，以英文原文为准。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.