Skip to content

Commit

Permalink
Adding JSON schema curl samples (#434)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
shilpakancharla and MarkDaoust authored Jul 23, 2024
1 parent b19fc8c commit 032f78f
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions samples/rest/controlled_generation.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
set -eu

echo "json_controlled_generation"
# [START json_controlled_generation]
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro-latest:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"contents": [{
"parts":[
{"text": "List 5 popular cookie recipes"}
]
}],
"generationConfig": {
"response_mime_type": "application/json",
"response_schema": {
"type": "ARRAY",
"items": {
"type": "OBJECT",
"properties": {
"recipe_name": {"type":"STRING"},
}
}
}
}
}' 2> /dev/null | head
# [END json_controlled_generation]

echo "json_no_schema"
# [START json_no_schema]
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro-latest:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"contents": [{
"parts":[
{"text": "List a few popular cookie recipes using this JSON schema:
Recipe = {\"recipe_name\": str}
Return: list[Recipe]"
}
]
}],
"generationConfig": { "response_mime_type": "application/json" }
}' 2> /dev/null | head
# [END json_no_schema]

0 comments on commit 032f78f

Please sign in to comment.