Skip to content

Commit db311dd

Browse files
authored
Add a README for /samples (#507)
* Add a README for /samples * Add rest/README.md * Add an action to keep updated * Typo * Fix action workflow * Reworked action a bit * Extra info line
1 parent 3612328 commit db311dd

File tree

3 files changed

+133
-0
lines changed

3 files changed

+133
-0
lines changed

.github/workflows/samples.yaml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Validate samples
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize] # new, updates
6+
7+
jobs:
8+
update-python-list:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout Code
13+
uses: actions/checkout@v3
14+
15+
- name: Get Changed Files
16+
id: changed_files
17+
uses: tj-actions/changed-files@v44
18+
with:
19+
files: |
20+
samples/*.py
21+
22+
- name: Check Python samples
23+
env:
24+
NEW_FILES: ${{ steps.changed_files.outputs.all_modified_files }}
25+
README: samples/README.md
26+
run: |
27+
#!/bin/bash
28+
29+
for file in ${NEW_FILES}; do
30+
echo "Testing $file"
31+
if [[ -f ${file} ]]; then
32+
# File exists, so needs to be listed.
33+
if ! grep -q $name ${README}; then
34+
echo "Error: Sample not listed in README ($name)"
35+
exit 1
36+
fi
37+
else
38+
# File does not exist, ensure it's not listed
39+
if grep -q $name ${README}; then
40+
echo "Error: Sample should not be listed in README ($name)"
41+
exit 1
42+
fi
43+
fi
44+
done
45+
46+
update-rest-list:
47+
runs-on: ubuntu-latest
48+
49+
steps:
50+
- name: Checkout Code
51+
uses: actions/checkout@v3
52+
53+
- name: Get Changed Files
54+
id: changed_files
55+
uses: tj-actions/changed-files@v44
56+
with:
57+
files: |
58+
samples/rest/*.sh
59+
60+
- name: Check REST samples
61+
env:
62+
NEW_FILES: ${{ steps.changed_files.outputs.all_modified_files }}
63+
README: samples/rest/README.md
64+
run: |
65+
#!/bin/bash
66+
67+
for file in ${NEW_FILES}; do
68+
echo "Testing $file"
69+
if [[ -f ${file} ]]; then
70+
# File exists, so needs to be listed.
71+
if ! grep -q $name ${README}; then
72+
echo "Error: Sample not listed in README ($name)"
73+
exit 1
74+
fi
75+
else
76+
# File does not exist, ensure it's not listed
77+
if grep -q $name ${README}; then
78+
echo "Error: Sample should not be listed in README ($name)"
79+
exit 1
80+
fi
81+
fi
82+
done

samples/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Gemini API Python SDK sample code
2+
3+
This directory contains sample code for key features of the SDK, organised by high level feature.
4+
5+
These samples are embedded in parts of the [documentation](https://ai.google.dev), most notably in the [API reference](https://ai.google.dev/api).
6+
7+
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.
8+
9+
## Contents
10+
11+
| File | Description |
12+
| ---- | ----------- |
13+
| [cache.py](./cache.py) | Context caching |
14+
| [chat.py](./chat.py) | Multi-turn chat conversations |
15+
| [code_execution.py](./code_execution.py) | Executing code |
16+
| [configure_model_parameters.py](./configure_model_parameters.py) | Setting model parameters |
17+
| [controlled_generation.py](./controlled_generation.py) | Generating content with output constraints (e.g. JSON mode) |
18+
| [count_tokens.py](./count_tokens.py) | Counting input and output tokens |
19+
| [embed.py](./embed.py) | Generating embeddings |
20+
| [files.py](./files.py) | Managing files with the File API |
21+
| [function_calling.py](./function_calling.py) | Using function calling |
22+
| [models.py](./models.py) | Listing models and model metadata |
23+
| [safety_settings.py](./safety_settings.py) | Setting and using safety controls |
24+
| [system_instruction.py](./system_instruction.py) | Setting system instructions |
25+
| [text_generation.py](./text_generation.py) | Generating text |
26+
| [tuned_models.py](./tuned_models.py) | Creating and managing tuned models |

samples/rest/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Gemini API REST sample code
2+
3+
This directory contains sample code for key features of the API, organised by high level feature.
4+
5+
These samples are embedded in parts of the [documentation](https://ai.google.dev), most notably in the [API reference](https://ai.google.dev/api).
6+
7+
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.
8+
9+
## Contents
10+
11+
| File | Description |
12+
| ---- | ----------- |
13+
| [cache.sh](./cache.sh) | Context caching |
14+
| [chat.sh](./chat.sh) | Multi-turn chat conversations |
15+
| [code_execution.sh](./code_execution.sh) | Executing code |
16+
| [configure_model_parameters.sh](./configure_model_parameters.sh) | Setting model parameters |
17+
| [controlled_generation.sh](./controlled_generation.sh) | Generating content with output constraints (e.g. JSON mode) |
18+
| [count_tokens.sh](./count_tokens.sh) | Counting input and output tokens |
19+
| [embed.sh](./embed.sh) | Generating embeddings |
20+
| [files.sh](./files.sh) | Managing files with the File API |
21+
| [function_calling.sh](./function_calling.sh) | Using function calling |
22+
| [models.sh](./models.sh) | Listing models and model metadata |
23+
| [safety_settings.sh](./safety_settings.sh) | Setting and using safety controls |
24+
| [system_instruction.sh](./system_instruction.sh) | Setting system instructions |
25+
| [text_generation.sh](./text_generation.sh) | Generating text |

0 commit comments

Comments
 (0)