搭DeleteAgent配 AWS 開發套件或 CLI 使用 - Amazon Bedrock

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

DeleteAgent配 AWS 開發套件或 CLI 使用

下列程式碼範例會示範如何使用DeleteAgent

動作範例是大型程式的程式碼摘錄,必須在內容中執行。您可以在下列程式碼範例的內容中看到此動作:

JavaScript
適用於 JavaScript (v3) 的開發套件
注意

還有更多關於 GitHub。尋找完整範例,並了解如何在AWS 設定和執行程式碼範例儲存庫

刪除代理程式。

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import { fileURLToPath } from "url"; import { checkForPlaceholders } from "../lib/utils.js"; import { BedrockAgentClient, DeleteAgentCommand, } from "@aws-sdk/client-bedrock-agent"; /** * Deletes an Amazon Bedrock Agent. * * @param {string} agentId - The unique identifier of the agent to delete. * @param {string} [region='us-east-1'] - The AWS region in use. * @returns {Promise<import("@aws-sdk/client-bedrock-agent").DeleteAgentCommandOutput>} An object containing the agent id, the status, and some additional metadata. */ export const deleteAgent = (agentId, region = "us-east-1") => { const client = new BedrockAgentClient({ region }); const command = new DeleteAgentCommand({ agentId }); return client.send(command); }; // Invoke main function if this file was run directly. if (process.argv[1] === fileURLToPath(import.meta.url)) { // Replace the placeholders for agentId with an existing agent's id. // Ensure to remove the brackets (`[]`) before adding your data. // The agentId must be an alphanumeric string with exactly 10 characters. const agentId = "[ABC123DE45]"; // Check for unresolved placeholders in agentId. checkForPlaceholders([agentId]); console.log(`Deleting agent with ID ${agentId}...`); const response = await deleteAgent(agentId); console.log(response); }
  • 如需 API 詳細資訊,請參閱 AWS SDK for JavaScript API 參考DeleteAgent中的。

Python
適用於 Python (Boto3) 的 SDK
注意

還有更多關於 GitHub。尋找完整範例,並了解如何在AWS 設定和執行程式碼範例儲存庫

刪除代理程式。

def delete_agent(self, agent_id): """ Deletes an Amazon Bedrock agent. :param agent_id: The unique identifier of the agent to delete. :return: The response from Agents for Bedrock if successful, otherwise raises an exception. """ try: response = self.client.delete_agent( agentId=agent_id, skipResourceInUseCheck=False ) except ClientError as e: logger.error(f"Couldn't delete agent. {e}") raise else: return response
  • 如需 API 的詳細資訊,請參閱AWS 開發套件DeleteAgent中的 Python (博托 3) API 參考。

如需 AWS SDK 開發人員指南和程式碼範例的完整清單,請參閱搭配 AWS SDK 使用此服務。此主題也包含有關入門的資訊和舊版 SDK 的詳細資訊。