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 rest of the curriculum. Card required, cancel any time in Dashboard.Start 7-day trial →
← CoursesAI Engineering with PythonModule 6 · Frontier AI EngineeringFiles API: persistent document processingwrite97 / 105
+110 XP
Task
📝 **Task:** Implement `FileCache` with two methods: * `upload_or_reuse(content: bytes) -> str` — returns a `file_id`. If `sha256(content)` was seen before, return the cached id. Otherwise call `self._real_upload(content)` (already provided — it returns `f"file_{n}"` where `n` is the call count starting at 1) and remember the mapping. * `stats() -> tuple[int, int]` — returns `(uploads_called, cache_hits)`. The starter ends with a canonical driver: 2 distinct uploads + 1 duplicate. Expected canonical output: ``` file_1 file_2 file_1 (2, 1) ``` Two additional graded scenarios run after your code (via `input_append`) and exercise the empty-bytes and hot-doc boundaries — your `FileCache` must generalise so they pass too. 📋 Implement the function above. Tests run automatically. 💡 **Hint:** Re-read the theory if stuck.
✏️ 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…