Skip to main content
πŸ”’ Preview mode. The first 15 Foundations lessons are free; this one is Pro. Start a 7-day trial to unlock the editor, AI hints and the the rest of the curriculum. Card required, cancel any time in Dashboard.Start 7-day trial β†’
⚑
← Coursesβ€ΊAI Engineering with PythonModule 1 Β· LLM API Fundamentals Β· Recapβ€ΊπŸŽ― Review: AI engineering module 1 recapscenario22 / 105
+80 XP
Task
Build a small `summarise_chat(messages)` helper that ties together 4 ideas from module 1: 1. **Message format** β€” read role + content fields. 2. **Context trimming** β€” if total content chars exceeds 8000, drop oldest messages (FIFO) until it fits. 3. **Model selection** β€” count chars on the last user message. If `chars // 4 < 100` (rough token estimate), route to Haiku; otherwise Sonnet. 4. **Return shape** β€” `{"messages": [...trimmed...], "model": "<id>"}`. Fill the `# TODO` blocks in the starter. The harness prints model choice for two short chats, then trims a chat that overflows 8000 chars and prints the surviving length + first remaining role.
✏️ Write your code here
🐍
Loading Python...
One-time download (~1 MB). Then it runs instantly.
πŸ“Š Result
Press Run to see result...

πŸ’¬ Discussion

Be the first to ask a question or share a tip.
Sign in to join the discussion. Reading is free.
Loading discussion…