Performance: Handling follow-up questions
This affects the responsiveness and smoothness of conversational AI interactions by managing context efficiently.
const memory = new BufferMemory();
const chain = new ConversationChain({ llm: openai, memory });
await chain.call({ input: 'What is AI?' });
await chain.call({ input: 'And how does it work?' });const chain = new ConversationChain({ llm: openai });
await chain.call({ input: 'What is AI?' });
await chain.call({ input: 'And how does it work?' });| Pattern | Context Management | LLM Calls | Response Time | Verdict |
|---|---|---|---|---|
| No context reuse | None | Multiple full calls | High latency | [X] Bad |
| Context reuse with memory | Efficient | Single incremental calls | Lower latency | [OK] Good |
from langchain.chains import ConversationChain from langchain.llms import OpenAI llm = OpenAI(temperature=0) conv = ConversationChain(llm=llm) response1 = conv.predict(input="What is AI?") response2 = conv.predict(input="Can you explain more?") print(response2)What does
response2 represent?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)Pass the test and this pattern moves unknown