From c7155d2fc3d522d7e77c269176eaa2e10df074aa Mon Sep 17 00:00:00 2001 From: David Huntsperger <5672572+pcoet@users.noreply.github.com> Date: Thu, 12 Sep 2024 06:10:13 -0700 Subject: [PATCH 1/2] Update prompt in json_no_schema snippet Make this match the other language snippets. Tested the change on my machine, and the output is as expected: `[{"recipeName": "Chocolate Chip Cookies"}, {"recipeName": "Peanut Butter Cookies"}, {"recipeName": "Oatmeal Raisin Cookies"}, {"recipeName": "Sugar Cookies"}, {"recipeName": "Snickerdoodles"}]` --- genai/internal/samples/docs-snippets_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/genai/internal/samples/docs-snippets_test.go b/genai/internal/samples/docs-snippets_test.go index 92ee450..4e6a0d1 100644 --- a/genai/internal/samples/docs-snippets_test.go +++ b/genai/internal/samples/docs-snippets_test.go @@ -942,7 +942,10 @@ func ExampleGenerativeModel_jSONNoSchema() { model := client.GenerativeModel("gemini-1.5-pro-latest") // Ask the model to respond with JSON. model.ResponseMIMEType = "application/json" - resp, err := model.GenerateContent(ctx, genai.Text("List a few popular cookie recipes.")) + prompt := `List a few popular cookie recipes using this JSON schema: + Recipe = {'recipeName': string} + Return: Array` + resp, err := model.GenerateContent(ctx, genai.Text(prompt)) if err != nil { log.Fatal(err) } From 1cc9fcdca66e47ad7d485469d1e1c6c4a7f69662 Mon Sep 17 00:00:00 2001 From: pcoet Date: Thu, 12 Sep 2024 06:50:47 -0700 Subject: [PATCH 2/2] running go:generate for examples --- genai/example_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/genai/example_test.go b/genai/example_test.go index 184eb7c..cd225b0 100644 --- a/genai/example_test.go +++ b/genai/example_test.go @@ -912,7 +912,10 @@ func ExampleGenerativeModel_jSONNoSchema() { model := client.GenerativeModel("gemini-1.5-pro-latest") // Ask the model to respond with JSON. model.ResponseMIMEType = "application/json" - resp, err := model.GenerateContent(ctx, genai.Text("List a few popular cookie recipes.")) + prompt := `List a few popular cookie recipes using this JSON schema: + Recipe = {'recipeName': string} + Return: Array` + resp, err := model.GenerateContent(ctx, genai.Text(prompt)) if err != nil { log.Fatal(err) }