

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# SageMaker 筆記本環境中的生成式 AI
<a name="jupyterai"></a>

[Jupyter AI](https://github.com/jupyterlab/jupyter-ai) 是 JupyterLab 的開放原始碼延伸模組，將生成式 AI 功能整合至 Jupyter 筆記本。透過 Jupyter AI 聊天介面和魔術命令，使用者可實驗從自然語言指示產生的程式碼、解釋現有程式碼、詢問有關其本機檔案的問題、產生整個筆記本等。延伸模組會將 Jupyter 筆記本與大型語言模型 (LLM) 連線，使用者可以用來產生文字、程式碼或影像，以及詢問有關其自己資料的問題。Jupyter AI 支援生成式模型提供者，例如 AI21、Anthropic、 AWS (JumpStart 和 Amazon Bedrock)、Cohere 和 OpenAI。

您也可以使用 Amazon Q Developer 做為開箱可用的解決方案。您可以使用 Amazon Q Developer 搭配最少的組態開始，而不必手動設定模型的連線。當您啟用 Amazon Q Developer 時，它會成為 Jupyter AI 內的預設解決方案提供者。如需使用 Amazon Q Developer 的詳細資訊，請參閱 [SageMaker JupyterLab](studio-updated-jl.md)。

延伸模組的套件包含在 [Amazon SageMaker Distribution](https://github.com/aws/sagemaker-distribution) [1.2 版及更新版本](https://github.com/aws/sagemaker-distribution/tree/main/build_artifacts/v1)中。Amazon SageMaker Distribution 是適用於資料科學和科學運算的 Docker 環境，用作 JupyterLab 筆記本執行個體的預設映像。不同 IPython 環境的使用者可以手動安裝 Jupyter AI。

在本節中，我們提供 Jupyter AI 功能的概觀，並示範如何從 [JupyterLab](https://docs.aws.amazon.com/sagemaker/latest/dg/studio-updated-jl.html) 或 [Studio Classic](https://docs.aws.amazon.com/sagemaker/latest/dg/studio.html) 筆記本設定 JumpStart 或 Amazon Bedrock 提供的模型。如需 Jupyter AI 專案的深入資訊，請參閱其[文件](https://jupyter-ai.readthedocs.io/en/latest/)。或者，您可以參考部落格文章 *[Jupyter 中的生成式 AI](https://blog.jupyter.org/generative-ai-in-jupyter-3f7174824862)*，以取得重要 Jupyter AI 功能的概觀和範例。

在使用 Jupyter AI 並與 LLM 互動之前，請確定您滿足下列先決條件：
+ 對於 託管的模型 AWS，您應該擁有 SageMaker AI 端點的 ARN 或可存取 Amazon Bedrock。對於其他模型提供者，您應該具有 API 金鑰，用來驗證和授權對模型的請求。Jupyter AI 支援廣泛的模型提供者和語言模型。請參閱其[支援的模型](https://jupyter-ai.readthedocs.io/en/latest/users/index.html#model-providers)清單，以隨時掌握最新的可用模型。如需有關如何在 JumpStart 中部署模型的資訊，請參閱 JumpStart 文件中的[部署模型](https://docs.aws.amazon.com/sagemaker/latest/dg/jumpstart-deploy.html)。您需要請求存取 [Amazon Bedrock](https://aws.amazon.com/bedrock/)，以將其用作模型提供者。
+ 確定 Jupyter AI 程式庫存在於您的環境中。如果沒有，請遵循 [Jupyter AI 安裝](sagemaker-jupyterai-installation.md)中的指示安裝所需的套件。
+ 在[存取 Jupyter AI 功能](sagemaker-jupyterai-overview.md)中熟悉 Jupyter AI 的功能。
+ 遵循[設定您的模型提供者](sagemaker-jupyterai-model-configuration.md)中的指示，設定您想要使用的目標模型。

完成先決條件步驟後，您可以繼續[在 JupyterLab 或 Studio Classic 中使用 Jupyter AI](sagemaker-jupyterai-use.md)。

**Topics**
+ [Jupyter AI 安裝](sagemaker-jupyterai-installation.md)
+ [存取 Jupyter AI 功能](sagemaker-jupyterai-overview.md)
+ [設定您的模型提供者](sagemaker-jupyterai-model-configuration.md)
+ [在 JupyterLab 或 Studio Classic 中使用 Jupyter AI](sagemaker-jupyterai-use.md)

# Jupyter AI 安裝
<a name="sagemaker-jupyterai-installation"></a>

若要使用 Jupyter AI，您必須先安裝 Jupyter AI 套件。對於 [Amazon SageMaker AI Distribution](https://github.com/aws/sagemaker-distribution/tree/main/build_artifacts/v1) 使用者，我們建議您選取 SageMaker Distribution 映像 1.2 版或更新版本。不需要進一步安裝。Studio 中的 JupyterLab 使用者可以在建立空間時選擇其 Amazon SageMaker Distribution 的版本。

對於其他 IPython 環境的使用者，建議的 Jupyter AI 套件版本取決於他們正在使用的 JupyterLab 版本。

Jupyter AI Distribution 包含兩個套件。
+ `jupyter_ai`：此套件提供 JupyterLab 延伸模組和原生聊天使用者介面 (UI)。它使用您選擇的大型語言模型做為對話助理。
+ `jupyter_ai_magics`：此套件提供 IPython `%%ai` 和 `%ai` 魔術命令，您可以使用這些命令，從筆記本儲存格調用大型語言模型 (LLM)。

**注意**  
安裝 `jupyter_ai` 也會安裝 `jupyter_ai_magics`。不過，您可以在沒有 JupyterLab 或 `jupyter_ai` 的情況下獨立安裝 `jupyter_ai_magics`。魔術命令 `%%ai` 和 `%ai` 可在任何 IPython 核心環境中運作。如果您只安裝 `jupyter_ai_magics`，則無法使用聊天 UI。

對於 JupyterLab 3 的使用者，特別是 Studio Classic 使用者，我們建議您安裝 `jupyter-ai` [1.5.x 版](https://pypi.org/project/jupyter-ai/#history)或任何更新的 1.x 版。不過，我們強烈建議搭配 JupyterLab 4 使用 Jupyter AI。與 JupyterLab 3 相容的 `jupyter-ai` 版本可能不允許使用者設定其他模型參數，例如溫度、top-k 和 top-p 取樣、字符數上限或長度上限，或使用者接受授權合約。

對於不使用 SageMaker Distribution 的 JupyterLab 4 環境使用者，我們建議安裝 `jupyter-ai` [2.5.x 版](https://pypi.org/project/jupyter-ai/#history)或任何更新的 2.x 版。

請參閱 [Jupyter AI 文件](https://jupyter-ai.readthedocs.io/en/latest/users/index.html#installation-via-pip)的*安裝*一節中的指示。

# 存取 Jupyter AI 功能
<a name="sagemaker-jupyterai-overview"></a>

您可以透過兩種不同的方法存取 Jupyter AI 功能：使用聊天 UI 或在筆記本內使用魔術命令。

## 從聊天使用者介面 AI 助理
<a name="sagemaker-jupyterai-overview-chatui"></a>

聊天介面會將您與 Jupyternaut 連線，Jupyternaut 是使用您選擇的語言模型的對話代理程式。

在啟動與 Jupyter AI 一起安裝的 JupyterLab 應用程式之後，您可以選擇左側導覽面板中的聊天圖示 (![\[Icon of a rectangular shape with a curved arrow pointing to the upper right corner.\]](http://docs.aws.amazon.com/zh_tw/sagemaker/latest/dg/images/studio/icons/jupyterai/jupyterai-chat-ui.png)) 來存取聊天介面。系統會提示第一次使用者設定其模型。如需組態指示，請參閱[在聊天 UI 中設定模型提供者](sagemaker-jupyterai-model-configuration.md#sagemaker-jupyterai-model-configuration-chatui)：

**使用聊天 UI，您可以：**
+ **回答問題**：例如，您可以要求 Jupyternaut 建立 Python 函數，將 CSV 檔案新增至 Amazon S3 儲存貯體。之後，您可以使用後續問題來精簡您的答案，例如將參數新增至函數，以選擇檔案寫入的路徑。
+ **與 JupyterLab 中的檔案互動**：您可以透過選取筆記本的一部分，將其包含在提示中。然後，您可以將其取代為模型建議的答案，或手動將答案複製到剪貼簿。
+ 從提示**產生整個筆記本**：透過使用 `/generate` 啟動您的提示，您可以在背景觸發筆記本產生程序，而不會中斷您使用 Jupyternaut。程序完成後，會顯示一則訊息，其中包含新檔案的連結。
+ **從本機檔案學習並詢問有關本機檔案的問題**：使用 `/learn` 命令，您可以教導您選擇的嵌入模型有關本機檔案的一切，然後使用 `/ask` 命令詢問有關這些檔案的問題。Jupyter AI 會將內嵌內容存放在本機 [FAISS 向量資料庫](https://github.com/facebookresearch/faiss)中，然後使用檢索增強生成 (RAG) 根據其所學提供答案。若要清除您先前從嵌入模型中學到的所有資訊，請使用`/learn -d`。

**注意**  
Amazon Q Developer 無法從頭開始產生筆記本。

如需功能的完整清單及其使用方式的詳細指示，請參閱 [Jupyter AI 聊天介面](https://jupyter-ai.readthedocs.io/en/latest/users/index.html#the-chat-interface)文件。若要了解如何在 Jupyternaut 中設定對模型的存取，請參閱[在聊天 UI 中設定模型提供者](sagemaker-jupyterai-model-configuration.md#sagemaker-jupyterai-model-configuration-chatui)。

## 從筆記本儲存格
<a name="sagemaker-jupyterai-overview-magic-commands"></a>

使用 `%%ai` 和 `%ai` 魔術命令，您可以從筆記本儲存格或任何 IPython 命令列介面與您選擇的語言模型互動。`%%ai` 命令會將您的指示套用至整個儲存格，而 `%ai` 則會將其套用至特定行。

下列範例說明 `%%ai` 魔術命令，其會調用 Anthropic Claude 模型來輸出 HTML 檔案，其中包含帶有黑色邊框的白色方塊影像。

```
%%ai anthropic:claude-v1.2 -f html
Create a square using SVG with a black border and white fill.
```

若要了解每個命令的語法，請使用 `%ai help`。若要列出延伸模組支援的提供者和模型，請執行 `%ai list`。

如需功能的完整清單及其使用方式的詳細指示，請參閱 Jupyter AI [魔術命令](https://jupyter-ai.readthedocs.io/en/latest/users/index.html#the-ai-and-ai-magic-commands)文件。尤其，您可以使用 `-f` 或 `--format` 參數自訂模型的輸出格式、在提示中允許變數插補，包括特殊 `In` 和 `Out` 變數等。

若要了解如何設定對模型的存取，請參閱[在筆記本中設定您的模型提供者](sagemaker-jupyterai-model-configuration.md#sagemaker-jupyterai-model-configuration-magic-commands)。

# 設定您的模型提供者
<a name="sagemaker-jupyterai-model-configuration"></a>

**注意**  
在本節中，我們假設已部署您計劃使用的語言和嵌入模型。對於 提供的模型 AWS，您應該已經擁有 SageMaker AI 端點的 ARN 或對 Amazon Bedrock 的存取權。對於其他模型提供者，您應該具有 API 金鑰，用來驗證和授權對模型的請求。  
Jupyter AI 支援廣泛的模型提供者和語言模型。請參閱其[支援的模型](https://jupyter-ai.readthedocs.io/en/latest/users/index.html#model-providers)清單，以隨時掌握最新的可用模型。如需如何部署 JumpStart 所提供模型的相關資訊，請參閱 JumpStart 文件中的[部署模型](https://docs.aws.amazon.com/sagemaker/latest/dg/jumpstart-deploy.html)。您需要請求存取 [Amazon Bedrock](https://aws.amazon.com/bedrock/)，以將其用作模型提供者。

Jupyter AI 的組態會有所不同，取決於您使用的是聊天 UI 還是魔術命令。

## 在聊天 UI 中設定模型提供者
<a name="sagemaker-jupyterai-model-configuration-chatui"></a>

**注意**  
您可以遵循相同指示來設定數個 LLM 和嵌入模型。不過，您必須設定至少一個**語言模型**。

**設定聊天 UI**

1. 在 JupyterLab 中，選擇左側導覽面板中的聊天圖示 (![\[Icon of a rectangular shape with a curved arrow pointing to the upper right corner.\]](http://docs.aws.amazon.com/zh_tw/sagemaker/latest/dg/images/studio/icons/jupyterai/jupyterai-chat-ui.png)) 來存取聊天介面。

1. 選擇左窗格右上角的組態圖示 (![\[Gear or cog icon representing settings or configuration options.\]](http://docs.aws.amazon.com/zh_tw/sagemaker/latest/dg/images/studio/icons/jupyterai/jupyterai-configure-models.png))。這會開啟 Jupyter AI 組態面板。

1. 填寫與服務提供者相關的欄位。
   + **對於 JumpStart 或 Amazon Bedrock 提供的模型**
     + 在**語言模型**下拉式清單中，針對使用 JumpStart 部署的模型選取 `sagemaker-endpoint`，或針對 Amazon Bedrock 管理的模型選取 `bedrock`。
     + 這些參數會根據您的模型部署在 SageMaker AI 還是 Amazon Bedrock 上而有所不同。
       + 對於使用 JumpStart 部署的模型：
         + 在端點名稱中輸入**端點的名稱**，然後在[**區域名稱**](sagemaker-jupyterai-use.md#sagemaker-jupyterai-region-name)中部署模型 AWS 區域 的 。若要擷取 SageMaker AI 端點的 ARN，請導覽至 [https://console.aws.amazon.com/sagemaker/](https://console.aws.amazon.com/sagemaker/)，然後在左側功能表中選擇**推論**和**端點**。
         + 貼上為您模型量身打造之[**請求結構描述**](sagemaker-jupyterai-use.md#sagemaker-jupyterai-request-schema)的 JSON，以及用於剖析模型輸出的對應[**回應路徑**](sagemaker-jupyterai-use.md#sagemaker-jupyterai-response-path)。
**注意**  
您可以在下列[範例筆記本](https://github.com/aws/amazon-sagemaker-examples/tree/main/introduction_to_amazon_algorithms/jumpstart-foundation-models)中找到各種 JumpStart 基礎模型的請求和回應格式。每個筆記本都以其示範的模型命名。
       + 對於由 Amazon Bedrock 管理的模型：新增將登入資料儲存在 AWS 系統中的 AWS 設定檔 （選用），然後在 AWS 區域 [**區域中**](sagemaker-jupyterai-use.md#sagemaker-jupyterai-region-name)部署模型的 。
     + (選用) 選取您有權存取的[嵌入模型](sagemaker-jupyterai-overview.md#sagemaker-jupyterai-embedding-model)。嵌入模型用來從本機文件中擷取其他資訊，讓文字產生模型能夠在這些文件的內容中回應問題。
     + 選擇**儲存變更**，然後導覽至左窗格左上角的向左箭頭圖示 (![\[Left-pointing arrow icon, typically used for navigation or returning to a previous page.\]](http://docs.aws.amazon.com/zh_tw/sagemaker/latest/dg/images/studio/icons/jupyterai/jupyterai-return-to-chat.png))。這會開啟 Jupyter AI 聊天 UI。您可以開始與模型互動。
   + **針對第三方提供者託管的模型**
     + 在**語言模型**下拉式清單中，選取您的提供者 ID。您可以在 Jupyter AI [模型提供者清單](https://jupyter-ai.readthedocs.io/en/latest/users/index.html#model-providers)中尋找每個提供者的詳細資訊，包括其 ID。
     + (選用) 選取您有權存取的[嵌入模型](sagemaker-jupyterai-overview.md#sagemaker-jupyterai-embedding-model)。嵌入模型用來從本機文件中擷取其他資訊，讓文字產生模型能夠在這些文件的內容中回應問題。
     + 插入模型的 API 金鑰。
     + 選擇**儲存變更**，然後導覽至左窗格左上角的向左箭頭圖示 (![\[Left-pointing arrow icon, typically used for navigation or returning to a previous page.\]](http://docs.aws.amazon.com/zh_tw/sagemaker/latest/dg/images/studio/icons/jupyterai/jupyterai-return-to-chat.png))。這會開啟 Jupyter AI 聊天 UI。您可以開始與模型互動。

下列快照是聊天 UI 組態面板的圖例，此面板設定為調用 JumpStart 提供並部署在 SageMaker AI 中的 Flan-t5-small 模型。

![\[聊天 UI 組態面板設定為調用 JumpStart 提供的 Flan-t5-small 模型。\]](http://docs.aws.amazon.com/zh_tw/sagemaker/latest/dg/images/studio/jupyterai/jupyterai-chatui-configuration.png)


### 將額外的模型參數和自訂參數傳遞至您的請求
<a name="sagemaker-jupyterai-configuration-model-parameters"></a>

您的模型可能需要額外參數，例如用於使用者合約核准或調整其他模型參數 (例如溫度或回應長度) 的自訂屬性。我們建議您使用生命週期組態，設定這些設定做為 JupyterLab 應用程式的啟動選項。如需如何建立生命週期組態並將其連接至網域，或從 [SageMaker AI 主控台](https://console.aws.amazon.com/sagemaker/)連接至使用者設定檔的相關資訊，請參閱[建立並關聯生命週期組態](https://docs.aws.amazon.com/sagemaker/latest/dg/studio-lcc.html)。您可以在為 JupyterLab 應用程式建立空間時選擇 LCC 指令碼。

使用下列 JSON 結構描述來設定您的[額外參數](sagemaker-jupyterai-use.md#sagemaker-jupyterai-extra-model-params)：

```
{
  "AiExtension": {
    "model_parameters": {
      "<provider_id>:<model_id>": { Dictionary of model parameters which is unpacked and passed as-is to the provider.}
      }
    }
  }
}
```

下列指令碼是 JSON 組態檔案的範例，您可以在建立 JupyterLab 應用程式 LCC 時用來設定部署在 Amazon Bedrock 上的 [AI21 Labs Jurassic-2 模型](https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-jurassic2.html)的長度上限。增加模型產生的回應長度可防止模型回應的系統性截斷。

```
#!/bin/bash
set -eux

mkdir -p /home/sagemaker-user/.jupyter

json='{"AiExtension": {"model_parameters": {"bedrock:ai21.j2-mid-v1": {"model_kwargs": {"maxTokens": 200}}}}}'
# equivalent to %%ai bedrock:ai21.j2-mid-v1 -m {"model_kwargs":{"maxTokens":200}}

# File path
file_path="/home/sagemaker-user/.jupyter/jupyter_jupyter_ai_config.json"

#jupyter --paths

# Write JSON to file
echo "$json" > "$file_path"

# Confirmation message
echo "JSON written to $file_path"

restart-jupyter-server

# Waiting for 30 seconds to make sure the Jupyter Server is up and running
sleep 30
```

下列指令碼是用於建立 JupyterLab 應用程式 LCC 的 JSON 組態檔案範例，用來為部署在 Amazon Bedrock 上的 [Anthropic Claude 模型](https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-claude.html)設定其他模型參數。

```
#!/bin/bash
set -eux

mkdir -p /home/sagemaker-user/.jupyter

json='{"AiExtension": {"model_parameters": {"bedrock:anthropic.claude-v2":{"model_kwargs":{"temperature":0.1,"top_p":0.5,"top_k":25
0,"max_tokens_to_sample":2}}}}}'
# equivalent to %%ai bedrock:anthropic.claude-v2 -m {"model_kwargs":{"temperature":0.1,"top_p":0.5,"top_k":250,"max_tokens_to_sample":2000}}

# File path
file_path="/home/sagemaker-user/.jupyter/jupyter_jupyter_ai_config.json"

#jupyter --paths

# Write JSON to file
echo "$json" > "$file_path"

# Confirmation message
echo "JSON written to $file_path"

restart-jupyter-server

# Waiting for 30 seconds to make sure the Jupyter Server is up and running
sleep 30
```

一旦已將您的 LCC 連接至您的網域或使用者設定檔，請在啟動您的 JupyterLab 應用程式時將您的 LCC 新增至您的空間。若要確保 LCC 已更新您的組態檔案，請在終端機中執行 `more ~/.jupyter/jupyter_jupyter_ai_config.json`。檔案的內容應該對應至傳遞至 LCC 的 JSON 檔案內容。

## 在筆記本中設定您的模型提供者
<a name="sagemaker-jupyterai-model-configuration-magic-commands"></a>

**使用 `%%ai` 和 `%ai` 魔術命令，在 JupyterLab 或 Studio Classic 筆記本內透過 Jupyter AI 調用模型**

1. 在筆記本環境中安裝模型提供者特有的用戶端程式庫。例如，使用 OpenAI 模型時，您需要安裝 `openai` 用戶端程式庫。您可以在 Jupyter AI [模型提供者清單](https://jupyter-ai.readthedocs.io/en/latest/users/index.html#model-providers)的 *Python 套件*欄中尋找每個提供者所需的用戶端程式庫清單。
**注意**  
對於 託管的模型 AWS， `boto3` 已安裝在 JupyterLab 所使用的 SageMaker AI 分佈映像中，或與 Studio Classic 搭配使用的任何資料科學映像中。

1. 
   + **對於 託管的模型 AWS**

     確定您的執行角色具有為 JumpStart 提供的模型調用 SageMaker AI 端點的許可，或者您可以存取 Amazon Bedrock。
   + **針對第三方提供者託管的模型**

     使用環境變數在筆記本環境中匯出提供者的 API 金鑰。您可以使用下列魔術命令。將命令中的 `provider_API_key` 取代為您的提供者的 Jupyter AI [模型提供者清單](https://jupyter-ai.readthedocs.io/en/latest/users/index.html#model-providers)的*環境變數*欄中找到的環境變數。

     ```
     %env provider_API_key=your_API_key
     ```

# 在 JupyterLab 或 Studio Classic 中使用 Jupyter AI
<a name="sagemaker-jupyterai-use"></a>

您可以在 JupyterLab 或 Studio Classic 中使用 Jupyter AI，方法是從聊天 UI 或筆記本儲存格調用語言模型。下列各節提供完成此作業所需步驟的相關資訊。

## 從聊天 UI 使用語言模型
<a name="sagemaker-jupyterai-use-chatui"></a>

在聊天 UI 文字方塊中編寫您的訊息，以開始與您的模型互動。若要清除訊息歷程記錄，請使用 `/clear` 命令。

**注意**  
清除訊息歷程記錄不會消除與模型提供者的聊天內容。

## 從筆記本儲存格使用語言模型
<a name="sagemaker-jupyterai-use-magic-commands"></a>

使用 `%%ai` 和 `%ai` 命令調用語言模型之前，請在 JupyterLab 或 Studio Classic 筆記本儲存格中執行下列命令來載入 IPython 延伸模組。

```
%load_ext jupyter_ai_magics
```
+ **對於 託管的模型 AWS：**
  + 若要調用 SageMaker AI 中部署的模型，請使用下列必要參數將字串 `sagemaker-endpoint:endpoint-name` 傳遞至 `%%ai` 魔術命令，然後在下列幾行中新增您的提示。

    下表列出調用 SageMaker AI 或 Amazon Bedrock 託管的模型時的必要和選用參數。<a name="sagemaker-jupyterai-jumpstart-inference-params"></a>    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/sagemaker/latest/dg/sagemaker-jupyterai-use.html)

    下列命令會調用 SageMaker AI 託管的 [Llama2-7b](https://sagemaker.readthedocs.io/en/stable/doc_utils/pretrainedmodels.html) 模型。

    ```
    %%ai sagemaker-endpoint:jumpstart-dft-meta-textgeneration-llama-2-7b -q {"inputs":"<prompt>","parameters":{"max_new_tokens":64,"top_p":0.9,"temperature":0.6,"return_full_text":false}} -n us-east-2 -p [0].generation -m {"endpoint_kwargs":{"CustomAttributes":"accept_eula=true"}} -f text
    Translate English to French:
    sea otter => loutre de mer
    peppermint => menthe poivrée
    plush girafe => girafe peluche
    cheese =>
    ```

    下列範例會調用 SageMaker AI 託管的 Flan-t5-small 模型。

    ```
    %%ai sagemaker-endpoint:hf-text2text-flan-t5-small --request-schema={"inputs":"<prompt>","parameters":{"num_return_sequences":4}} --region-name=us-west-2 --response-path=[0]["generated_text"] -f text
    What is the atomic number of Hydrogen?
    ```
  + 若要調用 Amazon Bedrock 中部署的模型，請透過[用於調用 JumpStart 或 Amazon Bedrock 託管模型的參數](#sagemaker-jupyterai-jumpstart-inference-params)清單中定義的任何選用參數，將字串 `bedrock:model-name` 傳遞至 `%%ai` 魔術命令，然後在下列幾行中新增您的提示。

    下列範例會調用 Amazon Bedrock 託管的 [AI21 Labs Jurassic-2 模型](https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-jurassic2.html)。

    ```
    %%ai bedrock:ai21.j2-mid-v1 -m {"model_kwargs":{"maxTokens":256}} -f code
    Write a function in python implementing a bubbble sort.
    ```
+ **針對第三方提供者託管的模型**

  若要調用第三方供應商託管的模型，請使用選用的 [`Output format`](#sagemaker-jupyterai-output-format-params) 將字串 `provider-id:model-name` 傳遞至 `%%ai` 魔術命令，然後在下列幾行中新增您的提示。您可以在 Jupyter AI [模型提供者清單](https://jupyter-ai.readthedocs.io/en/latest/users/index.html#model-providers)中尋找每個提供者的詳細資訊，包括其 ID。

  下列命令會要求 Anthropic Claude 模型輸出 HTML 檔案，其中包含帶有黑色邊框的白色方塊影像。

  ```
  %%ai anthropic:claude-v1.2 -f html
  Create a square using SVG with a black border and white fill.
  ```