>Upstage 是一家领先的人工智能 (AI) 公司,专注于提供超越人类水平性能的大语言模型组件。 > >**Solar Pro** 是一款企业级大语言模型,针对单 GPU 部署进行了优化,擅长指令遵循和处理 HTML 和 Markdown 等结构化格式。它支持英语、韩语和日语,在多语言性能方面表现出色,并在金融、医疗和法律领域提供专业知识。
>除了 Solar,Upstage 还提供用于现实世界 RAG(检索增强生成)的功能,例如 **文档解析** 和 **Groundedness 检查**.
Upstage LangChain 集成
| API | Description | Import | Example usage |
|---|---|---|---|
| Chat | 使用 Solar Chat 构建助手 | from langchain_upstage import ChatUpstage | Go |
| Text Embedding | 将字符串嵌入为向量 | from langchain_upstage import UpstageEmbeddings | Go |
| Groundedness Check | 验证助手回复的真实性 | from langchain_upstage import UpstageGroundednessCheck | Go |
| Document Parse | 使用表格和图表序列化文档 | from langchain_upstage import UpstageDocumentParseLoader | Go |
参见 文档 了解更多关于模型和功能的信息。
安装和设置
安装 langchain-upstage package:
pip install -qU langchain-core langchain-upstage
获取 API 密钥 并设置环境变量 UPSTAGE_API_KEY.
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)
嵌入模型
参见 使用示例.
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)
文档加载器
文档解析
参见 使用示例.
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)
工具
Groundedness 检查
参见 使用示例.
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)