Skip to main content
Open In ColabOpen on GitHub

Upstage

Upstage 是一家领先的人工智能(AI)公司,专注于提供超越人类水平的LLM组件。

Solar Pro 是一款企业级LLM,专为单GPU部署优化,擅长指令跟随和处理HTML和Markdown等结构化格式。它支持英语、韩语和日语,具有顶尖的多语言性能,并在金融、医疗和法律领域提供专业知识。

除了Solar之外,Upstage还提供了现实世界中的RAG(检索增强生成)功能,例如文档解析基础性检查

Upstage LangChain 集成

API描述导入示例用法
聊天使用Solar Chat构建助手from langchain_upstage import ChatUpstageGo
文本嵌入将字符串嵌入为向量from langchain_upstage import UpstageEmbeddingsGo
基础性检查验证助手回答的基础性from langchain_upstage import UpstageGroundednessCheckGo
文档解析序列化包含表格和图表的文档from langchain_upstage import UpstageDocumentParseLoaderGo

查看文档以获取有关模型和功能的更多详细信息。

安装与设置

安装 langchain-upstage 包:

pip install -qU langchain-core langchain-upstage

获取 API Keys 并设置环境变量 UPSTAGE_API_KEY

import os

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

聊天模型

Solar 大语言模型

参见 使用示例

from langchain_upstage import ChatUpstage

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

嵌入模型

参见使用示例

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)
API Reference:UpstageEmbeddings

文档加载器

文档解析

参见使用示例

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)

工具

基础性检查

参见使用示例

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)

这个页面有帮助吗?