Oracle Cloud Infrastructure Generative AI
Oracle Cloud Infrastructure (OCI) Generative AI 是一項全方位託管服務,提供一組最先進、可自訂的大型語言模型 (LLM),涵蓋廣泛的用例,並可透過單一 API 取得。使用 OCI Generative AI 服務,您可以存取現成的預先訓練模型,或根據您在專用 AI 叢集上的自有資料,建立和託管您自己微調的自訂模型。服務和 API 的詳細文件可在此處和此處取得:這裡 和 這裡。
本筆記本說明如何將 OCI 的 Genrative AI 模型與 LangChain 搭配使用。
先決條件
我們需要安裝 oci sdk
!pip install -U oci
OCI Generative AI API 端點
https://inference.generativeai.us-chicago-1.oci.oraclecloud.com
驗證
此 LangChain 整合支援的驗證方法為
- API 金鑰
- 工作階段權杖
- 執行個體主體
- 資源主體
這些方法遵循此處詳述的標準 SDK 驗證方法:這裡。
使用方式
from langchain_community.embeddings import OCIGenAIEmbeddings
# use default authN method API-key
embeddings = OCIGenAIEmbeddings(
model_id="MY_EMBEDDING_MODEL",
service_endpoint="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com",
compartment_id="MY_OCID",
)
query = "This is a query in English."
response = embeddings.embed_query(query)
print(response)
documents = ["This is a sample document", "and here is another one"]
response = embeddings.embed_documents(documents)
print(response)
API 參考:OCIGenAIEmbeddings
# Use Session Token to authN
embeddings = OCIGenAIEmbeddings(
model_id="MY_EMBEDDING_MODEL",
service_endpoint="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com",
compartment_id="MY_OCID",
auth_type="SECURITY_TOKEN",
auth_profile="MY_PROFILE", # replace with your profile name
auth_file_location="MY_CONFIG_FILE_LOCATION", # replace with file location where profile name configs present
)
query = "This is a sample query"
response = embeddings.embed_query(query)
print(response)
documents = ["This is a sample document", "and here is another one"]
response = embeddings.embed_documents(documents)
print(response)