0
0
Prompt Engineering / GenAIml~10 mins

Few-shot prompting in Prompt Engineering / GenAI - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add examples to the prompt for few-shot learning.

Prompt Engineering / GenAI
prompt = "Translate English to French:\n" + [1] + "\nInput: How are you?\nOutput:"
Drag options to blanks, or click blank then click option'
A"English: Hello\nFrench: Hola"
B"English: Hello\nFrench: Bonjour"
C"English: Hello\nFrench: Ciao"
D"English: Hello\nFrench: Hallo"
Attempts:
3 left
💡 Hint
Common Mistakes
Using greetings in other languages like Spanish or Italian.
Not formatting the example as 'English: ...\nFrench: ...'.
2fill in blank
medium

Complete the code to add multiple examples separated by newlines for few-shot prompting.

Prompt Engineering / GenAI
examples = "English: Hello\nFrench: Bonjour\n" + [1] + "\nInput: Thank you\nOutput:"
Drag options to blanks, or click blank then click option'
A"English: Goodbye\nFrench: Au revoir"
B"English: Goodbye\nFrench: Adios"
C"English: Goodbye\nFrench: Ciao"
D"English: Goodbye\nFrench: Hallo"
Attempts:
3 left
💡 Hint
Common Mistakes
Using Spanish or Italian words instead of French.
Not separating examples with newlines.
3fill in blank
hard

Fix the error in the prompt construction to correctly format few-shot examples.

Prompt Engineering / GenAI
prompt = "Translate English to French:\n" + examples + [1] + "Input: Good night\nOutput:"
Drag options to blanks, or click blank then click option'
A""
B" "
C"\t"
D"\n"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a space or tab instead of a newline.
Not adding any separator causing formatting issues.
4fill in blank
hard

Fill both blanks to create a function that builds a few-shot prompt with given examples and input.

Prompt Engineering / GenAI
def build_prompt(examples, input_text):
    return "Translate English to French:\n" + [1] + "\nInput: " + [2] + "\nOutput:"
Drag options to blanks, or click blank then click option'
Aexamples
Binput_text
Cexamples + '\n'
D'input_text'
Attempts:
3 left
💡 Hint
Common Mistakes
Not adding a newline after examples.
Using a string literal 'input_text' instead of the variable.
5fill in blank
hard

Fill all three blanks to complete the few-shot prompt generation with multiple examples and input.

Prompt Engineering / GenAI
examples = [
    "English: Hello\nFrench: Bonjour",
    "English: Goodbye\nFrench: Au revoir",
    "English: Thank you\nFrench: Merci"
]
prompt = "Translate English to French:\n" + [1] + "\nInput: " + [2] + "\nOutput:"

response = model.generate(prompt, max_tokens=[3])
Drag options to blanks, or click blank then click option'
A'\n'.join(examples)
Binput_sentence
C50
D100
Attempts:
3 left
💡 Hint
Common Mistakes
Using commas instead of newlines to join examples.
Using a string literal instead of the input variable.
Setting max_tokens too high or too low.