Skip to content

Commit 4721b15

Browse files
Model list and get samples (#404)
1 parent 7bd2daa commit 4721b15

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

samples/models.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2023 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
from absl.testing import absltest
16+
17+
import google.generativeai as genai
18+
19+
20+
class UnitTests(absltest.TestCase):
21+
def test_models_list(self):
22+
# [START models_list]
23+
print("List of models that support generateContent:\n")
24+
for m in genai.list_models():
25+
if "generateContent" in m.supported_generation_methods:
26+
print(m.name)
27+
28+
print("List of models that support embedContent:\n")
29+
for m in genai.list_models():
30+
if "embedContent" in m.supported_generation_methods:
31+
print(m.name)
32+
# [END models_list]
33+
34+
def test_models_get(self):
35+
# [START models_get]
36+
model_info = genai.get_model("models/gemini-1.5-flash-latest")
37+
print(model_info)
38+
# [END models_get]
39+
40+
41+
if __name__ == "__main__":
42+
absltest.main()

0 commit comments

Comments
 (0)