कन्वर्सेशन के लिए ग्राफ मेमोरी का उपयोग
अब जब आपके चैटबॉट के पास मेमोरी की पहुँच है, तो आप उसके जवाबों को follow-up प्रश्नों के लिए स्ट्रीम कर सकते हैं. ध्यान दें कि आपके follow-up प्रश्नों को किसी अतिरिक्त संदर्भ की ज़रूरत नहीं होगी, क्योंकि चैटबॉट अपनी मेमोरी में सहेजी गई पूरी बातचीत तक पहुँच कर सकता है. आपके लिए प्रश्न पहले से सेट कर दिए गए हैं.
यह अभ्यास पाठ्यक्रम का हिस्सा है
LangChain के साथ Agentic Systems डिज़ाइन करना
अभ्यास निर्देश
"configurable"के साथ एकconfigdictionary बनाएँ, जिसमें"thread_id"को"single_session_memory"पर सेट करें.- प्रत्येक ग्राफ
eventपर loop चलाएँ,graphपर.stream()मेथड लगाएँ, और एक dictionary पास करें जिसमें"messages"मेंuser_inputको"user"लेबल के साथ रखें, औरconfigdictionary भी पास करें. event.values()परvalueके साथ loop चलाएँ और अगरvalueमें"messages"मौजूद हो और खाली न हो, तो"Agent:"प्रिंट करें और उसके बाद"messages"प्रिंट करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Set up a streaming function for a single user
def stream_memory_responses(user_input: str):
____ = {"____": {"____": "____"}}
# Stream the events in the graph
for ____ in graph.____({"messages": [("user", ____)]}, ____):
# Return the agent's last response
for ____ in event.____():
if "messages" in ____ and value["____"]:
print("Agent:", value["messages"])
stream_memory_responses("Tell me about the Eiffel Tower.")
stream_memory_responses("Who built it?")