提示範例

本文提供 Visual Studio Code 中聊天功能在不同情境與代理程式下的提示範例。您可以使用這些範例作為靈感,為自己的開發任務撰寫有效的提示。

如果您是 VS Code 聊天功能的新手,請進一步了解 開始使用聊天功能,或檢閱 撰寫提示的最佳實踐

一般編碼與技術問題

使用「詢問」代理程式來快速取得有關編碼概念、技術主題和一般程式設計問題的答案。

What is a linked list?
Provide 3 ways to implement a search feature in React.
Explain the difference between async/await and promises.

了解與探索您的程式碼庫

搭配使用「詢問」代理程式與 #codebase,以了解專案的運作方式、找到特定功能,或探索程式碼關聯。

Explain how authentication works in #codebase
Where is the database connection string configured? #codebase
How do I build this #codebase?
Which testing framework is used for #calculator.test.js?

程式碼生成與編輯

使用「代理程式」進行多檔案建立,並使用「行內聊天」(⌘I (Windows、Linux Ctrl+I))進行目標明確的即時編輯。

Add a login button and style it based on #styles.css
Create a meal-planning web app using React and Node.js
Refactor this code to use async/await

測試與品質保證

使用「代理程式」來生成測試或修正失敗的測試。

Add unit tests for the user service.
Fix the failing tests #testFailure

偵錯與修正問題

使用「代理程式」修正跨檔案的問題,或先使用「詢問」來了解根本原因。

Fix the issues in #problems
Why is this function returning undefined?

使用原始碼控制

使用聊天功能處理您待處理的變更並生成發布文件。

Summarize the #changes
Generate release notes based on the #changes

使用外部資源

使用 #fetch 引用網路內容,或使用 GitHub MCP 伺服器在公共 GitHub 儲存庫中搜尋程式碼範例。

How do I use the 'useState' hook in react 18? #fetch https://18.react.com.tw/reference/react/useState#usage
Build an API endpoint to fetch address info, use the template from GitHub repo contoso/api-templates
What are the top #extensions for this workspace?

終端機與命令列任務

使用 終端機行內聊天 來取得關於 Shell 指令與終端機操作的協助。

How do I install npm packages?
List the top 5 largest files in the src directory
undo the last git commit

使用 Jupyter Notebook

使用「代理程式」來建立、編輯和處理 Jupyter Notebook。

/newNotebook use pandas and seaborn to read and visualize the titanic dataset. Show key information from the dataset.
Create a notebook to read data from #housing.csv and plot the distribution of prices
Make sure the data is cleaned before visualizing and processing it
Show the correlation between different features in the dataset

多輪對話範例

聊天功能支援在同一會話中進行追蹤提示。使用多輪對話來迭代結果並改進 AI 的輸出。

首次提示

Create a REST API with Express.js that has endpoints for users and products

追蹤提示

Add input validation and error handling to both endpoints
Now add unit tests for the validation logic

透過基於先前的回應,AI 能夠維持先前的上下文,並生成更連貫的程式碼。

撰寫有效提示的技巧

  • 務必具體:包含您想要完成的內容、要使用的技術以及預期的輸出格式的詳細資訊。
  • 添加上下文:使用 # 提及來引用檔案、符號或上下文變數,例如 #codebase#changes#problems
  • 迭代:從簡單的提示開始,並根據回應進行改進。提出追蹤問題以改善結果。
  • 分解複雜任務:不要一次性詢問所有內容,而是將大型任務分解為較小、可管理的步驟。

進一步了解 撰寫提示的最佳實踐 以及 如何為提示添加上下文

© . This site is unofficial and not affiliated with Microsoft.