注意
- Copilot 提示文件目前处于公共预览阶段,可能会有所更改。提示文件仅在 VS Code、Visual Studio 和 JetBrains IDE 中可用。请参阅关于自定义 GitHub Copilot 响应。
- 有关特定语言和场景的社区贡献提示文件示例,请参阅 Awesome GitHub Copilot Customizations 仓库。
关于自定义
您可以使用两种类型的文件来自定义 GitHub Copilot 的响应
- 自定义指令 为 GitHub Copilot 在所有交互中的行为提供持续指导。有关入门示例,请参阅 您的第一个自定义指令。
- 提示文件(公开预览) 定义可重复使用的提示,用于特定任务,您可以在需要时调用。提示文件仅在 VS Code、Visual Studio 和 JetBrains IDE 中可用。
您的第一个提示文件
从这个简单的提示文件开始,它帮助您编写清晰、文档完善的代码解释。
代码解释提示
---
agent: 'agent'
description: 'Generate a clear code explanation with examples'
---
Explain the following code in a clear, beginner-friendly way:
Code to explain: ${input:code:Paste your code here}
Target audience: ${input:audience:Who is this explanation for? (e.g., beginners, intermediate developers, etc.)}
Please provide:
* A brief overview of what the code does
* A step-by-step breakdown of the main parts
* Explanation of any key concepts or terminology
* A simple example showing how it works
* Common use cases or when you might use this approach
Use clear, simple language and avoid unnecessary jargon.
---
agent: 'agent'
description: 'Generate a clear code explanation with examples'
---
Explain the following code in a clear, beginner-friendly way:
Code to explain: ${input:code:Paste your code here}
Target audience: ${input:audience:Who is this explanation for? (e.g., beginners, intermediate developers, etc.)}
Please provide:
* A brief overview of what the code does
* A step-by-step breakdown of the main parts
* Explanation of any key concepts or terminology
* A simple example showing how it works
* Common use cases or when you might use this approach
Use clear, simple language and avoid unnecessary jargon.
尝试一下
-
将上述提示文件保存为
explain-code.prompt.md,放置在您的.github/prompts文件夹中。 -
在 Visual Studio Code 中,显示 Copilot Chat 视图并输入
/explain-code。Copilot 将切换到代理模式(如果尚未选择),并提示您输入一些代码以及受众类型。
-
Enter(回车键)
Text The code is `function fibonacci(n) { return n <= 1 ? n : fibonacci(n-1) + fibonacci(n-2); }`. The audience is beginners.The code is `function fibonacci(n) { return n <= 1 ? n : fibonacci(n-1) + fibonacci(n-2); }`. The audience is beginners.
延伸阅读
- 在 Visual Studio Code 中使用提示文件,位于 Visual Studio Code 文档中——有关如何创建和使用提示文件的信息
- 关于定制 GitHub Copilot 响应 - GitHub Copilot 响应定制概览
- 优秀的 GitHub Copilot 定制 - 社区贡献的自定义提示文件及其他针对特定语言和场景的定制仓库