Gemini API ব্যবহার করে কাঠামোগত আউটপুট (যেমন JSON এবং enums) তৈরি করুন৷

জেমিনি এপিআই ডিফল্টভাবে আনস্ট্রাকচার্ড টেক্সট হিসেবে রেসপন্স ফেরত দেয়। তবে, কিছু ব্যবহারের ক্ষেত্রে স্ট্রাকচার্ড টেক্সটের প্রয়োজন হয়, যেমন JSON। উদাহরণস্বরূপ, আপনি হয়তো রেসপন্সটি অন্যান্য ডাউনস্ট্রিম কাজের জন্য ব্যবহার করছেন যার জন্য একটি প্রতিষ্ঠিত ডেটা স্কিমা প্রয়োজন।

মডেলের জেনারেটেড আউটপুট যাতে সর্বদা একটি নির্দিষ্ট স্কিমার সাথে মেনে চলে তা নিশ্চিত করার জন্য, আপনি একটি রেসপন্স স্কিমা সংজ্ঞায়িত করতে পারেন যা মডেল রেসপন্সের জন্য একটি ব্লুপ্রিন্টের মতো কাজ করে। এরপর আপনি কম পোস্ট-প্রসেসিং ব্যবহার করে মডেলের আউটপুট থেকে সরাসরি ডেটা বের করতে পারেন।

এখানে কিছু উদাহরণ দেওয়া হল:

  • নিশ্চিত করুন যে একটি মডেলের প্রতিক্রিয়া বৈধ JSON তৈরি করে এবং আপনার প্রদত্ত স্কিমার সাথে সঙ্গতিপূর্ণ।
    উদাহরণস্বরূপ, মডেলটি রেসিপির জন্য স্ট্রাকচার্ড এন্ট্রি তৈরি করতে পারে যাতে সর্বদা রেসিপির নাম, উপাদানের তালিকা এবং ধাপগুলি অন্তর্ভুক্ত থাকে। এরপর আপনি আরও সহজেই আপনার অ্যাপের UI-তে এই তথ্য বিশ্লেষণ এবং প্রদর্শন করতে পারবেন।

  • শ্রেণিবিন্যাসের কাজের সময় একজন মডেল কীভাবে প্রতিক্রিয়া জানাতে পারে তা সীমাবদ্ধ করুন।
    উদাহরণস্বরূপ, আপনি মডেলটি তৈরি করে এমন লেবেলের পরিবর্তে (যার মধ্যে good , positive , positive , অথবা bad এর মতো পরিবর্তনশীলতার মাত্রা থাকতে পারে) একটি নির্দিষ্ট সেট লেবেল (উদাহরণস্বরূপ, enums এর একটি নির্দিষ্ট সেট যেমন positive এবং negative ) দিয়ে মডেলটি negative টেক্সট ব্যবহার করতে bad

এই নির্দেশিকাটি আপনাকে দেখায় কিভাবে generateContent কলে একটি responseSchema প্রদান করে JSON আউটপুট তৈরি করতে হয়। এটি শুধুমাত্র টেক্সট ইনপুটের উপর ফোকাস করে, তবে জেমিনি মাল্টিমোডাল অনুরোধগুলিতে কাঠামোগত প্রতিক্রিয়াও তৈরি করতে পারে যার মধ্যে ইনপুট হিসাবে ছবি, ভিডিও এবং অডিও অন্তর্ভুক্ত থাকে।

এই পৃষ্ঠার নীচে আরও উদাহরণ রয়েছে, যেমন আউটপুট হিসাবে enum মান কীভাবে তৈরি করা যায়

শুরু করার আগে

এই পৃষ্ঠায় প্রোভাইডার-নির্দিষ্ট কন্টেন্ট এবং কোড দেখতে আপনার জেমিনি API প্রোভাইডারে ক্লিক করুন।

যদি আপনি ইতিমধ্যেই না করে থাকেন, তাহলে শুরু করার নির্দেশিকাটি সম্পূর্ণ করুন, যেখানে বর্ণনা করা হয়েছে কিভাবে আপনার Firebase প্রকল্প সেট আপ করবেন, আপনার অ্যাপটি Firebase-এর সাথে সংযুক্ত করবেন, SDK যোগ করবেন, আপনার নির্বাচিত Gemini API প্রদানকারীর জন্য ব্যাকএন্ড পরিষেবা শুরু করবেন এবং একটি GenerativeModel ইনস্ট্যান্স তৈরি করবেন।

আপনার প্রম্পটগুলি পরীক্ষা এবং পুনরাবৃত্তি করার জন্য, আমরা Google AI Studio ব্যবহার করার পরামর্শ দিচ্ছি।

ধাপ ১ : একটি প্রতিক্রিয়া স্কিমা সংজ্ঞায়িত করুন

একটি মডেলের আউটপুটের কাঠামো, ক্ষেত্রের নাম এবং প্রতিটি ক্ষেত্রের জন্য প্রত্যাশিত ডেটা টাইপ নির্দিষ্ট করার জন্য একটি প্রতিক্রিয়া স্কিমা সংজ্ঞায়িত করুন।

যখন একটি মডেল তার প্রতিক্রিয়া তৈরি করে, তখন এটি আপনার প্রম্পট থেকে ক্ষেত্রের নাম এবং প্রসঙ্গ ব্যবহার করে। আপনার উদ্দেশ্য স্পষ্ট কিনা তা নিশ্চিত করার জন্য, আমরা একটি স্পষ্ট কাঠামো, দ্ব্যর্থক ক্ষেত্রের নাম এবং এমনকি প্রয়োজনে বর্ণনা ব্যবহার করার পরামর্শ দিই।

প্রতিক্রিয়া স্কিমার জন্য বিবেচনা

আপনার প্রতিক্রিয়া স্কিমা লেখার সময় নিম্নলিখিত বিষয়গুলি মনে রাখবেন:

  • ইনপুট টোকেন সীমার জন্য প্রতিক্রিয়া স্কিমার আকার গণনা করা হয়।

  • রেসপন্স স্কিমা বৈশিষ্ট্যটি নিম্নলিখিত রেসপন্স MIME প্রকারগুলিকে সমর্থন করে:

    • application/json : রেসপন্স স্কিমায় সংজ্ঞায়িত JSON আউটপুট (কাঠামোগত আউটপুট প্রয়োজনীয়তার জন্য কার্যকর)

    • text/x.enum : রেসপন্স স্কিমায় সংজ্ঞায়িত একটি enum মান আউটপুট করে (শ্রেণীবদ্ধকরণের কাজের জন্য কার্যকর)

  • রেসপন্স স্কিমা বৈশিষ্ট্যটি নিম্নলিখিত স্কিমা ক্ষেত্রগুলিকে সমর্থন করে:

    enum
    items
    maxItems
    nullable
    properties
    required

    যদি আপনি একটি অসমর্থিত ক্ষেত্র ব্যবহার করেন, তাহলেও মডেলটি আপনার অনুরোধটি পরিচালনা করতে পারে, কিন্তু এটি ক্ষেত্রটিকে উপেক্ষা করে। মনে রাখবেন যে উপরের তালিকাটি OpenAPI 3.0 স্কিমা অবজেক্টের একটি উপসেট।

  • ডিফল্টরূপে, Firebase AI Logic SDK-এর জন্য, সমস্ত ক্ষেত্র প্রয়োজনীয় বলে বিবেচিত হবে যদি না আপনি একটি optionalProperties অ্যারেতে ঐচ্ছিক হিসাবে নির্দিষ্ট করেন। এই ঐচ্ছিক ক্ষেত্রগুলির জন্য, মডেলটি ক্ষেত্রগুলি পূরণ করতে পারে বা সেগুলি এড়িয়ে যেতে পারে। মনে রাখবেন যে আপনি যদি তাদের সার্ভার SDK বা তাদের API সরাসরি ব্যবহার করেন তবে এটি দুটি Gemini API প্রদানকারীর ডিফল্ট আচরণের বিপরীত।

ধাপ ২ : আপনার রেসপন্স স্কিমা ব্যবহার করে JSON আউটপুট তৈরি করুন

এই নমুনাটি চেষ্টা করার আগে, আপনার প্রকল্প এবং অ্যাপ সেট আপ করতে এই নির্দেশিকার "শুরু করার আগে" বিভাগটি সম্পূর্ণ করুন।
সেই বিভাগে, আপনি আপনার নির্বাচিত Gemini API প্রদানকারীর জন্য একটি বোতামে ক্লিক করবেন যাতে আপনি এই পৃষ্ঠায় প্রদানকারী-নির্দিষ্ট সামগ্রী দেখতে পান

নিম্নলিখিত উদাহরণটি দেখায় কিভাবে স্ট্রাকচার্ড JSON আউটপুট তৈরি করতে হয়।

যখন আপনি GenerativeModel ইনস্ট্যান্স তৈরি করবেন, তখন উপযুক্ত responseMimeType (এই উদাহরণে, application/json ) এবং সেই responseSchema উল্লেখ করুন যা আপনি মডেলটি ব্যবহার করতে চান।

সুইফট

animal-based characters."

let response = try await model.generateContent(prompt)
print(response.text ?? "No text in response.")

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 স্কোপ থেকে কল করতে হবে।
9;s card game, generate 10 animal-based characters."
val response = generativeModel.generateContent(prompt)
print(response.text)

// 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 টাইপ ফেরত দেয়।
Text);
      }

      @Override
      public void onFailure(Throwable t) {
        t.printStackTrace();
      }
    },
    executor);

// 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(&quo<t;For use in a children>'s card game, generate 10 animal-based characters.")
    .build();

// For illustrative purp<oses only. You should u>se an executor that fits your needs.
Executor executor = Executors.newSingleThreadExecutor();

ListenableFutureGenerateContentResponse response = model.generateContent(content);
Futures.addCallback(
    response,
    new FutureCallbackGenerateContentResponse() {
      @Override
      public void onSuccess(GenerateContentResponse result) {
        String resultText = result.getText();
        System.out.println(resultText);
      }

      @Override
      public void onFailure(Throwable t) {
        t.printStackTrace();
      }
    },
    executor);

Web

 = await model.generateContent(prompt)
console.log(result.response.text());

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

nerate 10 animal-based characters.";
final response = await model.generateContent([Content.text(prompt)]);
print(response.text);

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);

ঐক্য

cters.";

var response = await model.GenerateContentAsync(prompt);
UnityEngine.Debug.Log(response.Text ?? "No text in response.");

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.");

মডেল কীভাবে নির্বাচন করবেন তা শিখুনআপনার ব্যবহারের ক্ষেত্রে এবং অ্যাপের জন্য উপযুক্ত।

অতিরিক্ত উদাহরণ

আপনি কীভাবে স্ট্রাকচার্ড আউটপুট ব্যবহার এবং উৎপন্ন করতে পারেন তার কিছু অতিরিক্ত উদাহরণ এখানে দেওয়া হল।

আউটপুট হিসেবে enum মান তৈরি করুন

এই নমুনাটি চেষ্টা করার আগে, আপনার প্রকল্প এবং অ্যাপ সেট আপ করতে এই নির্দেশিকার "শুরু করার আগে" বিভাগটি সম্পূর্ণ করুন।
সেই বিভাগে, আপনি আপনার নির্বাচিত Gemini API প্রদানকারীর জন্য একটি বোতামে ক্লিক করবেন যাতে আপনি এই পৃষ্ঠায় প্রদানকারী-নির্দিষ্ট সামগ্রী দেখতে পান

নিম্নলিখিত উদাহরণে দেখানো হয়েছে কিভাবে একটি শ্রেণীবদ্ধকরণ কাজের জন্য একটি প্রতিক্রিয়া স্কিমা ব্যবহার করতে হয়। মডেলটিকে তার বর্ণনার উপর ভিত্তি করে একটি চলচ্চিত্রের ধরণ সনাক্ত করতে বলা হয়। আউটপুট হল একটি প্লেইন-টেক্সট এনাম মান যা মডেলটি প্রদত্ত প্রতিক্রিয়া স্কিমায় সংজ্ঞায়িত মানগুলির তালিকা থেকে নির্বাচন করে।

এই কাঠামোগত শ্রেণীবিভাগের কাজটি সম্পাদন করার জন্য, আপনাকে মডেল ইনিশিয়ালাইজেশনের সময় উপযুক্ত responseMimeType (এই উদাহরণে, text/x.enum ) এবং সেই responseSchema উল্লেখ করতে হবে যা আপনি মডেলটি ব্যবহার করতে চান।

সুইফট

 = try await model.generateContent(prompt)
print(response.text ?? "No text in response.")

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 স্কোপ থেকে কল করতে হবে।
;""
val response = generativeModel.generateContent(prompt)
print(response.text)

// 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 টাইপ ফেরত দেয়।
verride
      public void onFailure(Throwable t) {
        t.printStackTrace();
      }
    },
    executor);

// 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 conten<t = new Content.Builder>().addText(prompt).build();

// For illustrative purposes only. You should use an executor that fits <your needs.
Executor ex>ecutor = Executors.newSingleThreadExecutor();

ListenableFutureGenerateContentResponse response = model.generateContent(content);
Futures.addCallback(
    response,
    new FutureCallbackGenerateContentResponse() {
      @Override
      public void onSuccess(GenerateContentResponse result) {
        String resultText = result.getText();
        System.out.println(resultText);
      }

      @Override
      public void onFailure(Throwable t) {
        t.printStackTrace();
      }
    },
    executor);

Web

esult = await model.generateContent(prompt);
console.log(result.response.text());

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

t;";
final response = await model.generateContent([Content.text(prompt)]);
print(response.text);

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);

ঐক্য

yEngine.Debug.Log(response.Text ?? "No text in response.");

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.
&quot;;

var response = await model.GenerateContentAsync(prompt);
UnityEngine.Debug.Log(response.Text ?? "No text in response.");

মডেল কীভাবে নির্বাচন করবেন তা শিখুনআপনার ব্যবহারের ক্ষেত্রে এবং অ্যাপের জন্য উপযুক্ত।

কন্টেন্ট তৈরি নিয়ন্ত্রণের অন্যান্য বিকল্প

  • আপনার চাহিদা অনুযায়ী নির্দিষ্ট আউটপুট তৈরি করতে মডেলটিকে প্রভাবিত করতে প্রম্পট ডিজাইন সম্পর্কে আরও জানুন।
  • মডেল কীভাবে প্রতিক্রিয়া তৈরি করে তা নিয়ন্ত্রণ করতে মডেল প্যারামিটারগুলি কনফিগার করুন। জেমিনি মডেলগুলির জন্য, এই প্যারামিটারগুলির মধ্যে রয়েছে সর্বোচ্চ আউটপুট টোকেন, তাপমাত্রা, টপকে এবং টপপি। ইমেজেন মডেলগুলির জন্য, এর মধ্যে রয়েছে আকৃতির অনুপাত, ব্যক্তি তৈরি, ওয়াটারমার্কিং ইত্যাদি।
  • ঘৃণাত্মক বক্তব্য এবং যৌন স্পষ্ট বিষয়বস্তু সহ ক্ষতিকারক বলে বিবেচিত হতে পারে এমন প্রতিক্রিয়া পাওয়ার সম্ভাবনা সামঞ্জস্য করতে সুরক্ষা সেটিংস ব্যবহার করুন।
  • মডেলের আচরণ পরিচালনা করার জন্য সিস্টেম নির্দেশাবলী সেট করুন। এই বৈশিষ্ট্যটি একটি প্রস্তাবনার মতো যা আপনি শেষ ব্যবহারকারীর কাছ থেকে আরও কোনও নির্দেশের সংস্পর্শে আসার আগে যুক্ত করেন।


Firebase AI Logic এর সাথে আপনার অভিজ্ঞতা সম্পর্কে মতামত দিন।