diff --git a/samples/rest/controlled_generation.sh b/samples/rest/controlled_generation.sh new file mode 100644 index 000000000..69da2dac7 --- /dev/null +++ b/samples/rest/controlled_generation.sh @@ -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]