View a markdown version of this page

ListAgentKnowledgeBases 搭配 AWSSDK 使用 - Amazon Bedrock

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

ListAgentKnowledgeBases 搭配 AWSSDK 使用

以下程式碼範例顯示如何使用 ListAgentKnowledgeBases

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

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

GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

列出與代理程式相關聯的知識庫。

def list_agent_knowledge_bases(self, agent_id, agent_version): """ List the knowledge bases associated with a version of an Amazon Bedrock Agent. :param agent_id: The unique identifier of the agent. :param agent_version: The version of the agent. :return: The list of knowledge base summaries for the version of the agent. """ try: knowledge_bases = [] paginator = self.client.get_paginator("list_agent_knowledge_bases") for page in paginator.paginate( agentId=agent_id, agentVersion=agent_version, PaginationConfig={"PageSize": 10}, ): knowledge_bases.extend(page["agentKnowledgeBaseSummaries"]) except ClientError as e: logger.error(f"Couldn't list knowledge bases. {e}") raise else: return knowledge_bases

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