Gemini API डिफ़ॉल्ट रूप से जवाबों को अनस्ट्रक्चर्ड टेक्स्ट के तौर पर दिखाता है. हालांकि, कुछ मामलों में स्ट्रक्चर्ड टेक्स्ट की ज़रूरत होती है. जैसे, JSON. उदाहरण के लिए, हो सकता है कि आप जवाब का इस्तेमाल, डाउनस्ट्रीम के अन्य टास्क के लिए कर रहे हों. इन टास्क के लिए, तय किया गया डेटा स्कीमा ज़रूरी होता है.
यह पक्का करने के लिए कि मॉडल से जनरेट किया गया आउटपुट हमेशा किसी खास स्कीमा के मुताबिक हो, रिस्पॉन्स स्कीमा तय किया जा सकता है. यह स्कीमा, मॉडल के जवाबों के लिए ब्लूप्रिंट की तरह काम करता है. इसके बाद, मॉडल के आउटपुट से डेटा को सीधे तौर पर एक्सट्रैक्ट किया जा सकता है. इसके लिए, पोस्ट-प्रोसेसिंग की ज़रूरत कम होती है.
यहां कुछ उदाहरण दिए गए हैं:
पक्का करें कि मॉडल का जवाब, मान्य JSON फ़ॉर्मैट में हो और आपके दिए गए स्कीमा के मुताबिक हो.
उदाहरण के लिए, मॉडल रेसिपी के लिए स्ट्रक्चर्ड एंट्री जनरेट कर सकता है. इन एंट्री में हमेशा रेसिपी का नाम, सामग्री की सूची, और चरण शामिल होते हैं. इसके बाद, इस जानकारी को अपने ऐप्लिकेशन के यूज़र इंटरफ़ेस (यूआई) में आसानी से पार्स और दिखाया जा सकता है.क्लासिफ़िकेशन टास्क के दौरान, मॉडल के जवाब देने के तरीके पर पाबंदी लगाएं.
उदाहरण के लिए, मॉडल से टेक्स्ट को लेबल के किसी खास सेट (जैसे,positiveऔरnegativeजैसे ईनम का कोई खास सेट) के साथ एनोटेट कराया जा सकता है. इसके बजाय, मॉडल के जनरेट किए गए लेबल (जिनमेंgood,positive,negativeयाbadजैसे अलग-अलग लेबल हो सकते हैं) का इस्तेमाल किया जा सकता है.
इस गाइड में, generateContent को कॉल करके, responseSchema उपलब्ध कराकर JSON आउटपुट जनरेट करने का तरीका बताया गया है. इसमें सिर्फ़ टेक्स्ट वाले इनपुट पर फ़ोकस किया गया है. हालांकि, Gemini, मल्टीमॉडल अनुरोधों के लिए स्ट्रक्चर्ड जवाब भी जनरेट कर सकता है. इन अनुरोधों में, इमेज, वीडियो, और ऑडियो को इनपुट के तौर पर शामिल किया जाता है.
इस पेज पर सबसे नीचे, ज़्यादा उदाहरण दिए गए हैं. जैसे, आउटपुट के तौर पर ईनम वैल्यू जनरेट करने का तरीका .
शुरू करने से पहले
|
इस पेज पर, Gemini API प्रोवाइडर के हिसाब से कॉन्टेंट और कोड देखने के लिए, उस पर क्लिक करें. |
अगर आपने अब तक, शुरू करने के लिए
गाइडमें दिए गए निर्देशों को पूरा नहीं किया है, तो उन्हें पूरा करें. इसमें बताया गया है कि
Firebase प्रोजेक्ट को कैसे सेट अप करें, अपने ऐप्लिकेशन को Firebase से कैसे कनेक्ट करें, एसडीके को कैसे जोड़ें,
अपने चुने हुए Gemini API प्रोवाइडर के लिए बैकएंड सेवा को कैसे शुरू करें, और
एक GenerativeModel इंस्टेंस कैसे बनाएं.
हम आपको Google AI StudioGoogle AI Studio का इस्तेमाल करने का सुझाव देते हैं. इससे, प्रॉम्प्ट की जांच की जा सकती है और उनमें बदलाव किया जा सकता है.
पहला चरण: रिस्पॉन्स स्कीमा तय करना
रिस्पॉन्स स्कीमा तय करें. इससे, मॉडल के आउटपुट का स्ट्रक्चर, फ़ील्ड के नाम, और हर फ़ील्ड के लिए अनुमानित डेटा टाइप तय किया जा सकता है.
जब कोई मॉडल अपना जवाब जनरेट करता है, तो वह आपके प्रॉम्प्ट से फ़ील्ड का नाम और कॉन्टेक्स्ट इस्तेमाल करता है. यह पक्का करने के लिए कि आपका इरादा साफ़ हो, हमारा सुझाव है कि साफ़ स्ट्रक्चर, ऐसे फ़ील्ड के नाम इस्तेमाल करें जिनमें कोई भ्रम न हो, और ज़रूरत के हिसाब से ब्यौरे भी शामिल करें.
रिस्पॉन्स स्कीमा के लिए ध्यान देने वाली बातें
रिस्पॉन्स स्कीमा लिखते समय इन बातों का ध्यान रखें:
रिस्पॉन्स स्कीमा का साइज़, इनपुट टोकन की सीमा में गिना जाता है.
रिस्पॉन्स स्कीमा की सुविधा, जवाब के इन MIME टाइप के साथ काम करती है:
application/json: रिस्पॉन्स स्कीमा में तय किए गए JSON को आउटपुट के तौर पर दिखाना (स्ट्रक्चर्ड आउटपुट की ज़रूरी शर्तों के लिए काम का है)text/x.enum: रिस्पॉन्स स्कीमा में तय की गई ईनम वैल्यू को आउटपुट के तौर पर दिखाना (क्लासिफ़िकेशन टास्क के लिए काम का है)
रिस्पॉन्स स्कीमा की सुविधा, स्कीमा के इन फ़ील्ड के साथ काम करती है:
enum
items
maxItems
nullable
properties
required
अगर किसी ऐसे फ़ील्ड का इस्तेमाल किया जाता है जो काम नहीं करता है, तो मॉडल अब भी आपके अनुरोध को प्रोसेस कर सकता है. हालांकि, वह उस फ़ील्ड को अनदेखा कर देता है. ध्यान दें कि ऊपर दी गई सूची, OpenAPI 3.0 स्कीमा ऑब्जेक्ट का सबसेट है.
डिफ़ॉल्ट रूप से, Firebase AI Logic SDK के लिए, सभी फ़ील्ड को ज़रूरी माना जाता है. हालांकि, उन्हें
optionalPropertiesकलेक्शन में, 'ज़रूरी नहीं' के तौर पर तय किया जा सकता है. इन 'ज़रूरी नहीं' वाले फ़ील्ड के लिए, मॉडल इन फ़ील्ड में जानकारी भर सकता है या इन्हें छोड़ सकता है. ध्यान दें कि अगर दो Gemini API प्रोवाइडर के सर्वर एसडीके या उनके एपीआई का सीधे तौर पर इस्तेमाल किया जाता है, तो यह उनके डिफ़ॉल्ट व्यवहार के उलट है.
दूसरा चरण: अपने रिस्पॉन्स स्कीमा का इस्तेमाल करके, JSON आउटपुट जनरेट करना
|
इस सैंपल को आज़माने से पहले, अपने प्रोजेक्ट और ऐप्लिकेशन को सेट अप करने के लिए, इस गाइड का
'शुरू करने से पहले' सेक्शन पूरा करें. उस सेक्शन में, आपको Gemini API के अपने चुने हुए Gemini API प्रोवाइडर के लिए एक बटन पर भी क्लिक करना होगा, ताकि आपको इस पेज पर प्रोवाइडर के हिसाब से कॉन्टेंट दिखे. |
यहां दिए गए उदाहरण में, स्ट्रक्चर्ड JSON आउटपुट जनरेट करने का तरीका दिखाया गया है.
GenerativeModel इंस्टेंस बनाते समय, सही responseMimeType (इस उदाहरण में, application/json) के साथ-साथ, वह responseSchema भी तय करें जिसका इस्तेमाल मॉडल से कराना है.
Swift
import FirebaseAILogic
// Provide a JSON schema object using a standard format.
// Later, pass this schema object into `responseSchema` in the generation config.
let jsonSchema = Schema.object(
properties: [
"characters": Schema.array(
items: .object(
properties: [
"name": .string(),
"age": .integer(),
"species": .string(),
"accessory": .enumeration(values: ["hat", "belt", "shoes"]),
],
optionalProperties: ["accessory"]
)
),
]
)
// Initialize the Gemini Developer API backend service
let ai = FirebaseAI.firebaseAI(backend: .googleAI())
// Create a `GenerativeModel` instance with a model that supports your use case
let model = ai.generativeModel(
modelName: "gemini-3-flash-preview",
// In the generation config, set the `responseMimeType` to `application/json`
// and pass the JSON schema object into `responseSchema`.
generationConfig: GenerationConfig(
responseMIMEType: "application/json",
responseSchema: jsonSchema
)
)
let prompt = "For use in a children's card game, generate 10 animal-based characters."
let response = try await model.generateContent(prompt)
print(response.text ?? "No text in response.")
Kotlin
Kotlin के लिए, इस एसडीके में मौजूद तरीके, सस्पेंड फ़ंक्शन होते हैं. इन्हें Coroutine स्कोप से कॉल करना होता है.
// Provide a JSON schema object using a standard format.
// Later, pass this schema object into `responseSchema` in the generation config.
val jsonSchema = Schema.obj(
mapOf("characters" to Schema.array(
Schema.obj(
mapOf(
"name" to Schema.string(),
"age" to Schema.integer(),
"species" to Schema.string(),
"accessory" to Schema.enumeration(listOf("hat", "belt", "shoes")),
),
optionalProperties = listOf("accessory")
)
))
)
// Initialize the Gemini Developer API backend service
// Create a `GenerativeModel` instance with a model that supports your use case
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel(
modelName = "gemini-3-flash-preview",
// In the generation config, set the `responseMimeType` to `application/json`
// and pass the JSON schema object into `responseSchema`.
generationConfig = generationConfig {
responseMimeType = "application/json"
responseSchema = jsonSchema
})
val prompt = "For use in a children's card game, generate 10 animal-based characters."
val response = generativeModel.generateContent(prompt)
print(response.text)
Java
Java के लिए, इस एसडीके में मौजूद स्ट्रीमिंग के तरीके,Publisher टाइप दिखाते हैं, जो Reactive Streams लाइब्रेरी से है.
// Provide a JSON schema object using a standard format.
// Later, pass this schema object into `responseSchema` in the generation config.
Schema jsonSchema = Schema.obj(
/* properties */
Map.of(
"characters", Schema.array(
/* items */ Schema.obj(
/* properties */
Map.of("name", Schema.str(),
"age", Schema.numInt(),
"species", Schema.str(),
"accessory",
Schema.enumeration(
List.of("hat", "belt", "shoes")))
))),
List.of("accessory"));
// In the generation config, set the `responseMimeType` to `application/json`
// and pass the JSON schema object into `responseSchema`.
GenerationConfig.Builder configBuilder = new GenerationConfig.Builder();
configBuilder.responseMimeType = "application/json";
configBuilder.responseSchema = jsonSchema;
GenerationConfig generationConfig = configBuilder.build();
// Initialize the Gemini Developer API backend service
// Create a `GenerativeModel` instance with a model that supports your use case
GenerativeModel ai = FirebaseAI.getInstance(GenerativeBackend.googleAI())
.generativeModel(
/* modelName */ "gemini-3-flash-preview",
/* generationConfig */ generationConfig);
GenerativeModelFutures model = GenerativeModelFutures.from(ai);
Content content = new Content.Builder()
.addText("For use in a children's card game, generate 10 animal-based characters.")
.build();
// For illustrative purposes only. You should use an executor that fits your needs.
Executor executor = Executors.newSingleThreadExecutor();
ListenableFuture<GenerateContentResponse> response = model.generateContent(content);
Futures.addCallback(
response,
new FutureCallback<GenerateContentResponse>() {
@Override
public void onSuccess(GenerateContentResponse result) {
String resultText = result.getText();
System.out.println(resultText);
}
@Override
public void onFailure(Throwable t) {
t.printStackTrace();
}
},
executor);
Web
import { initializeApp } from "firebase/app";
import { getAI, getGenerativeModel, GoogleAIBackend, Schema } from "firebase/ai";
// TODO(developer) Replace the following with your app's Firebase configuration
// See: https://firebase.google.com/docs/web/learn-more#config-object
const firebaseConfig = {
// ...
};
// Initialize FirebaseApp
const firebaseApp = initializeApp(firebaseConfig);
// Initialize the Gemini Developer API backend service
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
// Provide a JSON schema object using a standard format.
// Later, pass this schema object into `responseSchema` in the generation config.
const jsonSchema = Schema.object({
properties: {
characters: Schema.array({
items: Schema.object({
properties: {
name: Schema.string(),
accessory: Schema.string(),
age: Schema.number(),
species: Schema.string(),
},
optionalProperties: ["accessory"],
}),
}),
}
});
// Create a `GenerativeModel` instance with a model that supports your use case
const model = getGenerativeModel(ai, {
model: "gemini-3-flash-preview",
// In the generation config, set the `responseMimeType` to `application/json`
// and pass the JSON schema object into `responseSchema`.
generationConfig: {
responseMimeType: "application/json",
responseSchema: jsonSchema
},
});
let prompt = "For use in a children's card game, generate 10 animal-based characters.";
let result = await model.generateContent(prompt)
console.log(result.response.text());
Dart
import 'package:firebase_ai/firebase_ai.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';
// Provide a JSON schema object using a standard format.
// Later, pass this schema object into `responseSchema` in the generation config.
final jsonSchema = Schema.object(
properties: {
'characters': Schema.array(
items: Schema.object(
properties: {
'name': Schema.string(),
'age': Schema.integer(),
'species': Schema.string(),
'accessory':
Schema.enumString(enumValues: ['hat', 'belt', 'shoes']),
},
),
),
},
optionalProperties: ['accessory'],
);
// Initialize FirebaseApp
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
// Initialize the Gemini Developer API backend service
// Create a `GenerativeModel` instance with a model that supports your use case
final model =
FirebaseAI.googleAI().generativeModel(
model: 'gemini-3-flash-preview',
// In the generation config, set the `responseMimeType` to `application/json`
// and pass the JSON schema object into `responseSchema`.
generationConfig: GenerationConfig(
responseMimeType: 'application/json', responseSchema: jsonSchema));
final prompt = "For use in a children's card game, generate 10 animal-based characters.";
final response = await model.generateContent([Content.text(prompt)]);
print(response.text);
Unity
using Firebase;
using Firebase.AI;
// Provide a JSON schema object using a standard format.
// Later, pass this schema object into `responseSchema` in the generation config.
var jsonSchema = Schema.Object(
properties: new System.Collections.Generic.Dictionary<string, Schema> {
{ "characters", Schema.Array(
items: Schema.Object(
properties: new System.Collections.Generic.Dictionary<string, Schema> {
{ "name", Schema.String() },
{ "age", Schema.Int() },
{ "species", Schema.String() },
{ "accessory", Schema.Enum(new string[] { "hat", "belt", "shoes" }) },
},
optionalProperties: new string[] { "accessory" }
)
) },
}
);
// Initialize the Gemini Developer API backend service
// Create a `GenerativeModel` instance with a model that supports your use case
var model = FirebaseAI.DefaultInstance.GetGenerativeModel(
modelName: "gemini-3-flash-preview",
// In the generation config, set the `responseMimeType` to `application/json`
// and pass the JSON schema object into `responseSchema`.
generationConfig: new GenerationConfig(
responseMimeType: "application/json",
responseSchema: jsonSchema
)
);
var prompt = "For use in a children's card game, generate 10 animal-based characters.";
var response = await model.GenerateContentAsync(prompt);
UnityEngine.Debug.Log(response.Text ?? "No text in response.");
अपने इस्तेमाल के मामले और ऐप्लिकेशन के हिसाब से, मॉडल
कुछ और उदाहरण
यहां स्ट्रक्चर्ड आउटपुट का इस्तेमाल और उसे जनरेट करने के कुछ और उदाहरण दिए गए हैं.आउटपुट के तौर पर ईनम वैल्यू जनरेट करना
|
इस सैंपल को आज़माने से पहले, अपने प्रोजेक्ट और ऐप्लिकेशन को सेट अप करने के लिए, इस गाइड का
'शुरू करने से पहले' सेक्शन पूरा करें. उस सेक्शन में, आपको Gemini API के अपने चुने हुए Gemini API प्रोवाइडर के लिए एक बटन पर भी क्लिक करना होगा, ताकि आपको इस पेज पर प्रोवाइडर के हिसाब से कॉन्टेंट दिखे. |
यहां दिए गए उदाहरण में, क्लासिफ़िकेशन टास्क के लिए रिस्पॉन्स स्कीमा का इस्तेमाल करने का तरीका दिखाया गया है. मॉडल से, किसी फ़िल्म के ब्यौरे के आधार पर उसकी शैली की पहचान करने के लिए कहा गया है. आउटपुट, सादे टेक्स्ट वाली एक ईनम वैल्यू है. मॉडल, यह वैल्यू, दिए गए रिस्पॉन्स स्कीमा में तय की गई वैल्यू की सूची से चुनता है.
स्ट्रक्चर्ड क्लासिफ़िकेशन टास्क को पूरा करने के लिए, मॉडल को शुरू करते समय, सही responseMimeType (इस उदाहरण में, text/x.enum) के साथ-साथ, वह responseSchema भी तय करें जिसका इस्तेमाल मॉडल से कराना है.
Swift
import FirebaseAILogic
// Provide an enum schema object using a standard format.
// Later, pass this schema object into `responseSchema` in the generation config.
let enumSchema = Schema.enumeration(values: ["drama", "comedy", "documentary"])
// Initialize the Gemini Developer API backend service
let ai = FirebaseAI.firebaseAI(backend: .googleAI())
// Create a `GenerativeModel` instance with a model that supports your use case
let model = ai.generativeModel(
modelName: "gemini-3-flash-preview",
// In the generation config, set the `responseMimeType` to `text/x.enum`
// and pass the enum schema object into `responseSchema`.
generationConfig: GenerationConfig(
responseMIMEType: "text/x.enum",
responseSchema: enumSchema
)
)
let prompt = """
The film aims to educate and inform viewers about real-life subjects, events, or people.
It offers a factual record of a particular topic by combining interviews, historical footage,
and narration. The primary purpose of a film is to present information and provide insights
into various aspects of reality.
"""
let response = try await model.generateContent(prompt)
print(response.text ?? "No text in response.")
Kotlin
Kotlin के लिए, इस एसडीके में मौजूद तरीके, सस्पेंड फ़ंक्शन होते हैं. इन्हें Coroutine स्कोप से कॉल करना होता है.
// Provide an enum schema object using a standard format.
// Later, pass this schema object into `responseSchema` in the generation config.
val enumSchema = Schema.enumeration(listOf("drama", "comedy", "documentary"))
// Initialize the Gemini Developer API backend service
// Create a `GenerativeModel` instance with a model that supports your use case
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel(
modelName = "gemini-3-flash-preview",
// In the generation config, set the `responseMimeType` to `text/x.enum`
// and pass the enum schema object into `responseSchema`.
generationConfig = generationConfig {
responseMimeType = "text/x.enum"
responseSchema = enumSchema
})
val prompt = """
The film aims to educate and inform viewers about real-life subjects, events, or people.
It offers a factual record of a particular topic by combining interviews, historical footage,
and narration. The primary purpose of a film is to present information and provide insights
into various aspects of reality.
"""
val response = generativeModel.generateContent(prompt)
print(response.text)
Java
Java के लिए, इस एसडीके में मौजूद स्ट्रीमिंग के तरीके,Publisher टाइप दिखाते हैं, जो Reactive Streams लाइब्रेरी से है.
// Provide an enum schema object using a standard format.
// Later, pass this schema object into `responseSchema` in the generation config.
Schema enumSchema = Schema.enumeration(List.of("drama", "comedy", "documentary"));
// In the generation config, set the `responseMimeType` to `text/x.enum`
// and pass the enum schema object into `responseSchema`.
GenerationConfig.Builder configBuilder = new GenerationConfig.Builder();
configBuilder.responseMimeType = "text/x.enum";
configBuilder.responseSchema = enumSchema;
GenerationConfig generationConfig = configBuilder.build();
// Initialize the Gemini Developer API backend service
// Create a `GenerativeModel` instance with a model that supports your use case
GenerativeModel ai = FirebaseAI.getInstance(GenerativeBackend.googleAI())
.generativeModel(
/* modelName */ "gemini-3-flash-preview",
/* generationConfig */ generationConfig);
GenerativeModelFutures model = GenerativeModelFutures.from(ai);
String prompt = "The film aims to educate and inform viewers about real-life subjects," +
" events, or people. It offers a factual record of a particular topic by" +
" combining interviews, historical footage, and narration. The primary purpose" +
" of a film is to present information and provide insights into various aspects" +
" of reality.";
Content content = new Content.Builder().addText(prompt).build();
// For illustrative purposes only. You should use an executor that fits your needs.
Executor executor = Executors.newSingleThreadExecutor();
ListenableFuture<GenerateContentResponse> response = model.generateContent(content);
Futures.addCallback(
response,
new FutureCallback<GenerateContentResponse>() {
@Override
public void onSuccess(GenerateContentResponse result) {
String resultText = result.getText();
System.out.println(resultText);
}
@Override
public void onFailure(Throwable t) {
t.printStackTrace();
}
},
executor);
Web
import { initializeApp } from "firebase/app";
import { getAI, getGenerativeModel, GoogleAIBackend, Schema } from "firebase/ai";
// TODO(developer) Replace the following with your app's Firebase configuration
// See: https://firebase.google.com/docs/web/learn-more#config-object
const firebaseConfig = {
// ...
};
// Initialize FirebaseApp
const firebaseApp = initializeApp(firebaseConfig);
// Initialize the Gemini Developer API backend service
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
// Provide an enum schema object using a standard format.
// Later, pass this schema object into `responseSchema` in the generation config.
const enumSchema = Schema.enumString({
enum: ["drama", "comedy", "documentary"],
});
// Create a `GenerativeModel` instance with a model that supports your use case
const model = getGenerativeModel(ai, {
model: "gemini-3-flash-preview",
// In the generation config, set the `responseMimeType` to `text/x.enum`
// and pass the JSON schema object into `responseSchema`.
generationConfig: {
responseMimeType: "text/x.enum",
responseSchema: enumSchema,
},
});
let prompt = `The film aims to educate and inform viewers about real-life
subjects, events, or people. It offers a factual record of a particular topic
by combining interviews, historical footage, and narration. The primary purpose
of a film is to present information and provide insights into various aspects
of reality.`;
let result = await model.generateContent(prompt);
console.log(result.response.text());
Dart
import 'package:firebase_ai/firebase_ai.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';
// Provide an enum schema object using a standard format.
// Later, pass this schema object into `responseSchema` in the generation config.
final enumSchema = Schema.enumString(enumValues: ['drama', 'comedy', 'documentary']);
// Initialize FirebaseApp
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
// Initialize the Gemini Developer API backend service
// Create a `GenerativeModel` instance with a model that supports your use case
final model =
FirebaseAI.googleAI().generativeModel(
model: 'gemini-3-flash-preview',
// In the generation config, set the `responseMimeType` to `text/x.enum`
// and pass the enum schema object into `responseSchema`.
generationConfig: GenerationConfig(
responseMimeType: 'text/x.enum', responseSchema: enumSchema));
final prompt = """
The film aims to educate and inform viewers about real-life subjects, events, or people.
It offers a factual record of a particular topic by combining interviews, historical footage,
and narration. The primary purpose of a film is to present information and provide insights
into various aspects of reality.
""";
final response = await model.generateContent([Content.text(prompt)]);
print(response.text);
Unity
using Firebase;
using Firebase.AI;
// Provide an enum schema object using a standard format.
// Later, pass this schema object into `responseSchema` in the generation config.
var enumSchema = Schema.Enum(new string[] { "drama", "comedy", "documentary" });
// Initialize the Gemini Developer API backend service
// Create a `GenerativeModel` instance with a model that supports your use case
var model = FirebaseAI.DefaultInstance.GetGenerativeModel(
modelName: "gemini-3-flash-preview",
// In the generation config, set the `responseMimeType` to `text/x.enum`
// and pass the enum schema object into `responseSchema`.
generationConfig: new GenerationConfig(
responseMimeType: "text/x.enum",
responseSchema: enumSchema
)
);
var prompt = @"
The film aims to educate and inform viewers about real-life subjects, events, or people.
It offers a factual record of a particular topic by combining interviews, historical footage,
and narration. The primary purpose of a film is to present information and provide insights
into various aspects of reality.
";
var response = await model.GenerateContentAsync(prompt);
UnityEngine.Debug.Log(response.Text ?? "No text in response.");
अपने इस्तेमाल के मामले और ऐप्लिकेशन के हिसाब से, मॉडल
कॉन्टेंट जनरेट करने को कंट्रोल करने के अन्य विकल्प
- प्रॉम्प्ट डिज़ाइन के बारे में ज़्यादा जानें, ताकि मॉडल को अपनी ज़रूरत के हिसाब से आउटपुट जनरेट करने के लिए प्रभावित किया जा सके.
- मॉडल के पैरामीटर कॉन्फ़िगर करें, ताकि यह कंट्रोल किया जा सके कि मॉडल जवाब कैसे जनरेट करता है. Gemini मॉडल के लिए, इन पैरामीटर में ज़्यादा से ज़्यादा आउटपुट टोकन, तापमान, topK, और topP शामिल हैं. Imagen मॉडल के लिए, इनमें आसपेक्ट रेशियो, व्यक्ति जनरेशन, वॉटरमार्किंग वगैरह शामिल हैं.
- सेफ़्टी सेटिंग का इस्तेमाल करके, ऐसे जवाब मिलने की संभावना को अडजस्ट करें जिन्हें नुकसान पहुंचाने वाला माना जा सकता है. इनमें, नफ़रत फैलाने वाली भाषा और साफ़ तौर पर सेक्शुअल कॉन्टेंट शामिल है.
- मॉडल के व्यवहार को कंट्रोल करने के लिए, सिस्टम इंस्ट्रक्शन सेट करें. यह सुविधा, एक प्रस्तावना की तरह है. इसे मॉडल को असली उपयोगकर्ता से कोई और निर्देश मिलने से पहले जोड़ा जाता है.
सुझाव/राय देना या शिकायत करना के बारे में अपने अनुभव के साथ Firebase AI Logic