A partire dal 29 aprile 2025, i modelli Gemini 1.5 Pro e Gemini 1.5 Flash non sono disponibili nei progetti che non li hanno mai utilizzati, inclusi i nuovi progetti. Per maggiori dettagli, vedi
Versioni e ciclo di vita dei modelli.
Output JSON di generazione controllata con enum
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Restituisce un oggetto formattato in JSON con un valore enum, data una descrizione dell'oggetto e un elenco di valori tra cui scegliere.
Esempio di codice
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],[],[],[],null,["# Controlled generation JSON output with enum\n\nOutput JSON formatted object with an enum value, given a description of the object and a list of values to choose from.\n\nCode sample\n-----------\n\n### C#\n\n\nBefore trying this sample, follow the C# setup instructions in the\n[Vertex AI quickstart using\nclient libraries](/vertex-ai/docs/start/client-libraries).\n\n\nFor more information, see the\n[Vertex AI C# API\nreference documentation](/dotnet/docs/reference/Google.Cloud.AIPlatform.V1/latest).\n\n\nTo authenticate to Vertex AI, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n public async Task\u003cstring\u003e GenerateContentWithResponseSchema4(\n string projectId = \"your-project-id\",\n string location = \"us-central1\",\n string publisher = \"google\",\n string model = \"gemini-2.0-flash-001\")\n {\n\n var predictionServiceClient = new PredictionServiceClientBuilder\n {\n Endpoint = $\"{location}-aiplatform.googleapis.com\"\n }.Build();\n\n var responseSchema = new OpenApiSchema\n {\n Type = Type.Array,\n Items = new()\n {\n Type = Type.Object,\n Properties =\n {\n [\"to_discard\"] = new() { Type = Type.Integer },\n [\"subcategory\"] = new() { Type = Type.String },\n [\"safe_handling\"] = new() { Type = Type.Integer },\n [\"item_category\"] = new()\n {\n Type = Type.String,\n Enum =\n {\n \"clothing\",\n \"winter apparel\",\n \"specialized apparel\",\n \"furniture\",\n \"decor\",\n \"tableware\",\n \"cookware\",\n \"toys\"\n }\n },\n [\"for_resale\"] = new() { Type = Type.Integer },\n [\"condition\"] = new()\n {\n Type = Type.String,\n Enum =\n {\n \"new in package\",\n \"like new\",\n \"gently used\",\n \"used\",\n \"damaged\",\n \"soiled\"\n }\n }\n }\n }\n };\n\n string prompt = @\"\n Item description:\n The item is a long winter coat that has many tears all around the seams and is falling apart.\n It has large questionable stains on it.\";\n\n var generateContentRequest = new GenerateContentRequest\n {\n Model = $\"projects/{projectId}/locations/{location}/publishers/{publisher}/models/{model}\",\n Contents =\n {\n new Content\n {\n Role = \"USER\",\n Parts =\n {\n new Part { Text = prompt }\n }\n }\n },\n GenerationConfig = new GenerationConfig\n {\n ResponseMimeType = \"application/json\",\n ResponseSchema = responseSchema\n },\n };\n\n GenerateContentResponse response = await predictionServiceClient.GenerateContentAsync(generateContentRequest);\n\n string responseText = response.Candidates[0].Content.Parts[0].Text;\n Console.WriteLine(responseText);\n\n return responseText;\n }\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=generativeaionvertexai)."]]