Thank you for your interest in contributing to Gemini by Example! This document provides guidelines and instructions for adding new examples and improving the project.
Create a new directory in examples/ with a numeric prefix for ordering:
examples/003-your-example-name/
The numeric prefix determines the order of examples on the site.
Create a Python file (.py) within your example directory that demonstrates the feature:
# Your Example Title
# This is a description of what this example demonstrates.
# This will appear at the top of the example page.
# This comment explains the next line of code
from google import genai
# Comments should explain each significant step
client = genai.Client(api_key="YOUR_API_KEY")
# Empty comment lines create section breaks
# This starts a new section of explanation
response = client.models.generate_content(
model="gemini-2.0-flash",
contents="Your prompt here"
)
print(response.text)- The first comment block becomes the title and description
- Each comment block explains the code that follows it
- Comment blocks with no following code create section headings
- Comments must start with
#at the beginning of the line
Create a shell script (.sh) showing how to run the example:
# First, install the Google Generative AI library
$ pip install google-generative-ai
# Then run the program with Python
$ python your-example.py
Expected output goes here...- Lines starting with
#are explanations - Lines starting with
$are commands to run - Other lines are expected output
- Keep outputs concise and relevant
If you want to include images:
- Add a single PNG file to your example directory
- Use a meaningful filename with a numeric prefix, e.g.,
01-result-image.png - The part after the prefix will be used as the caption (e.g., "Result image")
- Please compress images using TinyPNG before adding them
After creating your example:
-
Build the examples data:
python build_static_site.py
This runs both the example builder and static site generator in one step.
-
Open the generated HTML in the
docs/directory to preview your example
Examples are organized into sections using the data/sections.json file. To add your example to a section:
- Find the appropriate section in
sections.json - Add your example's directory name to the
examplesarray
{
"sections": [
{
"id": "001-basic",
"title": "Basic Examples",
"description": "Getting started with Gemini API",
"order": 1,
"examples": ["001-basic-generation", "002-values", "003-your-example-name"]
}
]
}If you're creating a new section, add it to the array with a unique ID and order number.
- Keep examples simple and focused on one concept
- Use clear, concise explanations
- Follow PEP 8 for Python code
- Avoid complex dependencies beyond the Google Generative AI library
- Make sure examples are runnable with just the instructions provided
- Fork the repository
- Create a branch for your changes
- Add your example and test it locally
- Submit a pull request with a clear description of your example
Thank you for contributing to Gemini by Example!