Skip to main content
Open In Colab在 GitHub 上打开

Upstage

Upstage 是一家领先的人工智能 (AI) 公司,专门提供性能高于人类级的 LLM 组件。

Solar Pro 是一款企业级 LLM,针对单 GPU 部署进行了优化,擅长指令跟踪和处理结构化格式,如 HTML 和 Markdown。它支持英语、韩语和日语,具有一流的多语言性能,并提供金融、医疗保健和法律方面的领域专业知识。

除了 Solar 之外,Upstage 还提供用于实际 RAG(检索增强生成)的功能,例如 Document ParseGroundedness Check

Upstage LangChain 集成

应用程序接口描述进口用法示例
ChatBuild assistants using Solar Chatfrom langchain_upstage import ChatUpstageGo
Text EmbeddingEmbed strings to vectorsfrom langchain_upstage import UpstageEmbeddingsGo
Groundedness CheckVerify groundedness of assistant's responsefrom langchain_upstage import UpstageGroundednessCheckGo
Document ParseSerialize documents with tables and figuresfrom langchain_upstage import UpstageDocumentParseLoaderGo

有关模型和功能的更多详细信息,请参阅文档

安装和设置

安装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)

工具

接地检查

请参阅使用示例

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)