Menu
CoddyTech

סיכום: Weather Desk

חלק מהיחידה כלים וסוכנים במסלול ה-AI Engineering של Coddy. שיעור 5 מתוך 22.

challenge icon

אתגר

בינוני

בנה דסק מזג אוויר שעונה באמצעות שני כלים. קוד ההתחלה מגדיר את get_weather ואת get_air_quality וקורא את השאלה.

  1. הגדר שני כלים, לכל אחד מהם תכונת מחרוזת נדרשת אחת city: get_weather עם התיאור Get the current weather for a city, ו-get_air_quality עם התיאור Get the air quality index for a city.
  2. שלח את השאלה עם שני הכלים, model="claude-opus-5-5" ו-max_tokens=300.
  3. אם סיבת העצירה היא "tool_use": הדפס Tool: , את שם הכלי, רווח ואת ה-input שלו; הרץ את הפונקציה המתאימה; שלח את תור ה-assistant ואת ה-tool_result; וקרא למודל שוב. אחרת הדפס Tool: none.
  4. הדפס Answer: ואת הטקסט של בלוק הטקסט של התשובה האחרונה.

לדוגמה, עבור הקלט What is the weather in Lisbon? התוכנית מדפיסה:

Tool: get_weather {'city': 'Lisbon'}
Answer: Here is what I found: Lisbon: 19 C and sunny

נסו בעצמכם

import coddy_ai as anthropic  # בסביבת ייצור: import anthropic

client = anthropic.Anthropic()

WEATHER = {"Lisbon": "19 C and sunny", "Delhi": "31 C and hazy", "Montreal": "-3 C and snowing"}
AIR = {"Lisbon": "index 22, good", "Delhi": "index 168, unhealthy", "Montreal": "index 35, good"}


def get_weather(city):
    return f"{city}: {WEATHER.get(city, 'no weather data')}"


def get_air_quality(city):
    return f"{city}: {AIR.get(city, 'no air quality data')}"


question = input()

# כתוב את הקוד שלך למטה

כל השיעורים ביחידה כלים וסוכנים

תרגלו בעצמכם: קומפיילר Python אונליין