0
0
LangChainframework~10 mins

A/B testing prompt variations in LangChain - Interactive Code Practice

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

Complete the code to import the correct class for prompt templates in LangChain.

LangChain
from langchain.prompts import [1]
Drag options to blanks, or click blank then click option'
APromptManager
BPromptTemplate
CPromptBuilder
DPromptFactory
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent class like PromptManager.
Confusing with other prompt-related classes.
2fill in blank
medium

Complete the code to create two prompt templates for A/B testing with different greetings.

LangChain
prompt_a = PromptTemplate(template="Hello, {" + [1] + "}! How can I help you?")
prompt_b = PromptTemplate(template="Hi, {" + [1] + "}! What can I do for you?")
Drag options to blanks, or click blank then click option'
Acustomer
Buser
Cname
Dclient
Attempts:
3 left
💡 Hint
Common Mistakes
Using generic terms like 'user' or 'client' instead of a variable name.
Leaving the placeholder empty.
3fill in blank
hard

Fix the error in the code to select a prompt template randomly for A/B testing.

LangChain
import random
prompts = [prompt_a, prompt_b]
selected_prompt = prompts[[1](0, 1)]
Drag options to blanks, or click blank then click option'
Arandint
Bchoice
Crandom
Drandrange
Attempts:
3 left
💡 Hint
Common Mistakes
Using random.choice which returns an element, not an index.
Using random.random which returns a float.
4fill in blank
hard

Fill both blanks to create a dictionary that maps prompt names to their templates for easy access.

LangChain
prompt_variations = { [1]: prompt_a, [2]: prompt_b }
Drag options to blanks, or click blank then click option'
A"A"
B"B"
C"prompt_a"
D"prompt_b"
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names as keys instead of strings.
Omitting quotes around keys.
5fill in blank
hard

Fill all three blanks to complete the function that runs A/B testing by selecting a prompt and formatting it with a user name.

LangChain
def run_ab_test(user_name):
    selected = prompt_variations[[1]]
    formatted_prompt = selected.[2]([3]=user_name)
    return formatted_prompt
Drag options to blanks, or click blank then click option'
A"A"
Bformat
Cname
D"B"
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect keys that don't exist in the dictionary.
Calling a non-existent method instead of format.
Passing the wrong argument name.