Co-authored-by: Claire W <78226508+crwaters16@users.noreply.github.com> Co-authored-by: Anne-Marie <102995847+am-stead@users.noreply.github.com> Co-authored-by: Jules <19994093+jules-p@users.noreply.github.com> Co-authored-by: Jules Porter <jules-p@users.noreply.github.com> Co-authored-by: hubwriter <hubwriter@github.com> Co-authored-by: Robert Sese <734194+rsese@users.noreply.github.com>
3.7 KiB
title, intro, versions, category, complexity, octicon, topics
| title | intro | versions | category | complexity | octicon | topics | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Your first custom instructions | Create and test your first custom instruction with this simple example. |
|
|
|
book |
|
{% data reusables.copilot.customization-examples-note %}
About customizations
You can customize {% data variables.product.prodname_copilot %}'s responses using two types of files:
- Custom instructions provide ongoing guidance for how {% data variables.product.prodname_copilot %} should behave across all your interactions.
- Prompt files (public preview) define reusable prompts for specific tasks that you can invoke when needed. {% data reusables.copilot.prompt-files-available-in-editors %} For an introductory example, see AUTOTITLE.
While custom instructions help to add context to each AI workflow, prompt files let you add instructions to a specific chat interaction.
Repository custom instructions are the most commonly used and supported, but you can also define personal and organization custom instructions, only for {% data variables.copilot.copilot_chat_dotcom %}. {% data reusables.copilot.repository-custom-instructions-types %}
Your first instructions
Start with these core custom instructions that helps {% data variables.product.prodname_copilot %} understand your coding preferences.
Instructions on writing functions
When writing functions, always:
- Add descriptive JSDoc comments
- Include input validation
- Use early returns for error conditions
- Add meaningful variable names
- Include at least one example usage in comments
These instructions will change how {% data variables.product.prodname_copilot %} generates functions.
Test it out
To quickly test out the difference that custom instructions can make, you can use personal custom instructions in {% data variables.copilot.copilot_chat_short %}'s immersive view.
-
First, go to github.com/copilot and enter this prompt:
Create a JavaScript function that calculates the area of a circleWithout custom instructions, you might get:
function areaOfCircle(radius) { if (typeof radius !== 'number' || radius < 0) { throw new Error('Radius must be a non-negative number'); } return Math.PI * radius * radius; } -
Now access your personal custom instructions by clicking on your profile picture in the bottom left of the page, then click Personal instructions. Paste the above instructions into the text box, then click Save.
Now enter the same prompt that you entered previously.
With custom instructions, you'll get something like:
/** * Calculates the area of a circle given its radius. * * @param {number} radius - The radius of the circle. Must be a positive number. * @returns {number|null} The area of the circle, or null if the input is invalid. * * @example * // returns 78.53981633974483 * areaOfCircle(5); * * @example * // returns null (invalid input) * areaOfCircle(-2); */ function areaOfCircle(radius) { if (typeof radius !== "number" || isNaN(radius) || radius <= 0) { // Invalid input: radius must be a positive number return null; } const area = Math.PI * Math.pow(radius, 2); return area; } // Example usage: console.log(areaOfCircle(5)); // 78.53981633974483 console.log(areaOfCircle(-2)); // null
{% data reusables.copilot.custom-instructions-further-reading %}