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

Conversation history पर सवाल पूछें

LangChain में एक बेसिक ReAct एजेंट के साथ, आप एजेंट की conversation history सुरक्षित रखकर follow-up सवाल पूछ सकते हैं. चूँकि LLM को पिछली सभी messages तक पहुँच होती है, अब आप नए सवाल पूछ सकते हैं, और एजेंट जवाब देने के लिए पूरे message संदर्भ का उपयोग कर सकता है.

अब आप एक अलग triangle की भुजाओं के बारे में follow-up सवाल पूछेंगे.

HumanMessage और AIMessage क्षमताओं का उपयोग करने के लिए, निम्न modules पहले से आपके लिए इम्पोर्ट कर दिए गए हैं: HumanMessage, AIMessage.

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

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

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

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

  • दी गई प्राकृतिक भाषा वाले सवाल को new_query में असाइन करें.
  • app ऑब्जेक्ट को invoke करें, और सभी messages पास करें, जिनमें message_history और new_query शामिल हों.
  • एक list comprehension का उपयोग करके response["messages"] से वे messages निकालें जिनका लेबल HumanMessage या AIMessage है.
  • नए query को इनपुट के रूप में पास करें और निकाले गए messages को प्रिंट करें, message classes को "agent_output" में पास करके.

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

message_history = response["messages"]
____ = "What about one with sides 12 and 14?"

# Invoke the app with the full message history
response = app.____({"messages": ____ + [("human", ____)]})

# Extract the human and AI messages from the result
filtered_messages = [msg for msg in ____["____"] if isinstance(msg, (____, ____)) and msg.content.strip()]

# Pass the new query as input and print the final outputs
print({
    "user_input": ____,
    "agent_output": [f"{msg.____.____}: {msg.content}" for msg in ____]
})
कोड संपादित करें और चलाएँ