注意
- Copilot 提示文件为 公共预览版,可能随时更改。 提示文件仅在 VS Code 中可用。 请参阅“关于自定义 GitHub Copilot 聊天助手响应”。
- 如需获取社区提供的有关特定语言和场景的提示文件示例,请参阅出色的 GitHub Copilot 自定义内容仓库。
关于自定义
可以使用两类文件来自定义 GitHub Copilot 的响应:
- 自定义说明****:为 GitHub Copilot 在你的所有交互中的行为方式提供持续指导。 有关入门示例,请参阅首条自定义说明。
- 提示文件(公共预览版)****:定义你可在需要时调用的特定任务的可重用提示。 提示文件仅在 VS Code 中可用。
第一个提示文件
从这个简单的提示文件开始,它帮助你编写清晰、规范的代码解释。
代码解释提示
--- mode: '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.
---
mode: '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.
测试一下
-
在
.github/prompts
文件夹中,将上面的提示文件另存为explain-code.prompt.md
。 -
在 Visual Studio Code 中,显示 Copilot 对话助手 视图,然后输入
/explain-code
。Copilot 将切换为代理模式(如果尚未选择此模式),并提示你输入一些代码和一个受众类型。
-
输入:
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 自定义内容 - 社区提供的自定义提示文件的仓库以及特定语言和场景的其他自定义内容