Menu
CoddyTech

결과 확인하기

Coddy AI Engineering 여정의 코드에서 모델 호출하기 섹션에 포함된 레슨. 22개 중 18번째.

challenge icon

챌린지

중급

이제 모든 티켓이 results의 dict 형태가 되었으므로, 순수 Python으로 하루 보고서를 작성할 수 있습니다. 지금까지 작성한 내용을 모두 유지하고, 루프 뒤에 다음 줄들을 추가하세요:

  1. SCHEMA의 enum 순서대로 각 카테고리에 대해 <category>: <count>를 출력하세요. 티켓이 없는 카테고리는 건너뜁니다.
  2. Urgent: 및 긴급 티켓의 번호들을 출력하되, 각 번호는 #<number> 형식으로 작성하고 쉼표와 공백으로 연결하세요. 긴급한 티켓이 없을 때는 Urgent: none를 출력합니다.

urgent는 json.loads 이후에 실제 불리언 값이 되므로 if data["urgent"]:로 검사하세요. 예를 들어 두 티켓이 모두 billing이고 긴급하지 않은 경우, 프로그램은 다음과 같이 끝납니다:

billing: 2
Urgent: none

직접 해보기

import coddy_ai as anthropic  # 프로덕션 환경에서는: import anthropic
import json

client = anthropic.Anthropic()

SCHEMA = {
    "type": "object",
    "properties": {
        "category": {"type": "string", "enum": ["billing", "shipping", "account", "technical", "other"]},
        "urgent": {"type": "boolean"},
        "summary": {"type": "string"},
    },
    "required": ["category", "urgent", "summary"],
    "additionalProperties": False,
}

count = int(input())
tickets = [input() for _ in range(count)]

print(f"Tickets: {count}")
results = []
for number, ticket in enumerate(tickets, start=1):
    response = client.messages.create(
        model="claude-opus-5-5",
        max_tokens=200,
        output_config={"format": {"type": "json_schema", "schema": SCHEMA}},
        messages=[{"role": "user", "content": ticket}],
    )
    for block in response.content:
        if block.type == "text":
            data = json.loads(block.text)
            results.append(data)
            urgent = "yes" if data["urgent"] else "no"
            print(f"#{number} {data['category']} | urgent: {urgent} | {data['summary']}")

코드에서 모델 호출하기의 모든 레슨

직접 연습해 보세요: 온라인 Python 컴파일러