Pembuatan terkontrol

Anda dapat menjamin bahwa output yang dihasilkan model selalu mematuhi skema tertentu sehingga Anda menerima respons yang diformat secara konsisten. Misalnya, Anda mungkin memiliki skema data yang sudah ditetapkan yang Anda gunakan untuk tugas lain. Jika membuat model mengikuti skema yang sama, Anda dapat langsung mengekstrak data dari output model tanpa pascapemrosesan apa pun.

Untuk menentukan struktur output model, tentukan skema respons, yang berfungsi seperti cetak biru untuk respons model. Saat Anda mengirimkan perintah dan menyertakan skema respons, respons model akan selalu mengikuti skema yang Anda tentukan.

Anda dapat mengontrol output yang dihasilkan saat menggunakan model berikut:

Contoh kasus penggunaan

Salah satu kasus penggunaan untuk menerapkan skema respons adalah memastikan bahwa respons model menghasilkan JSON yang valid dan sesuai dengan skema Anda. Output model generatif dapat memiliki beberapa tingkat variabilitas, sehingga menyertakan skema respons memastikan bahwa Anda selalu menerima JSON yang valid. Akibatnya, tugas downstream Anda dapat mengharapkan input JSON yang valid dari respons yang dihasilkan dengan andal.

Contoh lainnya adalah membatasi cara model merespons. Misalnya, Anda dapat meminta model menganotasi teks dengan label yang ditentukan pengguna, bukan dengan label yang dibuat model. Batasan ini berguna saat Anda mengharapkan kumpulan label tertentu seperti positive atau negative dan tidak ingin menerima campuran label lain yang mungkin dihasilkan model seperti good, positive, negative, atau bad.

Pertimbangan

Pertimbangan berikut membahas potensi batasan jika Anda berencana menggunakan skema respons:

  • Anda harus menggunakan API untuk menentukan dan menggunakan skema respons. Tidak ada dukungan konsol.
  • Ukuran skema respons Anda diperhitungkan dalam batas token input.
  • Hanya format output tertentu yang didukung, seperti application/json atau text/x.enum. Untuk informasi selengkapnya, lihat parameter responseMimeType di referensi Gemini API.
  • Pembuatan terkontrol mendukung sebagian referensi skema Vertex AI. Untuk mengetahui informasi selengkapnya, lihat Bidang skema yang didukung.
  • Skema yang kompleks dapat menyebabkan error InvalidArgument: 400. Kompleksitas mungkin berasal dari nama properti yang panjang, batas panjang array yang panjang, enum dengan banyak nilai, objek dengan banyak properti opsional, atau kombinasi faktor-faktor ini.

    Jika Anda mendapatkan error ini dengan skema yang valid, lakukan satu atau beberapa perubahan berikut untuk mengatasi error:

    • Persingkat nama properti atau nama enum.
    • Meratakan array bertingkat.
    • Kurangi jumlah properti dengan batasan, seperti angka dengan batas minimum dan maksimum.
    • Kurangi jumlah properti dengan batasan yang kompleks, seperti properti dengan format yang kompleks seperti date-time.
    • Kurangi jumlah properti opsional.
    • Kurangi jumlah nilai yang valid untuk enum.

Kolom skema yang didukung

Pembuatan terkontrol mendukung kolom berikut dari skema Vertex AI. Jika Anda menggunakan kolom yang tidak didukung, Vertex AI masih dapat menangani permintaan Anda, tetapi mengabaikan kolom tersebut.

  • anyOf
  • enum
  • format
  • items
  • maximum
  • maxItems
  • minimum
  • minItems
  • nullable
  • properties
  • propertyOrdering*
  • required

* propertyOrdering khusus untuk pembuatan terkontrol dan bukan bagian dari skema Vertex AI. Kolom ini menentukan urutan pembuatan properti. Properti yang tercantum harus unik dan harus kunci yang valid dalam kamus properties.

Untuk kolom format, Vertex AI mendukung nilai berikut: date, date-time, duration, dan time. Deskripsi dan format setiap nilai dijelaskan dalam OpenAPI Initiative Registry

Sebelum memulai

Tentukan skema respons untuk menentukan struktur output model, nama kolom, dan jenis data yang diharapkan untuk setiap kolom. Hanya gunakan kolom yang didukung seperti yang tercantum di bagian Pertimbangan. Semua kolom lainnya akan diabaikan.

Sertakan skema respons Anda sebagai bagian dari kolom responseSchema saja. Jangan menduplikasi skema dalam perintah input Anda. Jika Anda melakukannya, kualitas output yang dihasilkan mungkin lebih rendah.

Untuk contoh skema, lihat bagian Contoh skema dan respons model.

Perilaku model dan skema respons

Saat menghasilkan respons, model menggunakan nama kolom dan konteks dari perintah Anda. Oleh karena itu, sebaiknya gunakan struktur yang jelas dan nama kolom yang tidak ambigu sehingga intent Anda jelas.

Secara default, kolom bersifat opsional, yang berarti model dapat mengisi kolom atau melewati kolom tersebut. Anda dapat menetapkan kolom sesuai kebutuhan untuk memaksa model memberikan nilai. Jika tidak ada cukup konteks dalam perintah input terkait, model akan menghasilkan respons terutama berdasarkan data yang digunakan untuk melatihnya.

Jika Anda tidak melihat hasil yang diharapkan, tambahkan lebih banyak konteks ke perintah input atau revisi skema respons Anda. Misalnya, tinjau respons model tanpa pembuatan terkontrol untuk melihat respons model. Kemudian, Anda dapat memperbarui skema respons yang lebih sesuai dengan output model.

Mengirim perintah dengan skema respons

Secara default, semua kolom bersifat opsional, yang berarti model dapat menghasilkan respons ke kolom. Untuk memaksa model agar selalu menghasilkan respons ke kolom, tetapkan kolom sesuai kebutuhan.

Gen AI SDK for Python

Instal

pip install --upgrade google-genai

Untuk mempelajari lebih lanjut, lihat dokumentasi referensi SDK.

Tetapkan variabel lingkungan untuk menggunakan Gen AI SDK dengan Vertex AI:

# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values
# with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT
export GOOGLE_CLOUD_LOCATION=global
export GOOGLE_GENAI_USE_VERTEXAI=True

from google import genai
from google.genai.types import HttpOptions

response_schema = {
    "type": "ARRAY",
    "items": {
        "type": "OBJECT",
        "properties": {
            "recipe_name": {"type": "STRING"},
            "ingredients": {"type": "ARRAY", "items": {"type": "STRING"}},
        },
        "required": ["recipe_name", "ingredients"],
    },
}

prompt = """
    List a few popular cookie recipes.
"""

client = genai.Client(http_options=HttpOptions(api_version="v1"))
response = client.models.generate_content(
    model="gemini-2.0-flash-001",
    contents=prompt,
    config={
        "response_mime_type": "application/json",
        "response_schema": response_schema,
    },
)

print(response.text)
# Example output:
# [
#     {
#         "ingredients": [
#             "2 1/4 cups all-purpose flour",
#             "1 teaspoon baking soda",
#             "1 teaspoon salt",
#             "1 cup (2 sticks) unsalted butter, softened",
#             "3/4 cup granulated sugar",
#             "3/4 cup packed brown sugar",
#             "1 teaspoon vanilla extract",
#             "2 large eggs",
#             "2 cups chocolate chips",
#         ],
#         "recipe_name": "Chocolate Chip Cookies",
#     }
# ]

Gen AI SDK for Go

Pelajari cara menginstal atau mengupdate Gen AI SDK for Go.

Untuk mempelajari lebih lanjut, lihat dokumentasi referensi SDK.

Tetapkan variabel lingkungan untuk menggunakan Gen AI SDK dengan Vertex AI:

# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values
# with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT
export GOOGLE_CLOUD_LOCATION=global
export GOOGLE_GENAI_USE_VERTEXAI=True

import (
	"context"
	"fmt"
	"io"

	genai "google.golang.org/genai"
)

// generateWithRespSchema shows how to use a response schema to generate output in a specific format.
func generateWithRespSchema(w io.Writer) error {
	ctx := context.Background()

	client, err := genai.NewClient(ctx, &genai.ClientConfig{
		HTTPOptions: genai.HTTPOptions{APIVersion: "v1"},
	})
	if err != nil {
		return fmt.Errorf("failed to create genai client: %w", err)
	}

	config := &genai.GenerateContentConfig{
		ResponseMIMEType: "application/json",
		// See the OpenAPI specification for more details and examples:
		//   https://spec.openapis.org/oas/v3.0.3.html#schema-object
		ResponseSchema: &genai.Schema{
			Type: "array",
			Items: &genai.Schema{
				Type: "object",
				Properties: map[string]*genai.Schema{
					"recipe_name": {Type: "string"},
					"ingredients": {
						Type:  "array",
						Items: &genai.Schema{Type: "string"},
					},
				},
				Required: []string{"recipe_name", "ingredients"},
			},
		},
	}
	contents := []*genai.Content{
		{Parts: []*genai.Part{
			{Text: "List a few popular cookie recipes."},
		}},
	}
	modelName := "gemini-2.0-flash-001"

	resp, err := client.Models.GenerateContent(ctx, modelName, contents, config)
	if err != nil {
		return fmt.Errorf("failed to generate content: %w", err)
	}

	respText, err := resp.Text()
	if err != nil {
		return fmt.Errorf("failed to convert model response to text: %w", err)
	}
	fmt.Fprintln(w, respText)

	// Example response:
	// [
	//   {
	//     "ingredients": [
	//       "2 1/4 cups all-purpose flour",
	//       "1 teaspoon baking soda",
	//       ...
	//     ],
	//     "recipe_name": "Chocolate Chip Cookies"
	//   },
	//   {
	//     ...
	//   },
	//   ...
	// ]

	return nil
}

REST

Sebelum menggunakan salah satu data permintaan, lakukan penggantian berikut:

  • GENERATE_RESPONSE_METHOD: Jenis respons yang ingin Anda hasilkan dari model. Pilih metode yang menghasilkan cara Anda ingin respons model ditampilkan:
    • streamGenerateContent: Respons di-streaming saat dibuat untuk mengurangi persepsi latensi bagi audiens manusia.
    • generateContent: Respons ditampilkan setelah sepenuhnya dibuat.
  • LOCATION: Region untuk memproses permintaan.
  • PROJECT_ID: Project ID Anda.
  • MODEL_ID: ID model multimodal yang ingin Anda gunakan.
  • ROLE: Peran dalam percakapan yang terkait dengan konten. Menentukan peran diperlukan bahkan dalam kasus penggunaan satu giliran. Nilai yang dapat diterima mencakup hal berikut:
    • USER: Menentukan konten yang dikirim oleh Anda.
  • TEXT: Petunjuk teks yang akan disertakan dalam perintah.
  • RESPONSE_MIME_TYPE: Jenis format teks kandidat yang dihasilkan. Untuk mengetahui daftar nilai yang didukung, lihat parameter responseMimeType di Gemini API.
  • RESPONSE_SCHEMA: Skema untuk model yang akan diikuti saat membuat respons. Untuk mengetahui informasi selengkapnya, lihat referensi Skema.

Metode HTTP dan URL:

POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/MODEL_ID:GENERATE_RESPONSE_METHOD

Isi JSON permintaan:

{
  "contents": {
    "role": "ROLE",
    "parts": {
      "text": "TEXT"
    }
  },
  "generation_config": {
    "responseMimeType": "RESPONSE_MIME_TYPE",
    "responseSchema": RESPONSE_SCHEMA,
  }
}

Untuk mengirim permintaan Anda, pilih salah satu opsi berikut:

curl

Simpan isi permintaan dalam file bernama request.json, dan jalankan perintah berikut:

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/MODEL_ID:GENERATE_RESPONSE_METHOD"

PowerShell

Simpan isi permintaan dalam file bernama request.json, dan jalankan perintah berikut:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/MODEL_ID:GENERATE_RESPONSE_METHOD" | Select-Object -Expand Content

Anda akan melihat respons JSON yang mirip seperti berikut:

Contoh perintah curl

LOCATION="us-central1"
MODEL_ID="gemini-2.0-flash"
PROJECT_ID="test-project"
GENERATE_RESPONSE_METHOD="generateContent"

cat << EOF > request.json
{
  "contents": {
    "role": "user",
    "parts": {
      "text": "List a few popular cookie recipes."
    }
  },
  "generation_config": {
    "maxOutputTokens": 2048,
    "responseMimeType": "application/json",
    "responseSchema": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "recipe_name": {
            "type": "string",
          },
        },
        "required": ["recipe_name"],
      },
    }
  }
}
EOF

curl \
-X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
https://${LOCATION}-aiplatform.googleapis.com/v1/projects/${PROJECT_ID}/locations/${LOCATION}/publishers/google/models/${MODEL_ID}:${GENERATE_RESPONSE_METHOD} \
-d '@request.json'

Contoh skema untuk output JSON

Bagian berikut menunjukkan berbagai contoh perintah dan skema respons. Contoh respons model juga disertakan setelah setiap contoh kode.

Memperkirakan cuaca untuk setiap hari dalam seminggu

Contoh berikut menghasilkan objek forecast untuk setiap hari dalam seminggu yang menyertakan array properti seperti perkiraan suhu dan tingkat kelembapan untuk hari tersebut. Beberapa properti ditetapkan ke nullable sehingga model dapat menampilkan nilai null jika tidak memiliki konteks yang memadai untuk menghasilkan respons yang bermakna. Strategi ini membantu mengurangi halusinasi.

Gen AI SDK for Python

Instal

pip install --upgrade google-genai

Untuk mempelajari lebih lanjut, lihat dokumentasi referensi SDK.

Tetapkan variabel lingkungan untuk menggunakan Gen AI SDK dengan Vertex AI:

# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values
# with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT
export GOOGLE_CLOUD_LOCATION=global
export GOOGLE_GENAI_USE_VERTEXAI=True

from google import genai
from google.genai.types import GenerateContentConfig, HttpOptions

response_schema = {
    "type": "OBJECT",
    "properties": {
        "forecast": {
            "type": "ARRAY",
            "items": {
                "type": "OBJECT",
                "properties": {
                    "Day": {"type": "STRING", "nullable": True},
                    "Forecast": {"type": "STRING", "nullable": True},
                    "Temperature": {"type": "INTEGER", "nullable": True},
                    "Humidity": {"type": "STRING", "nullable": True},
                    "Wind Speed": {"type": "INTEGER", "nullable": True},
                },
                "required": ["Day", "Temperature", "Forecast", "Wind Speed"],
            },
        }
    },
}

prompt = """
    The week ahead brings a mix of weather conditions.
    Sunday is expected to be sunny with a temperature of 77°F and a humidity level of 50%. Winds will be light at around 10 km/h.
    Monday will see partly cloudy skies with a slightly cooler temperature of 72°F and the winds will pick up slightly to around 15 km/h.
    Tuesday brings rain showers, with temperatures dropping to 64°F and humidity rising to 70%.
    Wednesday may see thunderstorms, with a temperature of 68°F.
    Thursday will be cloudy with a temperature of 66°F and moderate humidity at 60%.
    Friday returns to partly cloudy conditions, with a temperature of 73°F and the Winds will be light at 12 km/h.
    Finally, Saturday rounds off the week with sunny skies, a temperature of 80°F, and a humidity level of 40%. Winds will be gentle at 8 km/h.
"""

client = genai.Client(http_options=HttpOptions(api_version="v1"))
response = client.models.generate_content(
    model="gemini-2.0-flash-001",
    contents=prompt,
    config=GenerateContentConfig(
        response_mime_type="application/json",
        response_schema=response_schema,
    ),
)

print(response.text)
# Example output:
# {"forecast": [{"Day": "Sunday", "Forecast": "sunny", "Temperature": 77, "Wind Speed": 10, "Humidity": "50%"},
#   {"Day": "Monday", "Forecast": "partly cloudy", "Temperature": 72, "Wind Speed": 15},
#   {"Day": "Tuesday", "Forecast": "rain showers", "Temperature": 64, "Wind Speed": null, "Humidity": "70%"},
#   {"Day": "Wednesday", "Forecast": "thunderstorms", "Temperature": 68, "Wind Speed": null},
#   {"Day": "Thursday", "Forecast": "cloudy", "Temperature": 66, "Wind Speed": null, "Humidity": "60%"},
#   {"Day": "Friday", "Forecast": "partly cloudy", "Temperature": 73, "Wind Speed": 12},
#   {"Day": "Saturday", "Forecast": "sunny", "Temperature": 80, "Wind Speed": 8, "Humidity": "40%"}]}

Gen AI SDK for Go

Pelajari cara menginstal atau mengupdate Gen AI SDK for Go.

Untuk mempelajari lebih lanjut, lihat dokumentasi referensi SDK.

Tetapkan variabel lingkungan untuk menggunakan Gen AI SDK dengan Vertex AI:

# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values
# with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT
export GOOGLE_CLOUD_LOCATION=global
export GOOGLE_GENAI_USE_VERTEXAI=True

import (
	"context"
	"fmt"
	"io"

	genai "google.golang.org/genai"
)

// generateWithNullables shows how to use the response schema with nullable values.
func generateWithNullables(w io.Writer) error {
	ctx := context.Background()

	client, err := genai.NewClient(ctx, &genai.ClientConfig{
		HTTPOptions: genai.HTTPOptions{APIVersion: "v1"},
	})
	if err != nil {
		return fmt.Errorf("failed to create genai client: %w", err)
	}

	modelName := "gemini-2.0-flash-001"
	prompt := `
The week ahead brings a mix of weather conditions.
Sunday is expected to be sunny with a temperature of 77°F and a humidity level of 50%. Winds will be light at around 10 km/h.
Monday will see partly cloudy skies with a slightly cooler temperature of 72°F and the winds will pick up slightly to around 15 km/h.
Tuesday brings rain showers, with temperatures dropping to 64°F and humidity rising to 70%.
Wednesday may see thunderstorms, with a temperature of 68°F.
Thursday will be cloudy with a temperature of 66°F and moderate humidity at 60%.
Friday returns to partly cloudy conditions, with a temperature of 73°F and the Winds will be light at 12 km/h.
Finally, Saturday rounds off the week with sunny skies, a temperature of 80°F, and a humidity level of 40%. Winds will be gentle at 8 km/h.
`
	contents := []*genai.Content{
		{Parts: []*genai.Part{
			{Text: prompt},
		}},
	}
	config := &genai.GenerateContentConfig{
		ResponseMIMEType: "application/json",
		// See the OpenAPI specification for more details and examples:
		//   https://spec.openapis.org/oas/v3.0.3.html#schema-object
		ResponseSchema: &genai.Schema{
			Type: "object",
			Properties: map[string]*genai.Schema{
				"forecast": {
					Type: "array",
					Items: &genai.Schema{
						Type: "object",
						Properties: map[string]*genai.Schema{
							"Day":         {Type: "string", Nullable: true},
							"Forecast":    {Type: "string", Nullable: true},
							"Temperature": {Type: "integer", Nullable: true},
							"Humidity":    {Type: "string", Nullable: true},
							"Wind Speed":  {Type: "integer", Nullable: true},
						},
						Required: []string{"Day", "Temperature", "Forecast", "Wind Speed"},
					},
				},
			},
		},
	}

	resp, err := client.Models.GenerateContent(ctx, modelName, contents, config)
	if err != nil {
		return fmt.Errorf("failed to generate content: %w", err)
	}

	respText, err := resp.Text()
	if err != nil {
		return fmt.Errorf("failed to convert model response to text: %w", err)
	}
	fmt.Fprintln(w, respText)

	// Example response:
	// {
	// 	"forecast": [
	// 		{"Day": "Sunday", "Forecast": "Sunny", "Temperature": 77, "Wind Speed": 10, "Humidity": "50%"},
	// 		{"Day": "Monday", "Forecast": "Partly Cloudy", "Temperature": 72, "Wind Speed": 15},
	// 		{"Day": "Tuesday", "Forecast": "Rain Showers", "Temperature": 64, "Wind Speed": null, "Humidity": "70%"},
	// 		{"Day": "Wednesday", "Forecast": "Thunderstorms", "Temperature": 68, "Wind Speed": null},
	// 		{"Day": "Thursday", "Forecast": "Cloudy", "Temperature": 66, "Wind Speed": null, "Humidity": "60%"},
	// 		{"Day": "Friday", "Forecast": "Partly Cloudy", "Temperature": 73, "Wind Speed": 12},
	// 		{"Day": "Saturday", "Forecast": "Sunny", "Temperature": 80, "Wind Speed": 8, "Humidity": "40%"}
	// 	]
	// }

	return nil
}

Mengklasifikasikan produk

Contoh berikut menyertakan enum tempat model harus mengklasifikasikan jenis dan kondisi objek dari daftar nilai yang diberikan.

Gen AI SDK for Python

Instal

pip install --upgrade google-genai

Untuk mempelajari lebih lanjut, lihat dokumentasi referensi SDK.

Tetapkan variabel lingkungan untuk menggunakan Gen AI SDK dengan Vertex AI:

# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values
# with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT
export GOOGLE_CLOUD_LOCATION=global
export GOOGLE_GENAI_USE_VERTEXAI=True

from google import genai
from google.genai.types import GenerateContentConfig, HttpOptions

client = genai.Client(http_options=HttpOptions(api_version="v1"))
response = client.models.generate_content(
    model="gemini-2.0-flash-001",
    contents="What type of instrument is an oboe?",
    config=GenerateContentConfig(
        response_mime_type="text/x.enum",
        response_schema={
            "type": "STRING",
            "enum": ["Percussion", "String", "Woodwind", "Brass", "Keyboard"],
        },
    ),
)

print(response.text)
# Example output:
# Woodwind

Gen AI SDK for Go

Pelajari cara menginstal atau mengupdate Gen AI SDK for Go.

Untuk mempelajari lebih lanjut, lihat dokumentasi referensi SDK.

Tetapkan variabel lingkungan untuk menggunakan Gen AI SDK dengan Vertex AI:

# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values
# with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT
export GOOGLE_CLOUD_LOCATION=global
export GOOGLE_GENAI_USE_VERTEXAI=True

import (
	"context"
	"fmt"
	"io"

	genai "google.golang.org/genai"
)

// generateWithEnumSchema shows how to use enum schema to generate output.
func generateWithEnumSchema(w io.Writer) error {
	ctx := context.Background()

	client, err := genai.NewClient(ctx, &genai.ClientConfig{
		HTTPOptions: genai.HTTPOptions{APIVersion: "v1"},
	})
	if err != nil {
		return fmt.Errorf("failed to create genai client: %w", err)
	}

	modelName := "gemini-2.0-flash-001"
	contents := []*genai.Content{
		{Parts: []*genai.Part{
			{Text: "What type of instrument is an oboe?"},
		}},
	}
	config := &genai.GenerateContentConfig{
		ResponseMIMEType: "text/x.enum",
		ResponseSchema: &genai.Schema{
			Type: "STRING",
			Enum: []string{"Percussion", "String", "Woodwind", "Brass", "Keyboard"},
		},
	}

	resp, err := client.Models.GenerateContent(ctx, modelName, contents, config)
	if err != nil {
		return fmt.Errorf("failed to generate content: %w", err)
	}

	respText, err := resp.Text()
	if err != nil {
		return fmt.Errorf("failed to convert model response to text: %w", err)
	}
	fmt.Fprintln(w, respText)

	// Example response:
	// Woodwind

	return nil
}