跳到主要內容

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 整合支援的身分驗證方法為

  1. API 金鑰
  2. 工作階段權杖
  3. 執行個體主體
  4. 資源主體

這些遵循此處詳述的標準 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
)


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)

此頁面是否有幫助?