codex-lv2-may-2025

Level Navigation: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Current Level: 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32


đź§Ş Level 15: Add Hugging Face API

What You’ll Do

Connect your function to the Hugging Face API.

⚠️ Tricky Lesson Alert!

This lesson involves working with APIs and can be challenging. If you get stuck or encounter errors, don’t worry - this is normal!

Need help? Use our Help Seeking Form to get support from your instructors and classmates.

Instructions

Paste the Hugging Face JavaScript fetch snippet into sendToModel. Replace the API token first.

đź’ˇ Code Hints

Making API calls? You’ll need to use the fetch function to call the Hugging Face API. Check out the API Calls section in SNIPPETS.md for fetch examples and the OpenAI Response Format section for correct response handling.

đź“‹ Cheat Sheet

Quick Reference: Check out the Hugging Face Gen Code Cheat Sheet for what you will need to change on your generated code.

âś… Check

  1. Open your webpage in a browser
  2. Open Chrome DevTools (F12) and go to the Console tab
  3. Type sendToModel() and press Enter
  4. You should see either:
    • A successful API response (JSON data with the AI’s answer)
    • An error message (this is normal if you haven’t set up your API token yet)
  5. If you get a syntax error, check that you pasted the fetch code correctly
  6. If you get a network error, check that your API token is properly set in secret-variables.js

Next: Level 16 - Proof-of-Life Test



Level Navigation: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Current Level: 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32