Bird
0
0

Identify the error in this LangChain code snippet for handling follow-up questions:

medium📝 Debug Q14 of 15
LangChain - Conversational RAG
Identify the error in this LangChain code snippet for handling follow-up questions:
from langchain.chains import ConversationChain
from langchain.llms import OpenAI

llm = OpenAI(temperature=0)
conv = ConversationChain(llm=llm)

response1 = conv.predict(input="Hello, who won the world cup?")
response2 = conv.predict("Who scored the most goals?")
print(response2)
AThe print statement is invalid syntax
BConversationChain cannot be called twice
COpenAI LLM requires temperature > 0
DMissing 'input=' keyword in second predict call causes error
Step-by-Step Solution
Solution:
  1. Step 1: Check method call syntax

    ConversationChain.predict expects a named argument 'input=...'. The second call misses this keyword.
  2. Step 2: Understand consequences

    Without 'input=', Python raises a TypeError because the argument is positional but not expected.
  3. Final Answer:

    Missing 'input=' keyword in second predict call causes error -> Option D
  4. Quick Check:

    predict requires input= keyword = D [OK]
Quick Trick: Always use input= keyword in predict calls [OK]
Common Mistakes:
  • Calling predict without input= keyword
  • Thinking ConversationChain disallows multiple calls
  • Believing temperature=0 is invalid
  • Assuming print syntax is wrong

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes