शुरू करेंमुफ़्त में शुरू करें

कन्वर्सेशन के लिए ग्राफ मेमोरी का उपयोग

अब जब आपके चैटबॉट के पास मेमोरी की पहुँच है, तो आप उसके जवाबों को follow-up प्रश्नों के लिए स्ट्रीम कर सकते हैं. ध्यान दें कि आपके follow-up प्रश्नों को किसी अतिरिक्त संदर्भ की ज़रूरत नहीं होगी, क्योंकि चैटबॉट अपनी मेमोरी में सहेजी गई पूरी बातचीत तक पहुँच कर सकता है. आपके लिए प्रश्न पहले से सेट कर दिए गए हैं.

यह अभ्यास पाठ्यक्रम का हिस्सा है

LangChain के साथ Agentic Systems डिज़ाइन करना

पाठ्यक्रम देखें

अभ्यास निर्देश

  • "configurable" के साथ एक config dictionary बनाएँ, जिसमें "thread_id" को "single_session_memory" पर सेट करें.
  • प्रत्येक ग्राफ event पर loop चलाएँ, graph पर .stream() मेथड लगाएँ, और एक dictionary पास करें जिसमें "messages" में user_input को "user" लेबल के साथ रखें, और config dictionary भी पास करें.
  • 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?")
कोड संपादित करें और चलाएँ