Menu
CoddyTech

요약: Weather Desk

Coddy AI Engineering 여정의 도구와 에이전트 섹션에 포함된 레슨. 22개 중 5번째.

challenge icon

챌린지

중급

두 개의 도구를 사용하여 답변하는 날씨 데스크를 만드세요. 시작 코드에는 get_weather와 get_air_quality가 정의되어 있으며 질문을 읽습니다.

  1. 각각 하나의 필수 문자열 속성 city를 갖는 두 개의 도구를 정의하세요: 설명이 Get the current weather for a city인 get_weather, 그리고 설명이 Get the air quality index for a city인 get_air_quality.
  2. 두 도구와 함께 model="claude-opus-5-5" 및 max_tokens=300으로 질문을 전송하세요.
  3. stop reason이 "tool_use"인 경우: Tool: , 도구의 이름, 공백 및 입력을 출력하고, 일치하는 함수를 실행하며, 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 컴파일러