提示示例

本文提供了 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 进行多文件创建,使用内联聊天⌘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.reactjs.ac.cn/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

使用 Agent 创建、编辑和处理 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.