開始使用適用於 Azure 的 GitHub Copilot 來簡化您的開發工作流程,並提升您在 Azure 平臺上的生產力。 本指南會逐步引導您在 Visual Studio Code 中完成 GitHub Copilot for Azure 延伸模組的必要條件和安裝,以便撰寫您的第一個提示。
必要條件
若要完成本文中的步驟,請確定您有:
Azure 帳戶和 Azure 訂用帳戶的存取權。 如需如何設定它們的詳細資訊,請參閱 Azure 帳戶的定價頁面。
GitHub 帳戶和 GitHub Copilot 訂用帳戶。 如需如何設定帳戶的詳細資訊,請參閱 分別在 GitHub 上建立帳戶和 GitHub Copilot 快速入門。
Visual Studio Code。 如需如何下載並安裝的詳細資訊,請參閱 設定Visual Studio Code。
GitHub Copilot 延伸模組和 GitHub Copilot 聊天延伸模組。 如需如何安裝這些延伸模組的指示,請參閱 在 VS Code 中設定 GitHub Copilot 和 開始使用 VS Code 中的 GitHub Copilot 聊天。
重要
GitHub Copilot 不包含在 Visual Studio 訂用帳戶中,而且是由 GitHub 管理的個別訂用帳戶。 如需有關 GitHub Copilot 訂用帳戶和支援的問題,請參閱個人訂用帳戶或商務訂用帳戶。
根據預設,Azure Copilot 可供租用戶中的所有使用者使用。 不過,全域管理員可以管理其組織對 Azure 中 Copilot 的存取權。 您也可以選擇性地將存取權授與特定的 Microsoft Entra 使用者或群組。 如需詳細資訊,請參閱 管理 Microsoft Azure Copilot 的存取權。
安裝 GitHub Copilot for Azure
- 在 Visual Studio Code 中,選取 [ 延伸模組 ] 圖示。
- 在擴充功能市集中,搜尋 GitHub Copilot for Azure。 當 Azure 延伸模組的 GitHub Copilot 出現時,請選取 [ 安裝]。
- 如果系統提示您,請登入您的 Azure 帳戶。
撰寫您的第一個提示
請確定已安裝擴充功能、您已正確驗證,且延伸模組正常運作。
如果 [聊天] 視窗尚未開啟,請確定它已開啟,方法是選取功能表欄中的 [切換聊天] 按鈕,或選取 [切換聊天] 按鈕旁的下拉式清單,然後選取 [開啟聊天] [Ctrl+Alt+I]。
在聊天窗格底部的聊天文字區域中,輸入下列提示:
@azure Do I have any resources currently running?
根據預設,GitHub Copilot 會使用 詢問 模式。 詢問模式會在聊天窗格中提供對您提問的回答。 代理程式 模式可讓 GitHub Copilot 在您的工作區中採取動作。
在詢問模式中,部分 @azure
表示您想要在交談中包含 Azure 聊天參與者。 它會將您的提示範圍限定於特定網域,也就是您的 Azure 帳戶。
您問題的答案取決於您訂用帳戶中目前在 Azure 中執行的內容。
代理模式
從 Visual Studio Code 1.99 版開始,GitHub Copilot 引進 了代理程式模式、可在整個 Visual Studio Code 工作區中執行工作的代理程式體驗、進行編輯、執行終端機命令等等。
GitHub Copilot for Azure 提供 GitHub copilot 的「工具」,透過與 Azure 的深入整合來增強代理程序體驗。
在代理模式中,您不需要指示 GitHub Copilot 使用 @azure
前綴來啟用 GitHub Copilot for Azure。
啟用代理程式模式
您可能需要啟用代理程式模式。
在 Visual Studio Code 中,使用 [管理] 圖示開啟 [設定] (齒輪)。
在 [設定] 的搜尋列中,搜尋
chat.agent.enabled
。勾選 聊天 > 代理程式:已啟用 旁的方塊。
使用代理程式模式
有三種模式:詢問(預設)、編輯和代理程式。 若要使用代理程式模式,您必須在聊天窗格中加以選取。
在聊天窗格中,在聊天提示中,選取模式下拉式清單,然後選擇 [代理程式]。
聊天窗格會確認您目前處於代理程式模式。
若要查看代理程式模式正常運作,請使用下列提示:
What are your tools?
完成回應會顯示 GitHub Copilot 可供 GitHub Copilot 使用之 Azure 特定工具的清單。 回應提供目前可供您使用之功能種類的良好概觀:
I can assist you with various tasks using a range of tools. Here are the main tools I have available: 1. Search and Navigation Semantic search for code or documentation File search using glob patterns Text search (grep) List directory contents Read file contents List code usages/references 2. Code Editing and Analysis Insert edits into files Get errors in code files Test search (find test files) 3. Terminal and Git Operations Run commands in terminal Get terminal output Get Git diffs and changed files 4. Project Creation Create new workspaces Get project setup information Install VS Code extensions Create new Jupyter Notebooks 5. Web and API Tools Fetch webpage content Get VS Code API references 6. Azure Tools Azure development best practices Microsoft Learn documentation Azure resource management Azure authentication tools AI model deployment and management Azure Bicep schemas Service configuration and deployment Azure Developer CLI tools Would you like me to explain any specific tool in more detail or help you with a particular task?
最後一個項目
Azure Developer CLI tools
可以透過以下提示來使用。What is the az command to list all my storage accounts ordered by location?
該提示的完成可能會產生:
I'll help you generate the Azure CLI command to list all your storage accounts ordered by location. Let me use the Azure CLI generator tool to get the correct syntax for this command. To list all your storage accounts ordered by location in Azure, you can use the following Azure CLI command: az storage account list --query "sort_by(@, &location)" This command will: 1. Retrieve all storage accounts you have access to in your Azure subscription 2. Sort the results based on the location (Azure region) of each storage account 3. Display the full details of each storage account in the sorted order If you'd prefer a more concise output focusing on specific fields, you could modify the query. For example, to show only the name and location in a table format: az storage account list --query "sort_by(@, &location)[].[name,location]" -o table Make sure you're logged into the Azure CLI before running this command. If you're not logged in yet, you can do so with az login.
在代理程式模式中啟用和停用工具
您可能想要停用或重新啟用 GitHub Copilot for Azure 所提供的特定工具。
選取聊天窗格中的工具圖示。
使用工具清單旁的複選框來啟用/停用工具(或工具群組)。
在代理程式模式中運作的最佳做法
若要取得更好的代理結果,請考慮下列最佳做法。
出現提示時,請將
copilot-instructions.md
檔案新增至您的工作區。讓你的提示盡可能具體化。 您應該將這類
Generate a Python web application and deploy it to Azure
提示分成幾個提示,每個提示都有較小的責任範圍。允許 GitHub Copilot 執行工作(而不是自行執行)。 有時候,GitHub Copilot 會要求使用 [繼續] 按鈕執行工作的許可權。 雖然您可以在 [聊天] 視窗外執行該工作,但您應該允許 GitHub Copilot 改為執行工作。 這可讓 GitHub Copilot 保留其較大計劃目前狀態的內容。
允許 GitHub Copilot 重複動作。 有時候,GitHub Copilot 會要求重複執行工作的許可權。 這麼做可進一步了解項目檔的狀態,以及下一步應該執行的動作。 您應該允許 GitHub Copilot 重複其需要執行的工作。
表達您的喜好。 如果 GitHub Copilot 想要執行動作,但您想要採取 不同的 動作,您可以指示它執行您慣用的方式。 例如,如果某程式想要建立一個名為
\.azure
的資料夾來存放 bicep 檔案,您可以介入並要求它使用不同的資料夾,提示內容可以是:Instead of naming the folder `.azure`, please name it `infra`
選擇性:設定預設租使用者
如果您有多個 Microsoft Entra ID 租使用者,您可以使用下列提示來設定預設租使用者:
@azure /changeTenant
從頂端中央的下拉式清單中選取您的可用租戶。
您也可以在擴充功能設定中設定預設租使用者:
在 Visual Studio Code 的 [活動列] 上,選取 [ 擴充功能]。 然後向下卷動至 適用於 Azure 的 GitHub Copilot。
選取延伸模組條目角落的齒輪圖示,然後從快顯功能表選取 設定。
在 [ 設定] 索引標籤上,將 Azure Resource Graph 租使用者設定為Microsoft Entra 租使用者識別碼。 您可以在 Azure 入口網站 中找到Microsoft Entra 租使用者標識碼。
相關內容
- 了解什麼是適用於 Azure 的 GitHub Copilot 及其運作方式。
- 按照快速入門指南,瞭解如何在軟體開發工作流程中包含 GitHub Copilot for Azure。 本快速入門說明如何將服務部署至 Azure、監視其狀態,以及疑難解答問題。
- 請參閱範例提示以 深入瞭解 Azure 並瞭解您的 Azure 帳戶、訂用帳戶和資源。
- 請參閱設計 及開發 Azure 應用程式的範例提示。
- 請參閱將應用程式部署至 Azure 的範例提示。
- 請參閱在 Azure 中優化應用程式的範例提示。
- 請參閱針對 Azure 資源進行疑難解答的範例提示。