Skip to content

Commit 9c899fe

Browse files
authored
Merge pull request #13 from pcoet/cleanup
Cleanup
2 parents b16b4bb + a3d6915 commit 9c899fe

File tree

5 files changed

+25
-12
lines changed

5 files changed

+25
-12
lines changed

python/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Python examples
2+
3+
This directory contains examples of working with the Gemini API using the
4+
[Google Gen AI SDK for Python](https://googleapis.github.io/python-genai/).
5+
6+
## Install dependencies
7+
8+
pip install absl-py google-genai Pillow
9+
10+
## Run a test file
11+
12+
python <filename>.py

python/files.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717

1818
media = pathlib.Path(__file__).parents[1] / "third_party"
1919

20-
2120
class UnitTests(absltest.TestCase):
2221
def test_files_create_text(self):
2322
# [START files_create_text]
2423
from google import genai
24+
2525
client = genai.Client()
2626
myfile = client.files.upload(file=media / "poem.txt")
2727
print(f"{myfile=}")
@@ -36,6 +36,7 @@ def test_files_create_text(self):
3636
def test_files_create_image(self):
3737
# [START files_create_image]
3838
from google import genai
39+
3940
client = genai.Client()
4041
myfile = client.files.upload(file=media / "Cajun_instruments.jpg")
4142
print(f"{myfile=}")
@@ -50,6 +51,7 @@ def test_files_create_image(self):
5051
def test_files_create_audio(self):
5152
# [START files_create_audio]
5253
from google import genai
54+
5355
client = genai.Client()
5456
myfile = client.files.upload(file=media / "sample.mp3")
5557
print(f"{myfile=}")
@@ -87,6 +89,7 @@ def test_files_create_video(self):
8789
def test_files_create_pdf(self):
8890
# [START files_create_pdf]
8991
from google import genai
92+
9093
client = genai.Client()
9194
sample_pdf = client.files.upload(file=media / "test.pdf")
9295
response = client.models.generate_content(
@@ -118,6 +121,7 @@ def test_files_create_from_IO(self):
118121
def test_files_list(self):
119122
# [START files_list]
120123
from google import genai
124+
121125
client = genai.Client()
122126
print("My files:")
123127
for f in client.files.list():
@@ -127,6 +131,7 @@ def test_files_list(self):
127131
def test_files_get(self):
128132
# [START files_get]
129133
from google import genai
134+
130135
client = genai.Client()
131136
myfile = client.files.upload(file=media / "poem.txt")
132137
file_name = myfile.name
@@ -139,7 +144,7 @@ def test_files_get(self):
139144
def test_files_delete(self):
140145
# [START files_delete]
141146
from google import genai
142-
from google.api_core import exceptions
147+
143148
client = genai.Client()
144149
myfile = client.files.upload(file=media / "poem.txt")
145150

@@ -150,10 +155,10 @@ def test_files_delete(self):
150155
model="gemini-2.0-flash",
151156
contents=[myfile, "Describe this file."]
152157
)
158+
print(result)
153159
except genai.errors.ClientError:
154160
pass
155161
# [END files_delete]
156162

157-
158163
if __name__ == "__main__":
159164
absltest.main()

python/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class UnitTests(absltest.TestCase):
1818
def test_models_list(self):
1919
# [START models_list]
2020
from google import genai
21+
2122
client = genai.Client()
2223

2324
print("List of models that support generateContent:\n")
@@ -36,6 +37,7 @@ def test_models_list(self):
3637
def test_models_get(self):
3738
# [START models_get]
3839
from google import genai
40+
3941
client = genai.Client()
4042
model_info = client.models.get(model="gemini-2.0-flash")
4143
print(model_info)

python/safety_settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def test_safety_settings(self):
1919
# [START safety_settings]
2020
from google import genai
2121
from google.genai import types
22+
2223
client = genai.Client()
2324
unsafe_prompt = (
2425
"I support Martians Soccer Club and I think Jupiterians Football Club sucks! "
@@ -45,6 +46,7 @@ def test_safety_settings_multi(self):
4546
# [START safety_settings_multi]
4647
from google import genai
4748
from google.genai import types
49+
4850
client = genai.Client()
4951
unsafe_prompt = (
5052
"I support Martians Soccer Club and I think Jupiterians Football Club sucks! "

python/text_generation.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15-
from absl.testing import absltest
1615

1716
import pathlib
17+
from absl.testing import absltest
1818

1919
media = pathlib.Path(__file__).parents[1] / "third_party"
2020

21-
2221
class UnitTests(absltest.TestCase):
2322
def test_text_gen_text_only_prompt(self):
2423
# [START text_gen_text_only_prompt]
@@ -49,7 +48,6 @@ def test_text_gen_text_only_prompt_streaming(self):
4948
def test_text_gen_multimodal_one_image_prompt(self):
5049
# [START text_gen_multimodal_one_image_prompt]
5150
from google import genai
52-
5351
import PIL.Image
5452

5553
client = genai.Client()
@@ -64,7 +62,6 @@ def test_text_gen_multimodal_one_image_prompt(self):
6462
def test_text_gen_multimodal_one_image_prompt_streaming(self):
6563
# [START text_gen_multimodal_one_image_prompt_streaming]
6664
from google import genai
67-
6865
import PIL.Image
6966

7067
client = genai.Client()
@@ -81,7 +78,6 @@ def test_text_gen_multimodal_one_image_prompt_streaming(self):
8178
def test_text_gen_multimodal_multi_image_prompt(self):
8279
# [START text_gen_multimodal_multi_image_prompt]
8380
from google import genai
84-
8581
import PIL.Image
8682

8783
client = genai.Client()
@@ -97,7 +93,6 @@ def test_text_gen_multimodal_multi_image_prompt(self):
9793
def test_text_gen_multimodal_multi_image_prompt_streaming(self):
9894
# [START text_gen_multimodal_multi_image_prompt_streaming]
9995
from google import genai
100-
10196
import PIL.Image
10297

10398
client = genai.Client()
@@ -143,7 +138,6 @@ def test_text_gen_multimodal_audio_streaming(self):
143138
def test_text_gen_multimodal_video_prompt(self):
144139
# [START text_gen_multimodal_video_prompt]
145140
from google import genai
146-
147141
import time
148142

149143
client = genai.Client()
@@ -167,7 +161,6 @@ def test_text_gen_multimodal_video_prompt(self):
167161
def test_text_gen_multimodal_video_prompt_streaming(self):
168162
# [START text_gen_multimodal_video_prompt_streaming]
169163
from google import genai
170-
171164
import time
172165

173166
client = genai.Client()
@@ -219,6 +212,5 @@ def test_text_gen_multimodal_pdf_streaming(self):
219212
print("_" * 80)
220213
# [END text_gen_multimodal_pdf_streaming]
221214

222-
223215
if __name__ == "__main__":
224216
absltest.main()

0 commit comments

Comments
 (0)