Bird
0
0

Given this code snippet, what will be the output of print(prompt_template.format(input="Translate to French: Hello") )?

medium📝 component behavior Q13 of 15
LangChain - Prompt Templates
Given this code snippet, what will be the output of print(prompt_template.format(input="Translate to French: Hello") )?
examples = [{"input": "Hello", "output": "Bonjour"}]
example_prompt = PromptTemplate(input_variables=["input", "output"], template="Input: {input}\nOutput: {output}")
prompt_template = FewShotPromptTemplate(examples=examples, example_prompt=example_prompt, prefix="Translate English to French:\n", suffix="\nInput: {input}\nOutput:", input_variables=["input"])
ATranslate English to French: Input: Translate to French: Hello Output:
BTranslate English to French: Input: Hello Output: Bonjour Translate to French: Hello
CInput: Hello Output: Bonjour Translate English to French: Hello
DTranslate English to French: Input: Hello Output: Bonjour Input: Translate to French: Hello Output:
Step-by-Step Solution
Solution:
  1. Step 1: Understand few-shot prompt formatting

    The prompt includes the prefix, then example prompts formatted with example data, then the new input prompt.
  2. Step 2: Apply formatting to given input

    The prefix is "Translate English to French:", then example "Input: Hello\nOutput: Bonjour", then the new input "Input: Translate to French: Hello\nOutput:" (empty output to be filled by AI).
  3. Final Answer:

    Translate English to French: Input: Hello Output: Bonjour Input: Translate to French: Hello Output: -> Option D
  4. Quick Check:

    Prefix + example + new input prompt = C [OK]
Quick Trick: Few-shot templates show prefix, examples, then new input [OK]
Common Mistakes:
  • Ignoring prefix text in output
  • Not formatting new input as 'Input: ... Output:'
  • Confusing example data with new input

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes