Skip to content
Free courses
Claude, Gemini and ChatGPTIntermediateFree

Working with Gemini: Prompting, Long Context and API

Learn to write effective prompts for Gemini, work with long documents, and call the Gemini API from Python. Build a command-line tool that answers questions about a file.

6 lessons 38 minNo account needed

Start lesson 1

What you will learn

  • Write prompts that ask Gemini for a role, context, and a fixed output format.
  • Use Gemini's long context to extract quoted evidence from a long document.
  • Call the Gemini API from a Python script and read the model's response.
  • Build a command-line tool that answers a question about a text file using your prompt.

Before you start

  • Run Python scripts from a terminal and install packages with pip.
  • Write basic Python: variables, functions, loops, and reading files.
  • Log in to a Google account in a web browser.

Lessons

  1. Lesson 1: Get a structured answer from a short textIn the Gemini chat window, write a prompt that gives Gemini a role, a short text, and a required output format, then check the answer.4 min
  2. Lesson 2: Use long context to answer across a long documentUpload a long report to Gemini and adjust your prompt to ask for quoted evidence and a summary, which prepares the prompt for API use.6 min
  3. Lesson 3: Make your first Gemini API requestSet up an API key, install the Gemini Python library, and send your prompt with a short sample text, then print the response.6 min
  4. Lesson 4: Send a long document through the APIRead a text file in Python and pass its full contents to the Gemini API with your prompt, then check that long context works.7 min
  5. Lesson 5: Build a command-line question toolAdd command-line arguments for a file path and a question, combine them with your prompt, and print a clean answer.7 min
  6. Lesson 6: Make the tool robust and test it end-to-endAdd a retry for failed API calls and test the complete tool on a long document of your own.8 min
4,814 open generative ai roles on Rolebound right nowSee the roles

Ready to use this in a job?

Rolebound applies to matching roles for you.

    Cookies on Rolebound

    We use necessary cookies to sign you in and keep the site working — those cannot be turned off. We would also like to set analytics and advertising cookies so we can see which pages help people get interviews and which adverts brought them here. Nothing optional is set unless you say yes, and you can change your mind at any time from “Cookie settings” in the footer. Read our Privacy Policy.

    Working with Gemini: Prompting, Long Context and API (free course) | Rolebound