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

LLM को कॉल करने वाला एक टूल बनाइए

स्कूल प्रशासन को Wikipedia सर्च एजेंट वाले आपके एजुकेशन ऐप पर किया गया काम बहुत पसंद आया है. वे चाहते हैं कि आप ऐप को कुछ अतिरिक्त टूल्स के साथ और आगे बढ़ाएँ. यहाँ, आप historical_events() नाम का एक टूल बनाएँगे जो टूल के अंदर LLM को invoke करके इतिहास की प्रसिद्ध तिथियों से जुड़े प्रश्नों के उत्तर दे सके. Wikipedia टूल आपके लिए पहले से सेटअप है और llm आपके environment में उपलब्ध है.

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

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

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

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

  • टूल को लेबल करने के लिए एक डेकोरेटर जोड़ें और इनपुट फ़ॉर्मेट को string पर सेट करें.
  • try ब्लॉक के भीतर, llm के साथ .invoke() मेथड का उपयोग करें ताकि date_input के साथ LLM से क्वेरी करके historical events जेनरेट किए जा सकें.
  • LLM के response की content को .content से रिटर्न करें.
  • एरर पकड़ने के लिए Exception ब्लॉक को e के रूप में जोड़ें और एरर डिटेल्स शामिल करते हुए एरर मैसेज को फ़ॉर्मेट करें.

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

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

# Use a decorator to label the tool and set the input format to string
@____
def historical_events(date_input: ____) -> ____:
    """Provide a list of important historical events for a given date in any format."""
    try:

      	# Invoke the LLM to interpret the date and generate historical events
        response = ____.____(f"List important historical events that occurred on {____}.")
        
        # Return the response
        return ____.____

    # Set an exception block for errors in retrieval
    except ____ as ____:
        return f"Error retrieving events: {str(____)}"
कोड संपादित करें और चलाएँ