提示示例

本文提供了针对 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.