File tree Expand file tree Collapse file tree 2 files changed +20
-6
lines changed Expand file tree Collapse file tree 2 files changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ def test_chat(self):
31
31
]
32
32
)
33
33
response = chat .send_message ("I have 2 dogs in my house." )
34
- print (response .text )
34
+ print (response .text )
35
35
response = chat .send_message ("How many paws are in my house?" )
36
36
print (response .text )
37
37
# [END chat]
@@ -62,11 +62,14 @@ def test_chat_streaming_with_images(self):
62
62
model = genai .GenerativeModel ("gemini-1.5-flash" )
63
63
chat = model .start_chat ()
64
64
65
- response = chat .send_message ("Hello, I'm interested in learning about musical instruments. Can I show you one?" , stream = True )
65
+ response = chat .send_message (
66
+ "Hello, I'm interested in learning about musical instruments. Can I show you one?" ,
67
+ stream = True ,
68
+ )
66
69
for chunk in response :
67
70
print (chunk .text ) # Yes.
68
71
print ("_" * 80 )
69
-
72
+
70
73
organ = genai .upload_file (media / "organ.jpg" )
71
74
response = chat .send_message (
72
75
["What family of intruments does this instrument belong to?" , organ ], stream = True
Original file line number Diff line number Diff line change 16
16
17
17
18
18
class UnitTests (absltest .TestCase ):
19
- def test_controlled_generation (self ):
20
- # [START controlled_generation ]
19
+ def test_json_controlled_generation (self ):
20
+ # [START json_controlled_generation ]
21
21
import typing_extensions as typing
22
22
23
23
class Recipe (typing .TypedDict ):
@@ -31,7 +31,18 @@ class Recipe(typing.TypedDict):
31
31
),
32
32
)
33
33
print (result )
34
- # [END controlled_generation]
34
+ # [END json_controlled_generation]
35
+
36
+ def test_json_no_schema (self ):
37
+ # [START json_no_schema]
38
+ model = genai .GenerativeModel ("gemini-1.5-pro-latest" )
39
+ prompt = """List a few popular cookie recipes using this JSON schema:
40
+
41
+ Recipe = {'recipe_name': str}
42
+ Return: list[Recipe]"""
43
+ result = model .generate_content (prompt )
44
+ print (result )
45
+ # [END json_no_schema]
35
46
36
47
37
48
if __name__ == "__main__" :
You can’t perform that action at this time.
0 commit comments