Upstage
Upstage is a leading artificial intelligence (AI) company specializing in delivering above-human-grade performance LLM components.
Solar Pro is an enterprise-grade LLM optimized for single-GPU deployment, excelling in instruction-following and processing structured formats like HTML and Markdown. It supports English, Korean, and Japanese with top multilingual performance and offers domain expertise in finance, healthcare, and legal.
Other than Solar, Upstage also offers features for real-world RAG (retrieval-augmented generation), such as Document Parse and Groundedness Check.
Upstage LangChain 集成
| API | 描述 | 导入 | 使用示例 |
|---|---|---|---|
| Chat | Build assistants using Solar Chat | from langchain_upstage import ChatUpstage | Go |
| Text Embedding | Embed strings to vectors | from langchain_upstage import UpstageEmbeddings | Go |
| Groundedness Check | Verify groundedness of assistant's response | from langchain_upstage import UpstageGroundednessCheck | Go |
| Document Parse | Serialize documents with tables and figures | from langchain_upstage import UpstageDocumentParseLoader | Go |
查看更多关于模型和功能的详细信息,请参阅文档。
安装与设置
安装 langchain-upstage 个包:
pip install -qU langchain-core langchain-upstage
获取 API密钥 并设置环境变量 UPSTAGE_API_KEY。
import os
os.environ["UPSTAGE_API_KEY"] = "YOUR_API_KEY"
聊天模型
太阳大型语言模型
查看使用示例。
from langchain_upstage import ChatUpstage
chat = ChatUpstage()
response = chat.invoke("Hello, how are you?")
print(response)
API 参考: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 参考: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 参考: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 参考:UpstageGroundednessCheck