Upstage
Upstage 是一家领先的人工智能 (AI) 公司,专注于提供超越人类水平的 LLM 组件。
Solar Pro 是一款企业级 LLM,针对单 GPU 部署进行了优化,在指令遵循和处理 HTML、Markdown 等结构化格式方面表现出色。它支持英语、韩语和日语,具有顶级的多语言性能,并在金融、医疗和法律领域拥有专业知识。
除了 Solar,Upstage 还为真实世界的 RAG(检索增强生成)提供功能,例如 Document Parse 和 Groundedness Check。
Upstage LangChain 集成
| API | 描述 | 导入 | 示例用法 |
|---|---|---|---|
| Chat | 使用 Solar Chat 构建助手 | from langchain_upstage import ChatUpstage | 前往 |
| Text Embedding | 将字符串嵌入为向量 | from langchain_upstage import UpstageEmbeddings | 前往 |
| Groundedness Check | 验证助手响应的 groundedness | from langchain_upstage import UpstageGroundednessCheck | 前往 |
| Document Parse | 序列化带表格和图形的文档 | from langchain_upstage import UpstageDocumentParseLoader | 前往 |
更多关于模型和功能详情,请参阅文档。
安装与设置
安装 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 LLM
请参阅使用示例。
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)
API Reference:UpstageDocumentParseLoader
工具
基于事实的检查
请参见 使用示例。
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)
API Reference:UpstageGroundednessCheck