Understand two fundamental prompting techniques to guide GitHub Copilot more effectively: Zero-Shot (direct instruction) and Few-Shot (providing examples).
This involves giving Copilot Chat a direct instruction or question without providing specific input/output examples within the prompt itself.
Example (Chat):
/explain #selection
Write a python function to calculate the area of a circle given the radius.
Here, you provide one or more examples (input -> output pairs) within the prompt to demonstrate the desired pattern, format, or style before making your actual request.
Example (Chat - Sentiment Classification):
Determine if each movie review is Positive or Negative.
Review: "I couldn't stop laughing throughout the film!"
Sentiment: Positive
Review: "The plot was a complete mess and very boring."
Sentiment: Negative
Review: "The cinematography was stunning and the story touched my heart."
Sentiment:
(Copilot should complete the last line with "Positive" based on the examples).
Example (Chat - Code Style/Format):
Convert the following Python comments to the specified format:
Input: # Get user data
Output: // Get user data
Input: # Calculate total price
Output: // Calculate total price
Input: # Validate input parameters
Output:
(Copilot should complete the last line with "// Validate input parameters").
Use zero-shot prompting for simpler tasks or when using built-in slash commands. Employ few-shot prompting with clear examples in Copilot Chat when you need to precisely control the output format, style, or logic pattern.