跳到主要內容
Open In ColabOpen on GitHub

Upstage

Upstage 是一家領先的人工智慧 (AI) 公司,專門提供超越人類等級效能的 LLM 組件。

Solar Pro 是一款企業級 LLM,針對單 GPU 部署進行了最佳化,擅長指令遵循和處理 HTML 和 Markdown 等結構化格式。它支援英語、韓語和日語,具有頂級多語言效能,並提供金融、醫療保健和法律領域的專業知識。

除了 Solar 之外,Upstage 還提供用於真實世界 RAG(檢索增強生成)的功能,例如Document ParseGroundedness Check

Upstage LangChain 整合

API描述匯入使用範例
聊天使用 Solar Chat 建立助理from langchain_upstage import ChatUpstage前往
文字嵌入將字串嵌入向量from langchain_upstage import UpstageEmbeddings前往
Groundedness Check驗證助理回應的 groundednessfrom langchain_upstage import UpstageGroundednessCheck前往
Document Parse序列化包含表格和圖形的文件from langchain_upstage import UpstageDocumentParseLoader前往

請參閱文件以瞭解有關模型和功能的更多詳細資訊。

安裝與設定

安裝 langchain-upstage 套件

pip install -qU langchain-core langchain-upstage

取得 API 金鑰 並設定環境變數 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 參考: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

文件載入器

Document Parse

請參閱使用範例

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 Check

請參閱使用範例

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)

此頁面是否對您有幫助?