0
0
LangChainframework~10 mins

Chat history management 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 create a chat history object using LangChain.

LangChain
from langchain.memory import [1]

chat_history = [1]()
Drag options to blanks, or click blank then click option'
AChatMemory
BConversationBufferMemory
CConversationSummaryMemory
DMemoryBuffer
Attempts:
3 left
💡 Hint
Common Mistakes
Using a class that summarizes instead of buffering the chat.
Using a class name that does not exist in LangChain memory module.
2fill in blank
medium

Complete the code to add chat history memory to a LangChain chat model.

LangChain
from langchain.chat_models import ChatOpenAI
from langchain.memory import ConversationBufferMemory

memory = ConversationBufferMemory()
chat = ChatOpenAI(memory=[1])
Drag options to blanks, or click blank then click option'
Amemory
Bhistory
Cchat_memory
Dbuffer
Attempts:
3 left
💡 Hint
Common Mistakes
Using a parameter name that does not exist in the constructor.
Passing the wrong variable name.
3fill in blank
hard

Fix the error in the code to retrieve the chat history as a string.

LangChain
history_str = memory.[1]
Drag options to blanks, or click blank then click option'
Abuffer
Bload_memory()
Cget_history()
Dchat_memory
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to call a method that does not exist.
Using an incorrect attribute name.
4fill in blank
hard

Fill both blanks to create a chat memory that summarizes conversation instead of buffering.

LangChain
from langchain.memory import [1]

memory = [2](llm=llm)
Drag options to blanks, or click blank then click option'
AConversationSummaryMemory
BConversationBufferMemory
CChatMemory
DSummaryMemory
Attempts:
3 left
💡 Hint
Common Mistakes
Using the buffer memory class instead of summary memory.
Using a class name that does not exist.
5fill in blank
hard

Fill all three blanks to create a chat memory with a custom key and return messages enabled.

LangChain
memory = ConversationBufferMemory(
    memory_key=[1],
    return_messages=[2],
    output_key=[3]
)
Drag options to blanks, or click blank then click option'
A"chat_history"
BTrue
C"output"
DFalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using booleans as strings or vice versa.
Using incorrect key names.