Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a few-shot prompt template with examples.
LangChain
from langchain.prompts import FewShotPromptTemplate, PromptTemplate example_prompt = PromptTemplate(input_variables=["word"], template="Translate '{{word}}' to French: '[1]'") examples = [{"word": "hello", "translation": "bonjour"}] few_shot_prompt = FewShotPromptTemplate( examples=examples, example_prompt=example_prompt, input_variables=["word"] )
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the input variable 'word' instead of the output variable 'translation' in the template.
Confusing the example keys with input variables.
✗ Incorrect
The example prompt template uses 'translation' as the variable to fill the French word in the template.
2fill in blank
mediumComplete the code to set the prefix for the few-shot prompt template.
LangChain
few_shot_prompt = FewShotPromptTemplate(
examples=examples,
example_prompt=example_prompt,
prefix=[1],
input_variables=["word"]
) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put quotes around the prefix string.
Using single quotes inconsistently.
✗ Incorrect
The prefix must be a string literal, so it needs to be enclosed in quotes.
3fill in blank
hardFix the error in the code to correctly create a few-shot prompt template with suffix.
LangChain
few_shot_prompt = FewShotPromptTemplate(
examples=examples,
example_prompt=example_prompt,
prefix="Translate English to French:",
suffix=[1],
input_variables=["word"]
) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the suffix string.
Not escaping the newline character properly.
✗ Incorrect
The suffix must be a string literal with placeholders, so it needs to be enclosed in quotes and use proper escape sequences.
4fill in blank
hardFill both blanks to create a few-shot prompt template with example separator and suffix.
LangChain
few_shot_prompt = FewShotPromptTemplate(
examples=examples,
example_prompt=example_prompt,
example_separator=[1],
suffix=[2],
input_variables=["word"]
) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect separator strings without newlines.
Not including the input variable placeholder in the suffix.
✗ Incorrect
The example separator is a string with newlines and dashes, and the suffix includes the input variable placeholder.
5fill in blank
hardFill all three blanks to build a few-shot prompt template with prefix, example separator, and suffix.
LangChain
few_shot_prompt = FewShotPromptTemplate(
examples=examples,
example_prompt=example_prompt,
prefix=[1],
example_separator=[2],
suffix=[3],
input_variables=["word"]
) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up prefix and suffix strings.
Not using proper escape sequences in separator and suffix.
✗ Incorrect
The prefix is a polite instruction, the example separator uses newlines and dashes, and the suffix prompts for input and output.