From 865d240e085c273eecc7c22b9dc142c541e868d6 Mon Sep 17 00:00:00 2001 From: Shilpa Kancharla Date: Wed, 3 Jul 2024 18:53:30 -0400 Subject: [PATCH 1/4] Adding JSON schema curl samples json_no_schema working Fix quoting. --- samples/rest/controlled_generation.sh | 43 +++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 samples/rest/controlled_generation.sh diff --git a/samples/rest/controlled_generation.sh b/samples/rest/controlled_generation.sh new file mode 100644 index 000000000..e88bcaa28 --- /dev/null +++ b/samples/rest/controlled_generation.sh @@ -0,0 +1,43 @@ +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]" + } + ], + }] +}' 2> /dev/null | head +# [END json_no_schema] From 534a544be627010b6b45b0c73d1a4fd7b5a4053b Mon Sep 17 00:00:00 2001 From: Mark Daoust Date: Tue, 23 Jul 2024 15:28:24 -0700 Subject: [PATCH 2/4] Update samples/rest/controlled_generation.sh --- samples/rest/controlled_generation.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/rest/controlled_generation.sh b/samples/rest/controlled_generation.sh index e88bcaa28..e849bfa65 100644 --- a/samples/rest/controlled_generation.sh +++ b/samples/rest/controlled_generation.sh @@ -34,7 +34,7 @@ curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro-lat "parts":[ {"text": "List a few popular cookie recipes using this JSON schema: - Recipe = {'recipe_name': str} + Recipe = {"recipe_name": str} Return: list[Recipe]" } ], From 4ef4458d422e87a86ec05ecb647ec3bbc8d0723c Mon Sep 17 00:00:00 2001 From: Mark Daoust Date: Tue, 23 Jul 2024 15:31:45 -0700 Subject: [PATCH 3/4] Fix quoting again. --- samples/rest/controlled_generation.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/rest/controlled_generation.sh b/samples/rest/controlled_generation.sh index e849bfa65..2b442ee66 100644 --- a/samples/rest/controlled_generation.sh +++ b/samples/rest/controlled_generation.sh @@ -34,9 +34,9 @@ curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro-lat "parts":[ {"text": "List a few popular cookie recipes using this JSON schema: - Recipe = {"recipe_name": str} + Recipe = {\"recipe_name\": str} Return: list[Recipe]" - } + } ], }] }' 2> /dev/null | head From 1d4ad90674473291aa8bcb067b753626dac70431 Mon Sep 17 00:00:00 2001 From: Mark Daoust Date: Tue, 23 Jul 2024 15:38:14 -0700 Subject: [PATCH 4/4] use response_mime_type Change-Id: I29f337ddf8ee9ceff628111a9124cb4e5141706b --- samples/rest/controlled_generation.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/samples/rest/controlled_generation.sh b/samples/rest/controlled_generation.sh index 2b442ee66..69da2dac7 100644 --- a/samples/rest/controlled_generation.sh +++ b/samples/rest/controlled_generation.sh @@ -34,10 +34,11 @@ curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro-lat "parts":[ {"text": "List a few popular cookie recipes using this JSON schema: - Recipe = {\"recipe_name\": str} - Return: list[Recipe]" - } - ], - }] + Recipe = {\"recipe_name\": str} + Return: list[Recipe]" + } + ] + }], + "generationConfig": { "response_mime_type": "application/json" } }' 2> /dev/null | head # [END json_no_schema]