提示範例

本文提供 Visual Studio Code 中針對不同情境與代理程式的聊天提示詞範例。請將這些範例作為靈感,為您的開發任務撰寫有效的提示詞。

如果您是剛開始使用 VS Code 聊天功能,請深入了解聊天功能入門或查閱提示詞撰寫的最佳實務

一般程式設計與技術問題

使用 Ask 代理程式來取得關於程式概念、技術主題與一般程式設計問題的快速解答。

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

理解並探索您的程式碼庫

Ask 代理程式與 #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?

程式碼生成與編輯

使用 Agent 進行多檔案建立,並使用內嵌聊天 (inline chat) (⌘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

測試與品質保證

使用 Agent 來產生測試或修復失敗的測試。

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

除錯與修復問題

使用 Agent 來修復跨檔案的問題,或先使用 Ask 來理解根本原因。

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 Notebooks

使用 Agent 來建立、編輯與使用 Jupyter Notebooks。

/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 能夠維持來自先前步驟的上下文,並產生更連貫的程式碼。

撰寫有效提示詞的秘訣

  • 具體明確:包含您想要完成事項的詳細資訊、要使用的技術以及預期的輸出格式。
  • 加入上下文:使用 #-mentions 來引用檔案、符號或上下文變數,例如 #codebase#changes#problems
  • 疊代優化:從簡單的提示開始,並根據回應進行修正。詢問後續問題以改善結果。
  • 拆解複雜任務:與其一次要求所有內容,不如將大型任務拆解為較小且易於管理的步驟。

進一步了解撰寫提示詞的最佳實務在提示詞中加入上下文

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