Upstage
Upstage 是一家领先的人工智能 (AI) 公司,专门提供性能高于人类级的 LLM 组件。
Solar Pro 是一款企业级 LLM,针对单 GPU 部署进行了优化,擅长指令跟踪和处理结构化格式,如 HTML 和 Markdown。它支持英语、韩语和日语,具有一流的多语言性能,并提供金融、医疗保健和法律方面的领域专业知识。
除了 Solar 之外,Upstage 还提供用于实际 RAG(检索增强生成)的功能,例如 Document Parse 和 Groundedness Check。
Upstage LangChain 集成
| 应用程序接口 | 描述 | 进口 | 用法示例 |
|---|---|---|---|
| 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"
聊天模型
太阳能 LLM
请参阅使用示例。
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