|
1 | 1 | # Gemini API examples
|
2 | 2 |
|
3 |
| -This repo contains sample code for key features of the Gemini API. The repo is |
4 |
| -organized by programming language. |
5 |
| - |
6 |
| -These samples are embedded in parts of the |
7 |
| -[documentation](https://ai.google.dev), most notably in the |
8 |
| -[API reference](https://ai.google.dev/api). |
9 |
| - |
10 |
| -Each file is structured as a runnable test case, ensuring that samples are |
11 |
| -executable and functional. Each test demonstrates a single concept, and contains |
12 |
| -region tags that are used to demarcate the test scaffolding from the spotlight |
13 |
| -code. If you are contributing, code within region tags should follow sample code |
14 |
| -best practices - being clear, complete and concise. |
| 3 | +This repository contains example code for key features of the Gemini API. The |
| 4 | +repo is organized by programming language. |
| 5 | + |
| 6 | +The examples are embedded in the |
| 7 | +[Gemini API reference](https://ai.google.dev/api) and other places in the |
| 8 | +developer documentation. |
| 9 | + |
| 10 | +Each file is structured as a runnable test case, ensuring that examples are |
| 11 | +executable and functional. Each test demonstrates a single concept and contains |
| 12 | +special comments called _region tags_ that demarcate the test scaffolding from |
| 13 | +the example code snippet. Here's a Python example: |
| 14 | + |
| 15 | +```python |
| 16 | +def test_text_gen_text_only_prompt(self): |
| 17 | + # [START text_gen_text_only_prompt] |
| 18 | + from google import genai |
| 19 | + |
| 20 | + client = genai.Client() |
| 21 | + response = client.models.generate_content( |
| 22 | + model="gemini-2.0-flash", contents="Write a story about a magic backpack." |
| 23 | + ) |
| 24 | + print(response.text) |
| 25 | + # [END text_gen_text_only_prompt] |
| 26 | +``` |
| 27 | + |
| 28 | +The API reference can then be configured to show the code between the region |
| 29 | +tags. |
| 30 | + |
| 31 | +If you're contributing, please make sure that the code within region tags |
| 32 | +follows best practices for example code: clear, complete, and concise. |
0 commit comments