Mulai 29 April 2025, model Gemini 1.5 Pro dan Gemini 1.5 Flash tidak tersedia di project yang belum pernah menggunakan model ini, termasuk project baru. Untuk mengetahui detailnya, lihat
Versi dan siklus proses model.
Menentukan jenis respons MIME untuk Gemini API
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Tentukan jenis respons MIME untuk Gemini API agar respons yang dihasilkan sesuai dengan jenis tersebut.
Contoh kode
Kecuali dinyatakan lain, konten di halaman ini dilisensikan berdasarkan Lisensi Creative Commons Attribution 4.0, sedangkan contoh kode dilisensikan berdasarkan Lisensi Apache 2.0. Untuk mengetahui informasi selengkapnya, lihat Kebijakan Situs Google Developers. Java adalah merek dagang terdaftar dari Oracle dan/atau afiliasinya.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],[],[],[],null,["# Specify a MIME response type for the Gemini API so that the generated response is compliant with that type.\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 GenerateContentWithResponseSchema(\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 [\"recipe_name\"] = new() { Type = Type.String },\n },\n Required = { \"recipe_name\" }\n }\n };\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 = \"List a few popular popular cookie recipes\" }\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)."]]