Bird
0
0

Identify the error in this LangChain code snippet for question reformulation with history:

medium📝 Debug Q14 of 15
LangChain - Conversational RAG
Identify the error in this LangChain code snippet for question reformulation with history:
from langchain.chains import ConversationChain
from langchain.memory import ConversationBufferMemory

llm = SomeLLM()
chain = ConversationChain(llm=llm, memory=ConversationBufferMemory)

response = chain.run("Explain machine learning.")
print(response)
AThe llm variable is not defined
BConversationBufferMemory is not instantiated with parentheses
CThe run method does not exist on ConversationChain
DThe print statement is missing parentheses
Step-by-Step Solution
Solution:
  1. Step 1: Check how ConversationBufferMemory is used

    It must be instantiated with parentheses to create an object, but here it's passed as a class.
  2. Step 2: Verify other parts

    llm is defined, run method exists, and print syntax is correct in Python 3.
  3. Final Answer:

    ConversationBufferMemory is not instantiated with parentheses -> Option B
  4. Quick Check:

    Instantiate classes with () [OK]
Quick Trick: Always add () when creating memory instance [OK]
Common Mistakes:
  • Forgetting parentheses when instantiating classes
  • Assuming run method is missing
  • Confusing print syntax in Python 3

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes