Skip to content

Commit 032f78f

Browse files
Adding JSON schema curl samples (#434)
* Adding JSON schema curl samples json_no_schema working Fix quoting. * Update samples/rest/controlled_generation.sh * Fix quoting again. * use response_mime_type Change-Id: I29f337ddf8ee9ceff628111a9124cb4e5141706b --------- Co-authored-by: Mark Daoust <[email protected]>
1 parent b19fc8c commit 032f78f

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

samples/rest/controlled_generation.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
set -eu
2+
3+
echo "json_controlled_generation"
4+
# [START json_controlled_generation]
5+
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro-latest:generateContent?key=$GOOGLE_API_KEY" \
6+
-H 'Content-Type: application/json' \
7+
-d '{
8+
"contents": [{
9+
"parts":[
10+
{"text": "List 5 popular cookie recipes"}
11+
]
12+
}],
13+
"generationConfig": {
14+
"response_mime_type": "application/json",
15+
"response_schema": {
16+
"type": "ARRAY",
17+
"items": {
18+
"type": "OBJECT",
19+
"properties": {
20+
"recipe_name": {"type":"STRING"},
21+
}
22+
}
23+
}
24+
}
25+
}' 2> /dev/null | head
26+
# [END json_controlled_generation]
27+
28+
echo "json_no_schema"
29+
# [START json_no_schema]
30+
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro-latest:generateContent?key=$GOOGLE_API_KEY" \
31+
-H 'Content-Type: application/json' \
32+
-d '{
33+
"contents": [{
34+
"parts":[
35+
{"text": "List a few popular cookie recipes using this JSON schema:
36+
37+
Recipe = {\"recipe_name\": str}
38+
Return: list[Recipe]"
39+
}
40+
]
41+
}],
42+
"generationConfig": { "response_mime_type": "application/json" }
43+
}' 2> /dev/null | head
44+
# [END json_no_schema]

0 commit comments

Comments
 (0)