0
0
LangChainframework~10 mins

ChatPromptTemplate for conversations 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 ChatPromptTemplate class from langchain.prompts.

LangChain
from langchain.prompts import [1]
Drag options to blanks, or click blank then click option'
AConversationTemplate
BChatPromptTemplate
CPromptTemplate
DChatTemplate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'PromptTemplate' instead of 'ChatPromptTemplate'.
Trying to import from the wrong module.
2fill in blank
medium

Complete the code to create a ChatPromptTemplate with a system message and a human message.

LangChain
from langchain.prompts import ChatPromptTemplate, SystemMessagePromptTemplate, HumanMessagePromptTemplate

prompt = ChatPromptTemplate.from_messages([
    SystemMessagePromptTemplate.from_template("You are a helpful assistant."),
    [1].from_template("Hello, how can I help you?")
])
Drag options to blanks, or click blank then click option'
AAssistantMessagePromptTemplate
BUserMessagePromptTemplate
CHumanMessagePromptTemplate
DMessagePromptTemplate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'UserMessagePromptTemplate' which does not exist.
Using 'AssistantMessagePromptTemplate' for human input.
3fill in blank
hard

Fix the error in the code by completing the method to format messages with input variables.

LangChain
response = prompt.format_messages([1]="What is the weather today?")
Drag options to blanks, or click blank then click option'
Ainput
Bquery
Cquestion
Dmessage
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'question' or 'query' which are not defined in the template.
Using 'message' which is not the expected variable name.
4fill in blank
hard

Fill both blanks to create a ChatPromptTemplate with system and human messages using templates.

LangChain
prompt = ChatPromptTemplate.from_messages([
    [1].from_template("You are an expert."),
    [2].from_template("Tell me about {{input}}.")
])
Drag options to blanks, or click blank then click option'
ASystemMessagePromptTemplate
BUserMessagePromptTemplate
CHumanMessagePromptTemplate
DAssistantMessagePromptTemplate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'UserMessagePromptTemplate' which is not valid.
Mixing up system and human message classes.
5fill in blank
hard

Fill all three blanks to create a ChatPromptTemplate with system, human, and AI messages.

LangChain
prompt = ChatPromptTemplate.from_messages([
    [1].from_template("You are a helpful assistant."),
    [2].from_template("What is the capital of France?"),
    [3].from_template("Paris is the capital of France.")
])
Drag options to blanks, or click blank then click option'
ASystemMessagePromptTemplate
BHumanMessagePromptTemplate
CAIMessagePromptTemplate
DAssistantMessagePromptTemplate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'AssistantMessagePromptTemplate' instead of 'AIMessagePromptTemplate'.
Mixing up human and AI message classes.