跳至主要內容

YandexGPT

本筆記本說明如何將 Langchain 與 YandexGPT 嵌入模型搭配使用。

要使用,您應該安裝 yandexcloud Python 套件。

%pip install --upgrade --quiet  yandexcloud

首先,您應該建立具有 ai.languageModels.user 角色的服務帳戶

接下來,您有兩個驗證選項

  • IAM 權杖。 您可以在建構子參數 iam_token 中或在環境變數 YC_IAM_TOKEN 中指定權杖。
  • API 金鑰 您可以在建構子參數 api_key 中或在環境變數 YC_API_KEY 中指定金鑰。

要指定模型,您可以使用 model_uri 參數,請參閱文件以取得更多詳細資訊。

預設情況下,會從參數 folder_idYC_FOLDER_ID 環境變數中指定的資料夾中使用 text-search-query 的最新版本。

from langchain_community.embeddings.yandex import YandexGPTEmbeddings
API 參考:YandexGPTEmbeddings
embeddings = YandexGPTEmbeddings()
text = "This is a test document."
query_result = embeddings.embed_query(text)
doc_result = embeddings.embed_documents([text])
query_result[:5]
[-0.021392822265625,
0.096435546875,
-0.046966552734375,
-0.0183258056640625,
-0.00555419921875]
doc_result[0][:5]
[-0.021392822265625,
0.096435546875,
-0.046966552734375,
-0.0183258056640625,
-0.00555419921875]

此頁面有幫助嗎?