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 1What 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
- 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
- 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
- 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
- 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
- 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
- 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