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

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

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

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

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

  • Constrain how a model can respond during classification tasks.
    উদাহরণস্বরূপ, আপনি মডেলটি তৈরি করে এমন লেবেলের পরিবর্তে (যার মধ্যে good , positive , positive , অথবা bad এর মতো পরিবর্তনশীলতার মাত্রা থাকতে পারে) একটি নির্দিষ্ট সেট লেবেল (উদাহরণস্বরূপ, enums এর একটি নির্দিষ্ট সেট যেমন positive এবং negative ) দিয়ে মডেলটি negative টেক্সট ব্যবহার করতে bad

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

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

শুরু করার আগে

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

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

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

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

Define a response schema to specify the structure of a model's output, the field names, and the expected data type for each field.

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

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

Keep the following in mind when writing your response schema:

  • The size of the response schema counts towards the input token limit.

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

    • application/json : output JSON as defined in the response schema (useful for structured output requirements)

    • text/x.enum : output an enum value as defined in the response schema (useful for classification tasks)

  • The response schema feature supports the following schema fields:

    enum
    items
    maxItems
    nullable
    properties
    required

    If you use an unsupported field, the model can still handle your request, but it ignores the field. Note that the list above is a subset of the OpenAPI 3.0 schema object.

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

Step 2 : Generate JSON output using your response schema

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

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

When you create the GenerativeModel instance, specify the appropriate responseMimeType (in this example, application/json ) as well as the responseSchema that you want the model to use.

সুইফট


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-2.5-flash",
  // 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

For Kotlin, the methods in this SDK are suspend functions and need to be called from a Coroutine scope .

// 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-2.5-flash",
    // 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

For Java, the streaming methods in this SDK return a Publisher type from the Reactive Streams library .

// 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-2.5-flash",
            /* 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-2.5-flash",
  // 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-2.5-flash',
        // 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-2.5-flash",
  // 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.");

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

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

Here are some additional examples of how you can use and generate structured output.

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

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

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

এই কাঠামোগত শ্রেণীবিভাগের কাজটি সম্পাদন করার জন্য, আপনাকে মডেল ইনিশিয়ালাইজেশনের সময় উপযুক্ত 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-2.5-flash",
  // 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

For Kotlin, the methods in this SDK are suspend functions and need to be called from a Coroutine scope .

// 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-2.5-flash",
    // 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-2.5-flash",
            /* 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-2.5-flash",
  // 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-2.5-flash',
        // 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-2.5-flash",
  // 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.");

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

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

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


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