在 Gemini 的协助下解释代码单元格
本文档介绍了如何使用 Gemini in Colab Enterprise(Gemini for Google Cloud 产品组合中的一款产品)帮助您说明 Colab Enterprise 笔记本中的代码单元。
了解 Gemini for Google Cloud 如何以及何时使用您的数据。
本文档适用于使用 Colab Enterprise 的数据分析师、数据科学家和数据开发者。本文档假定您了解如何在笔记本环境中编写代码。
概览
Gemini in Colab Enterprise 可帮助您说明 Colab Enterprise 笔记本中的代码单元。如果您正在使用他人的笔记本,并想快速了解代码的作用,则可能需要执行此操作。或者,在很长时间没有使用笔记本后,您可能需要提醒自己笔记本的某些部分是如何运作的。
在获得代码单元的说明后,您可以浏览任何包含的代码段并查看来源。您还可以使用解释代码对话框讨论代码并提出后续问题。 如需了解详情,请参阅说明代码单元。
准备工作
- 确保已为您的 Google Cloud 用户账号和项目设置了 Colab Enterprise 中的 Gemini。
- 登录您的 Google Cloud 账号。如果您是 Google Cloud新手,请 创建一个账号来评估我们的产品在实际场景中的表现。新客户还可获享 $300 赠金,用于运行、测试和部署工作负载。
Enable the Vertex AI, Gemini for Google Cloud, Dataform, and Compute Engine APIs.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.Enable the Vertex AI, Gemini for Google Cloud, Dataform, and Compute Engine APIs.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.
所需的角色
如需获得在 Colab Enterprise 中使用 Gemini 所需的权限,请让您的管理员为您授予项目的以下 IAM 角色:
- Colab Enterprise User (
roles/aiplatform.colabEnterpriseUser) - Gemini for Google Cloud User (
roles/cloudaicompanion.user)
如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限。
解释代码单元格
如需使用 Gemini 解释 Google Cloud的代码单元,请执行以下操作:
-
在 Google Cloud 控制台中,前往 Colab Enterprise 我的笔记本页面。
-
在区域菜单中,选择包含笔记本的区域。
-
点击您要打开的笔记本。
-
在笔记本中,点击包含代码的代码单元。
-
点击 可用的 AI 功能,然后点击代码说明。
如果您尚未授权数据科学智能体,Colab Enterprise 会在向数据科学智能体验证您的 Google 账号时显示一个简短的对话框。
-
系统随即会显示一个说明代码对话框,其中包含代码的说明。
仔细阅读说明,浏览示例代码段,并查看来源。使用此对话框讨论代码并提出后续问题。
-
如需关闭解释代码对话框,请点击 关闭。
停用 Gemini in Colab Enterprise
如需针对某个 Google Cloud 项目停用 Colab Enterprise 中的 Gemini,管理员必须停用 Gemini for Google Cloud API。请参阅停用服务。
如需为特定用户停用 Colab Enterprise 中的 Gemini,管理员需要撤消该用户的 Gemini for Google Cloud User (roles/cloudaicompanion.user) 角色。请参阅撤消单个 IAM 角色。
后续步骤
如需了解在 Gemini 的协助下编写和修改代码的更多方法,请参阅以下内容: