> ## 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.

# Upstage 集成

> 使用 LangChain Python 与 Upstage 集成。

> **[Upstage](https://upstage.ai)** 是一家专注于提供接近人类水平性能大语言模型（LLM）组件的领先人工智能（AI）公司。
>
> **Solar Pro** 是面向单GPU部署优化的企业级大语言模型，在指令遵循和解析HTML、Markdown等结构化格式方面表现卓越。它支持英语、韩语和日语，具备顶尖的多语言性能，并在金融、医疗和法律领域拥有专业领域知识。

> 除了Solar，Upstage还提供真实场景RAG（检索增强生成）相关功能，例如**Document Parse**和**Groundedness Check**。

### Upstage LangChain集成

| API | 描述 | 导入 | 示例用法 |
| - | - | - | - |
| Chat | 使用Solar Chat构建助手 | `from langchain_upstage import ChatUpstage` | [Go](https://langchain-docs-zh.mintlify.site/langchain/oss/python/integrations/chat/upstage.md) |
| Text Embedding | 将字符串嵌入为向量 | `from langchain_upstage import UpstageEmbeddings` | [Go](https://langchain-docs-zh.mintlify.site/langchain/oss/python/integrations/embeddings/upstage.md) |
| Groundedness Check | 验证助手响应的接地性 | `from langchain_upstage import UpstageGroundednessCheck` | [Go](https://langchain-docs-zh.mintlify.site/langchain/oss/python/integrations/tools/upstage_groundedness_check.md) |
| Document Parse | 使用表格和图表序列化文档 | `from langchain_upstage import UpstageDocumentParseLoader` | [Go](https://langchain-docs-zh.mintlify.site/langchain/oss/python/integrations/document_loaders/upstage.md) |

更多关于模型和功能的详细信息，请参阅[文档](https://console.upstage.ai/docs/getting-started/overview)。

## 安装与配置

安装`langchain-upstage`包：

```bash theme={null}
pip install -qU langchain-core langchain-upstage
```

获取[API密钥](https://console.upstage.ai)并设置环境变量`UPSTAGE_API_KEY`。

```python theme={null}
import os

os.environ["UPSTAGE_API_KEY"] = "YOUR_API_KEY"
```

## 对话模型

### Solar LLM

查看[a usage example](https://langchain-docs-zh.mintlify.site/langchain/oss/python/integrations/chat/upstage.md)。

```python theme={null}
from langchain_upstage import ChatUpstage

chat = ChatUpstage()
response = chat.invoke("Hello, how are you?")
print(response)
```

## 嵌入模型

查看[a usage example](https://langchain-docs-zh.mintlify.site/langchain/oss/python/integrations/embeddings/upstage.md)。

```python theme={null}
from langchain_upstage import UpstageEmbeddings

embeddings = UpstageEmbeddings(model="solar-embedding-1-large")
doc_result = embeddings.embed_documents(
    ["Sung is a professor.", "This is another document"]
)
print(doc_result)

query_result = embeddings.embed_query("What does Sung do?")
print(query_result)
```

## 文档加载器

### 文档解析

查看[a usage example](https://langchain-docs-zh.mintlify.site/langchain/oss/python/integrations/document_loaders/upstage.md)。

```python theme={null}
from langchain_upstage import UpstageDocumentParseLoader

file_path = "/PATH/TO/YOUR/FILE.pdf"
layzer = UpstageDocumentParseLoader(file_path, split="page")

# For improved memory efficiency, consider using the lazy_load method to load documents page by page.
docs = layzer.load()  # or layzer.lazy_load()

for doc in docs[:3]:
    print(doc)
```

## 工具

### 接地性验证

查看[a usage example](https://langchain-docs-zh.mintlify.site/langchain/oss/python/integrations/tools/upstage_groundedness_check.md)。

```python theme={null}
from langchain_upstage import UpstageGroundednessCheck

groundedness_check = UpstageGroundednessCheck()

request_input = {
    "context": "Mauna Kea is an inactive volcano on the island of Hawaii. Its peak is 4,207.3 m above sea level, making it the highest point in Hawaii and second-highest peak of an island on Earth.",
    "answer": "Mauna Kea is 5,207.3 meters tall.",
}
response = groundedness_check.invoke(request_input)
print(response)
```

***

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


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