null 값으로 제어 생성 JSON 출력
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
의미 있는 응답을 생성하기에 충분한 컨텍스트가 없을 때 모델이 null 응답을 출력하도록 허용합니다.
코드 샘플
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],[],[],[],null,["# Controlled generation JSON output with null values\n\nAllow the model to output null responses when it doesn't have enough context to generate a meaningful response.\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 GenerateContentWithResponseSchema3(\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.Object,\n Properties =\n {\n [\"forecast\"] = new()\n {\n Type = Type.Array,\n Items = new()\n {\n Type = Type.Object,\n Properties =\n {\n [\"Forecast\"] = new() { Type = Type.String },\n [\"Humidity\"] = new() { Type = Type.String },\n [\"Temperature\"] = new() { Type = Type.Integer },\n [\"Wind Speed\"] = new() { Type = Type.Integer }\n }\n }\n }\n }\n };\n\n string prompt = @\"\n The week ahead brings a mix of weather conditions.\n 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.\n Monday will see partly cloudy skies with a slightly cooler temperature of 72°F and humidity increasing to 55%. Winds will pick up slightly to around 15 km/h.\n Tuesday brings rain showers, with temperatures dropping to 64°F and humidity rising to 70%. Expect stronger winds at 20 km/h.\n Wednesday may see thunderstorms, with a temperature of 68°F and high humidity of 75%. Winds will be gusty at 25 km/h.\n Thursday will be cloudy with a temperature of 66°F and moderate humidity at 60%. Winds will ease slightly to 18 km/h.\n Friday returns to partly cloudy conditions, with a temperature of 73°F and lower humidity at 45%. Winds will be light at 12 km/h.\n 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.\";\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)."]]