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

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

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

এখানে কিছু উদাহরণ আছে:

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

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

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

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

আপনি শুরু করার আগে

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

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

আপনার প্রম্পটে পরীক্ষা এবং পুনরাবৃত্তি করার জন্য এবং এমনকি একটি জেনারেট করা কোড স্নিপেট পাওয়ার জন্য, আমরা Google AI Studio ব্যবহার করার পরামর্শ দিই।

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

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

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

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

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

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

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

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

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

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

    enum
    items
    maxItems
    nullable
    properties
    required

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

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

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

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

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

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

সুইফট


import FirebaseAI

// 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.0-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

কোটলিনের জন্য, এই 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-2.0-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

জাভার জন্য, এই SDK-এর স্ট্রিমিং পদ্ধতিগুলি প্রতিক্রিয়াশীল স্ট্রীমস লাইব্রেরি থেকে একটি 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-2.0-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.0-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.0-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.0-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.");

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

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

আপনি কীভাবে কাঠামোগত আউটপুট ব্যবহার এবং তৈরি করতে পারেন তার কিছু অতিরিক্ত উদাহরণ এখানে রয়েছে।

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

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

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

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

সুইফট


import FirebaseAI

// 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.0-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

কোটলিনের জন্য, এই 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-2.0-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-এর স্ট্রিমিং পদ্ধতিগুলি প্রতিক্রিয়াশীল স্ট্রীমস লাইব্রেরি থেকে একটি 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.0-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.0-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.0-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.0-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.");

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

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

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


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