জেমিনি এপিআই ডিফল্টরূপে প্রতিক্রিয়াগুলো অসংগঠিত টেক্সট হিসেবে ফেরত দেয়। তবে, কিছু ব্যবহারের ক্ষেত্রে JSON-এর মতো সংগঠিত টেক্সটের প্রয়োজন হয়। উদাহরণস্বরূপ, আপনি হয়তো প্রতিক্রিয়াটি এমন অন্যান্য পরবর্তী কাজের জন্য ব্যবহার করছেন, যেগুলোর জন্য একটি প্রতিষ্ঠিত ডেটা স্কিমা প্রয়োজন।
মডেলের তৈরি করা আউটপুট যেন সর্বদা একটি নির্দিষ্ট স্কিমা মেনে চলে, তা নিশ্চিত করার জন্য আপনি একটি রেসপন্স স্কিমা সংজ্ঞায়িত করতে পারেন, যা মডেলের রেসপন্সগুলোর জন্য একটি ব্লুপ্রিন্টের মতো কাজ করে। এর ফলে আপনি কম পোস্ট-প্রসেসিংয়ের মাধ্যমে সরাসরি মডেলের আউটপুট থেকে ডেটা এক্সট্র্যাক্ট করতে পারবেন।
এখানে কয়েকটি উদাহরণ দেওয়া হলো:
নিশ্চিত করুন যে মডেলের প্রতিক্রিয়া বৈধ JSON তৈরি করে এবং আপনার প্রদত্ত স্কিমার সাথে সঙ্গতিপূর্ণ।
উদাহরণস্বরূপ, মডেলটি রেসিপিগুলোর জন্য এমন সুসংগঠিত এন্ট্রি তৈরি করতে পারে, যাতে সবসময় রেসিপির নাম, উপকরণের তালিকা এবং ধাপগুলো অন্তর্ভুক্ত থাকে। এর ফলে আপনি আপনার অ্যাপের UI-তে এই তথ্য আরও সহজে পার্স এবং প্রদর্শন করতে পারবেন।শ্রেণীবিভাগ কার্য সম্পাদনের সময় একটি মডেলের প্রতিক্রিয়াকে সীমাবদ্ধ করুন।
উদাহরণস্বরূপ, আপনি মডেলকে দিয়ে টেক্সটকে একটি নির্দিষ্ট সেট লেবেল (যেমন,positive,negativeবাbadpositivegoodমতো বিভিন্ন মাত্রার পরিবর্তনশীল লেবেল) দিয়েnegativeকরাতে পারেন।
এই নির্দেশিকাটি আপনাকে দেখাবে কিভাবে generateContent কল করার সময় একটি responseSchema প্রদান করে JSON আউটপুট তৈরি করতে হয়। এটি মূলত শুধুমাত্র টেক্সট ইনপুটের উপর আলোকপাত করে, কিন্তু Gemini এমন মাল্টিমোডাল অনুরোধের জন্যও কাঠামোগত প্রতিক্রিয়া তৈরি করতে পারে যেগুলিতে ইনপুট হিসাবে ছবি, ভিডিও এবং অডিও অন্তর্ভুক্ত থাকে।
এই পৃষ্ঠার একেবারে নিচে আরও উদাহরণ রয়েছে, যেমন আউটপুট হিসেবে এনাম ভ্যালু কীভাবে তৈরি করতে হয়।
শুরু করার আগে
এই পৃষ্ঠায় প্রদানকারী-নির্দিষ্ট বিষয়বস্তু এবং কোড দেখতে আপনার জেমিনি এপিআই প্রদানকারীর উপর ক্লিক করুন। |
যদি আপনি ইতিমধ্যে তা না করে থাকেন, তাহলে ‘ গেটিং স্টার্টেড গাইড’টি সম্পূর্ণ করুন, যেখানে আপনার Firebase প্রজেক্ট সেট আপ করা, আপনার অ্যাপকে Firebase-এর সাথে সংযুক্ত করা, SDK যোগ করা, আপনার নির্বাচিত Gemini API প্রোভাইডারের জন্য ব্যাকএন্ড সার্ভিস ইনিশিয়ালাইজ করা এবং একটি GenerativeModel ইনস্ট্যান্স তৈরি করার পদ্ধতি বর্ণনা করা হয়েছে।
ধাপ ১ : একটি প্রতিক্রিয়া স্কিমা সংজ্ঞায়িত করুন
একটি মডেলের আউটপুটের কাঠামো, ফিল্ডের নাম এবং প্রতিটি ফিল্ডের প্রত্যাশিত ডেটা টাইপ নির্দিষ্ট করার জন্য একটি রেসপন্স স্কিমা নির্ধারণ করুন।
যখন কোনো মডেল তার প্রতিক্রিয়া তৈরি করে, তখন এটি আপনার প্রম্পট থেকে ফিল্ডের নাম এবং কনটেক্সট ব্যবহার করে। আপনার উদ্দেশ্য যাতে স্পষ্ট হয়, তা নিশ্চিত করতে আমরা একটি সুস্পষ্ট কাঠামো, দ্ব্যর্থহীন ফিল্ডের নাম এবং প্রয়োজন অনুযায়ী বিবরণ ব্যবহার করার পরামর্শ দিই।
প্রতিক্রিয়া স্কিমার জন্য বিবেচ্য বিষয়সমূহ
আপনার প্রতিক্রিয়া স্কিমা লেখার সময় নিম্নলিখিত বিষয়গুলি মনে রাখবেন:
রেসপন্স স্কিমার আকার ইনপুট টোকেন সীমার মধ্যে গণনা করা হয়।
রেসপন্স স্কিমা ফিচারটি নিম্নলিখিত রেসপন্স MIME টাইপগুলোকে সমর্থন করে:
application/json: রেসপন্স স্কিমাতে সংজ্ঞায়িত আউটপুট JSON (কাঠামোগত আউটপুটের প্রয়োজনে উপযোগী)text/x.enum: রেসপন্স স্কিমাতে সংজ্ঞায়িত একটি এনুম ভ্যালু আউটপুট করে (শ্রেণীবিভাগের কাজের জন্য উপযোগী)
রেসপন্স স্কিমা ফিচারটি নিম্নলিখিত স্কিমা ফিল্ডগুলিকে সমর্থন করে:
enum
itemsmaxItems
nullableproperties
requiredআপনি যদি কোনো অসমর্থিত ফিল্ড ব্যবহার করেন, তাহলেও মডেলটি আপনার অনুরোধটি পরিচালনা করতে পারলেও, এটি ফিল্ডটিকে উপেক্ষা করে। উল্লেখ্য যে, উপরের তালিকাটি ওপেনএপিআই ৩.০ স্কিমা অবজেক্টের একটি উপসেট।
ডিফল্টরূপে, Firebase AI Logic SDK-গুলোর ক্ষেত্রে, সমস্ত ফিল্ডকে আবশ্যক বলে গণ্য করা হয়, যদি না আপনি সেগুলোকে একটি
optionalPropertiesঅ্যারেতে ঐচ্ছিক হিসেবে নির্দিষ্ট করেন। এই ঐচ্ছিক ফিল্ডগুলোর জন্য, মডেলটি সেগুলোকে পূরণ করতে পারে অথবা এড়িয়ে যেতে পারে। উল্লেখ্য যে, আপনি যদি দুটি Gemini API প্রোভাইডারের সার্ভার SDK বা সরাসরি তাদের API ব্যবহার করেন, তবে এটি তাদের ডিফল্ট আচরণের বিপরীত।
ধাপ ২ : আপনার রেসপন্স স্কিমা ব্যবহার করে JSON আউটপুট তৈরি করুন
| এই নমুনাটি চেষ্টা করার আগে, আপনার প্রজেক্ট ও অ্যাপ সেট আপ করার জন্য এই গাইডের ' শুরু করার আগে ' অংশটি সম্পূর্ণ করুন। সেই বিভাগে, আপনি আপনার নির্বাচিত জেমিনি এপিআই প্রোভাইডারের জন্য একটি বোতামেও ক্লিক করবেন, যাতে আপনি এই পৃষ্ঠায় প্রোভাইডার-নির্দিষ্ট বিষয়বস্তু দেখতে পান । |
নিম্নলিখিত উদাহরণটি দেখায় কিভাবে স্ট্রাকচার্ড JSON আউটপুট তৈরি করতে হয়।
যখন আপনি GenerativeModel ইনস্ট্যান্স তৈরি করবেন, তখন উপযুক্ত responseMimeType (এই উদাহরণে, application/json ) এবং সেইসাথে মডেলের জন্য ব্যবহৃত responseSchema উল্লেখ করুন।
সুইফট
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
কোটলিনের জন্য, এই SDK-এর মেথডগুলো হলো সাসপেন্ড ফাংশন এবং এগুলোকে একটি 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
জাভার জন্য, এই SDK-এর স্ট্রিমিং মেথডগুলো Reactive Streams লাইব্রেরি থেকে একটিPublisher টাইপ রিটার্ন করে।
// 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);
ঐক্য
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.");
কীভাবে একটি মডেল বেছে নিতে হয় তা জানুনআপনার ব্যবহারের ক্ষেত্র এবং অ্যাপের জন্য উপযুক্ত।
অতিরিক্ত উদাহরণ
কীভাবে আপনি স্ট্রাকচার্ড আউটপুট ব্যবহার ও তৈরি করতে পারেন, তার আরও কিছু উদাহরণ এখানে দেওয়া হলো।আউটপুট হিসাবে এনাম মান তৈরি করুন
| এই নমুনাটি চেষ্টা করার আগে, আপনার প্রজেক্ট ও অ্যাপ সেট আপ করার জন্য এই গাইডের ' শুরু করার আগে ' অংশটি সম্পূর্ণ করুন। সেই বিভাগে, আপনি আপনার নির্বাচিত জেমিনি এপিআই প্রোভাইডারের জন্য একটি বোতামেও ক্লিক করবেন, যাতে আপনি এই পৃষ্ঠায় প্রোভাইডার-নির্দিষ্ট বিষয়বস্তু দেখতে পান । |
নিম্নলিখিত উদাহরণটি দেখায় কিভাবে একটি ক্লাসিফিকেশন টাস্কের জন্য রেসপন্স স্কিমা ব্যবহার করতে হয়। মডেলটিকে একটি সিনেমার বিবরণের উপর ভিত্তি করে তার ধরণ শনাক্ত করতে বলা হয়। আউটপুটটি হলো একটি প্লেইন-টেক্সট এনাম ভ্যালু, যা মডেলটি প্রদত্ত রেসপন্স স্কিমাতে সংজ্ঞায়িত ভ্যালুগুলোর তালিকা থেকে নির্বাচন করে।
এই কাঠামোগত শ্রেণিবিন্যাসের কাজটি সম্পাদন করার জন্য, মডেল ইনিশিয়ালাইজেশনের সময় আপনাকে উপযুক্ত responseMimeType (এই উদাহরণে, text/x.enum ) এবং সেইসাথে মডেলের জন্য কাঙ্ক্ষিত responseSchema নির্দিষ্ট করতে হবে।
সুইফট
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
কোটলিনের জন্য, এই SDK-এর মেথডগুলো হলো সাসপেন্ড ফাংশন এবং এগুলোকে একটি 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
জাভার জন্য, এই SDK-এর স্ট্রিমিং মেথডগুলো Reactive Streams লাইব্রেরি থেকে একটিPublisher টাইপ রিটার্ন করে।
// 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);
ঐক্য
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.");
কীভাবে একটি মডেল বেছে নিতে হয় তা জানুনআপনার ব্যবহারের ক্ষেত্র এবং অ্যাপের জন্য উপযুক্ত।
কন্টেন্ট তৈরি নিয়ন্ত্রণ করার অন্যান্য বিকল্প
- প্রম্পট ডিজাইন সম্পর্কে আরও জানুন, যাতে আপনি আপনার প্রয়োজন অনুযায়ী নির্দিষ্ট আউটপুট তৈরি করতে মডেলটিকে প্রভাবিত করতে পারেন।
- মডেলটি কীভাবে প্রতিক্রিয়া তৈরি করবে তা নিয়ন্ত্রণ করতে মডেলের প্যারামিটারগুলো কনফিগার করুন। জেমিনি মডেলের জন্য, এই প্যারামিটারগুলোর মধ্যে রয়েছে সর্বোচ্চ আউটপুট টোকেন, তাপমাত্রা, টপকে (topK), এবং টপপি (topP)। ইমাজেন মডেলের জন্য, এগুলোর মধ্যে রয়েছে অ্যাস্পেক্ট রেশিও, পার্সন জেনারেশন, ওয়াটারমার্কিং, ইত্যাদি।
- বিদ্বেষমূলক বক্তব্য এবং যৌনতাপূর্ণ বিষয়বস্তুর মতো ক্ষতিকর বলে বিবেচিত হতে পারে এমন প্রতিক্রিয়া পাওয়ার সম্ভাবনা নিয়ন্ত্রণ করতে সুরক্ষা সেটিংস ব্যবহার করুন।
- মডেলের আচরণ নিয়ন্ত্রণ করতে সিস্টেম নির্দেশাবলী সেট করুন। এই বৈশিষ্ট্যটি একটি প্রস্তাবনার মতো, যা মডেলটি অন্তিম ব্যবহারকারীর কাছ থেকে পরবর্তী কোনো নির্দেশাবলীর সম্মুখীন হওয়ার আগে যোগ করা হয়।
Firebase AI Logic ব্যবহারের অভিজ্ঞতা সম্পর্কে মতামত দিন।