Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions .github/workflows/samples.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Validate samples

on:
pull_request:
types: [opened, synchronize] # new, updates

jobs:
update-python-list:
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Get Changed Files
id: changed_files
uses: tj-actions/changed-files@v44
with:
files: |
samples/*.py
output_renamed_files_as_deleted_and_added: "true"

- name: Check Python samples
env:
NEW_FILES: ${{ steps.changed_files.outputs.all_changed_files }}
run: |
#!/bin/bash

for file in "${NEW_FILES}"; do
if ! grep -q $name samples/README.md; then
echo "Error: sample not listed in README ($name)"
exit 1
fi
done

update-rest-list:
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Get Changed Files
id: changed_files
uses: tj-actions/changed-files@v44
with:
files: |
samples/rest/*.sh
output_renamed_files_as_deleted_and_added: "true"

- name: Check REST samples
env:
NEW_FILES: ${{ steps.changed_files.outputs.all_changed_files }}
run: |
#!/bin/bash

for file in "${NEW_FILES}"; do
if ! grep -q $name samples/README.md; then
echo "Error: sample not listed in README ($name)"
exit 1
fi
done
26 changes: 26 additions & 0 deletions samples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Gemini API Python SDK sample code

This directory contains sample code for key features of the SDK, organised by high level feature.

These samples are embedded in parts of the [documentation](https://ai.google.dev), most notably in the [API reference](https://ai.google.dev/api).

Each file is structured as a runnable test case, ensuring that samples are executable and functional. Each test demonstrates a single concept, and contains region tags that are used to demarcate the test scaffolding from the spotlight code. If you are contributing, code within region tags should follow sample code best practices - being clear, complete and concise.

## Contents

| File | Description |
| ---- | ----------- |
| [cache.py](./cache.py) | Context caching |
| [chat.py](./chat.py) | Multi-turn chat conversations |
| [code_execution.py](./code_execution.py) | Executing code |
| [configure_model_parameters.py](./configure_model_parameters.py) | Setting model parameters |
| [controlled_generation.py](./controlled_generation.py) | Generating content with output constraints (e.g. JSON mode) |
| [count_tokens.py](./count_tokens.py) | Counting input and output tokens |
| [embed.py](./embed.py) | Generating embeddings |
| [files.py](./files.py) | Managing files with the File API |
| [function_calling.py](./function_calling.py) | Using function calling |
| [models.py](./models.py) | Listing models and model metadata |
| [safety_settings.py](./safety_settings.py) | Setting and using safety controls |
| [system_instruction.py](./system_instruction.py) | Setting system instructions |
| [text_generation.py](./text_generation.py) | Generating text |
| [tuned_models.py](./tuned_models.py) | Creating and managing tuned models |
25 changes: 25 additions & 0 deletions samples/rest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Gemini API REST sample code

This directory contains sample code for key features of the API, organised by high level feature.

These samples are embedded in parts of the [documentation](https://ai.google.dev), most notably in the [API reference](https://ai.google.dev/api).

Each file is structured as a runnable script, ensuring that samples are executable and functional. Each filee contains region tags that are used to demarcate the script from the spotlight code. If you are contributing, code within region tags should follow sample code best practices - being clear, complete and concise.

## Contents

| File | Description |
| ---- | ----------- |
| [cache.sh](./cache.sh) | Context caching |
| [chat.sh](./chat.sh) | Multi-turn chat conversations |
| [code_execution.sh](./code_execution.sh) | Executing code |
| [configure_model_parameters.sh](./configure_model_parameters.sh) | Setting model parameters |
| [controlled_generation.sh](./controlled_generation.sh) | Generating content with output constraints (e.g. JSON mode) |
| [count_tokens.sh](./count_tokens.sh) | Counting input and output tokens |
| [embed.sh](./embed.sh) | Generating embeddings |
| [files.sh](./files.sh) | Managing files with the File API |
| [function_calling.sh](./function_calling.sh) | Using function calling |
| [models.sh](./models.sh) | Listing models and model metadata |
| [safety_settings.sh](./safety_settings.sh) | Setting and using safety controls |
| [system_instruction.sh](./system_instruction.sh) | Setting system instructions |
| [text_generation.sh](./text_generation.sh) | Generating text |
Loading