در هر فراخوانی به مدل، میتوانید پیکربندی مدل را ارسال کنید تا نحوه تولید پاسخ توسط مدل را کنترل کنید. هر مدل از گزینههای پیکربندی مختلفی پشتیبانی میکند،
مانند تنظیم maxOutputTokens یا پیکربندیهای تخصصی برای تفکر،
حالتهای پاسخ، تصاویر، گفتار، یا تشخیص فعالیت گفتاری (VAD).
برای اکثر موارد استفاده هنگام دسترسی به مدل Gemini،
مدل را بااستفاده از GenerationConfig پیکربندی میکنید. اما اگر درحال پیکربندی مدل
Gemini Live API هستید، از LiveGenerationConfig استفاده میکنید.
این صفحه نحوه راهاندازی پیکربندی برای مدلهای Gemini را نشان میدهد و جدولی از پارامترهای دردسترس ارائه میدهد.
پرش به پیکربندی Gemini پرش به پیکربندی Gemini Live API
GenerationConfig برای مدلهای Gemini
|
روی ارائهدهنده Gemini API کلیک کنید تا محتوا و کد مختص ارائهدهنده را در این صفحه ببینید. |
برای اکثر مدلهای Gemini، ازجمله مدلهای با کاربرد عمومی، مدلهای تولیدکننده تصویر (Nano Banana)، و مدلهای نوشتار به گفتار (TTS)، GenerationConfig تنظیم کنید.
پیکربندی برای طول عمر نمونه GenerativeModel حفظ میشود. اگر میخواهید از پیکربندی دیگری استفاده کنید، نمونه جدیدی با پیکربندی متفاوت ایجاد و استفاده کنید.
مثال زیر پیکربندی مدل بسیار پایهای را نشان میدهد. برای گزینههای بیشتر (بهویژه برای مدلهای تخصصی)، جدول پارامترهای دردسترس را در ادامه این صفحه ببینید.
Swift
مقادیر پارامترها را در
GenerationConfig
بهعنوان بخشی از ایجاد نمونه GenerativeModel تنظیم کنید.
import FirebaseAILogic
// Set parameter values in a `GenerationConfig`.
// IMPORTANT: Example values shown here. Make sure to update for your use case.
// For the latest general-use Gemini models, the following parameters are now unsupported:
// temperature, top-K, top-P, frequency penalty, presence penalty, and candidate count
let config = GenerationConfig(
maxOutputTokens: 200,
stopSequences: ["red"]
)
// Initialize the Gemini Developer API backend service.
// Specify the config as part of creating the `GenerativeModel` instance.
let model = FirebaseAI.firebaseAI(backend: .googleAI()).generativeModel(
modelName: "GEMINI_MODEL_NAME",
generationConfig: config
)
// ...
Kotlin
مقادیر پارامترها را در
GenerationConfig
بهعنوان بخشی از ایجاد نمونه GenerativeModel تنظیم کنید.
// ...
// Set parameter values in a `GenerationConfig`.
// IMPORTANT: Example values shown here. Make sure to update for your use case.
// For the latest general-use Gemini models, the following parameters are now unsupported:
// temperature, top-K, top-P, frequency penalty, presence penalty, and candidate count
val config = generationConfig {
maxOutputTokens = 200
stopSequences = listOf("red")
}
// Initialize the Gemini Developer API backend service.
// Specify the config as part of creating the `GenerativeModel` instance.
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel(
modelName = "GEMINI_MODEL_NAME",
generationConfig = config
)
// ...
Java
مقادیر پارامترها را در
GenerationConfig
بهعنوان بخشی از ایجاد نمونه GenerativeModel تنظیم کنید.
// ...
// Set parameter values in a `GenerationConfig`.
// IMPORTANT: Example values shown here. Make sure to update for your use case.
// For the latest general-use Gemini models, the following parameters are now unsupported:
// temperature, top-K, top-P, frequency penalty, presence penalty, and candidate count
GenerationConfig.Builder configBuilder = new GenerationConfig.Builder();
configBuilder.maxOutputTokens = 200;
configBuilder.stopSequences = List.of("red");
GenerationConfig config = configBuilder.build();
// Specify the config as part of creating the `GenerativeModel` instance.
GenerativeModelFutures model = GenerativeModelFutures.from(
FirebaseAI.getInstance(GenerativeBackend.googleAI())
.generativeModel(
"GEMINI_MODEL_NAME",
config
);
);
// ...
Web
مقادیر پارامترها را در
GenerationConfig
بهعنوان بخشی از ایجاد نمونه GenerativeModel تنظیم کنید.
// ...
// Initialize the Gemini Developer API backend service.
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
// Set parameter values in a `GenerationConfig`.
// IMPORTANT: Example values shown here. Make sure to update for your use case.
// For the latest general-use Gemini models, the following parameters are now unsupported:
// temperature, top-K, top-P, frequency penalty, presence penalty, and candidate count
const generationConfig = {
maxOutputTokens: 200,
stopSequences: ["red"],
};
// Specify the config as part of creating the `GenerativeModel` instance.
const model = getGenerativeModel(ai, { model: "GEMINI_MODEL_NAME", generationConfig });
// ...
Dart
مقادیر پارامترها را در
GenerationConfig
بهعنوان بخشی از ایجاد نمونه GenerativeModel تنظیم کنید.
// ...
// Set parameter values in a `GenerationConfig`.
// IMPORTANT: Example values shown here. Make sure to update for your use case.
// For the latest general-use Gemini models, the following parameters are now unsupported:
// temperature, top-K, top-P, frequency penalty, presence penalty, and candidate count
final generationConfig = GenerationConfig(
maxOutputTokens: 200,
stopSequences: ["red"],
);
// Initialize the Gemini Developer API backend service.
// Specify the config as part of creating the `GenerativeModel` instance.
final model = FirebaseAI.googleAI().generativeModel(
model: 'GEMINI_MODEL_NAME',
generationConfig: generationConfig,
);
// ...
Unity
مقادیر پارامترها را در
GenerationConfig
بهعنوان بخشی از ایجاد نمونه GenerativeModel تنظیم کنید.
// ...
// Set parameter values in a `GenerationConfig`.
// IMPORTANT: Example values shown here. Make sure to update for your use case.
// For the latest general-use Gemini models, the following parameters are now unsupported:
// temperature, top-K, top-P, frequency penalty, presence penalty, and candidate count
var generationConfig = new GenerationConfig(
maxOutputTokens: 200,
stopSequences: new string[] { "red" }
);
// Initialize the Gemini Developer API backend service.
// Specify the config as part of creating the `GenerativeModel` instance.
var ai = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI());
var model = ai.GetGenerativeModel(
modelName: "GEMINI_MODEL_NAME",
generationConfig: generationConfig
);
LiveGenerationConfig برای مدلهای Gemini Live API
|
روی ارائهدهنده Gemini API کلیک کنید تا محتوا و کد مختص ارائهدهنده را در این صفحه ببینید. |
LiveGenerationConfig را فقط هنگام استفاده از مدلهای Gemini Live API تنظیم کنید.
پیکربندی برای طول عمر نمونه LiveModel حفظ میشود. اگر میخواهید از پیکربندی دیگری استفاده کنید، نمونه جدیدی با پیکربندی متفاوت ایجاد و استفاده کنید.
مثال زیر پیکربندی مدل بسیار پایهای را نشان میدهد. برای گزینههای بیشتر (مثل پیکربندی تشخیص فعالیت گفتاری (VAD))، جدول پارامترهای دردسترس را در ادامه این صفحه ببینید.
Swift
مقادیر پارامترها را در
liveGenerationConfig
درطول مقداردهی اولیه نمونه LiveModel تنظیم کنید:
// ...
// Set parameter values in a `LiveGenerationConfig` (example values shown here).
let config = LiveGenerationConfig(
maxOutputTokens: 200,
responseModalities: [.audio],
speech: SpeechConfig(voiceName: "Fenrir"),
)
// Specify the config as part of creating the `liveModel` instance.
let liveModel = FirebaseAI.firebaseAI(backend: .googleAI()).liveModel(
modelName: "GEMINI_LIVE_MODEL_NAME",
generationConfig: config
)
// ...
Kotlin
مقادیر پارامترها را در
LiveGenerationConfig
بهعنوان بخشی از ایجاد نمونه LiveModel تنظیم کنید.
// ...
// Set parameter values in a `LiveGenerationConfig` (example values shown here).
val config = liveGenerationConfig {
maxOutputTokens = 200
responseModality = ResponseModality.AUDIO
speechConfig = SpeechConfig(voice = Voice("FENRIR"))
}
// Specify the config as part of creating the `LiveModel` instance.
val liveModel = Firebase.ai(backend = GenerativeBackend.googleAI()).liveModel(
modelName = "GEMINI_LIVE_MODEL_NAME",
generationConfig = config
)
// ...
Java
مقادیر پارامترها را در
LiveGenerationConfig
بهعنوان بخشی از ایجاد نمونه LiveModel تنظیم کنید.
// ...
// Set parameter values in a `LiveGenerationConfig` (example values shown here).
LiveGenerationConfig.Builder configBuilder = new LiveGenerationConfig.Builder();
configBuilder.setMaxOutputTokens(200);
configBuilder.setResponseModality(ResponseModality.AUDIO);
configBuilder.setSpeechConfig(new SpeechConfig(new Voice("FENRIR")));
LiveGenerationConfig config = configBuilder.build();
// Specify the config as part of creating the `LiveModel` instance.
LiveGenerativeModel lm = FirebaseAI.getInstance(GenerativeBackend.googleAI()).liveModel(
"GEMINI_LIVE_MODEL_NAME",
config
);
// ...
Web
مقادیر پارامترها را در
LiveGenerationConfig
درطول مقداردهی اولیه نمونه LiveGenerativeModel تنظیم کنید:
// ...
// Initialize the Gemini Developer API backend service.
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
// Set parameter values in a `LiveGenerationConfig` (example values shown here).
const liveGenerationConfig = {
maxOutputTokens: 200,
responseModalities: [ResponseModality.AUDIO],
speechConfig: {
voiceConfig: {
prebuiltVoiceConfig: { voiceName: "Fenrir" },
},
},
};
// Specify the config as part of creating the `LiveGenerativeModel` instance.
const liveModel = getLiveGenerativeModel(ai, {
model: "GEMINI_LIVE_MODEL_NAME",
liveGenerationConfig,
});
// ...
Dart
مقادیر پارامترها را در
LiveGenerationConfig
بهعنوان بخشی از ایجاد نمونه LiveGenerativeModel تنظیم کنید.
// ...
// Set parameter values in a `LiveGenerationConfig` (example values shown here).
final config = LiveGenerationConfig(
maxOutputTokens: 200,
responseModalities: [ResponseModalities.audio],
speechConfig: SpeechConfig(voiceName: 'Fenrir'),
);
// Specify the config as part of creating the `liveGenerativeModel` instance.
final liveModel = FirebaseAI.googleAI().liveGenerativeModel(
model: 'GEMINI_LIVE_MODEL_NAME',
liveGenerationConfig: config,
);
// ...
Unity
مقادیر پارامترها را در
LiveGenerationConfig
بهعنوان بخشی از ایجاد نمونه LiveModel تنظیم کنید.
// ...
// Set parameter values in a `LiveGenerationConfig` (example values shown here).
var config = new LiveGenerationConfig(
maxOutputTokens: 200,
responseModalities: new[] { ResponseModality.Audio },
speechConfig: SpeechConfig.UsePrebuiltVoice("Fenrir")
);
// Specify the config as part of creating the `LiveModel` instance.
var liveModel = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI()).GetLiveModel(
modelName: "GEMINI_LIVE_MODEL_NAME",
liveGenerationConfig: config
);
// ...
پارامترهای مدل دردسترس
جدول زیر نمای کلی سطح بالایی از پارامترهای دردسترس برای پیکربندی مدل است. برخی پارامترها فقط برای مدلهای خاصی قابلاعمال هستند.
| پارامتر | شرح | محدودیتها | مقدار پیشفرض |
|---|---|---|---|
مُهر زمان صداaudioTimestamp
|
درک مُهر زمان را برای فایلهای ورودی فقط صوتی فعال میکند. |
بولی
فقط زمانی قابلاعمال است که از پیکربندی |
false
|
بیشینه دادهواحدهای بروندادmaxOutputTokens
|
حداکثر تعداد نشانههایی را که میتوان در پاسخ تولید کرد مشخص میکند.
برای |
--- | --- |
توقف توالیهاstopSequences
|
فهرستی از رشتهها را مشخص میکند که به مدل میگوید اگر یکی از رشتهها در پاسخ وجود داشت، تولید محتوا را متوقف کند. |
فقط هنگام استفاده از پیکربندی برای مدلهای Nano Banana یا «نوشتار به گفتار» کاربرد ندارد. |
--- |
| پیکربندیهای تخصصی | |||
درحال فکر کردنthinkingConfig
|
«فرایند تفکر» مدلها را هنگام تولید پاسخ کنترل میکند.
|
مقادیر پشتیبانیشده: اسناد تفکر را ببینید برای مدلهای تبدیل نوشتار به گفتار قابل اجرا نیست.
Firebase AI Logic هنوز از تنظیم
|
بسته به مدل |
حالتهای پاسخresponseModalities
|
نوع خروجی (مانند نوشتار، صدا، یا تصویر) را مشخص میکند. | فقط هنگام استفاده از مدلهای Nano Banana، TTS، و Live API قابلاعمال (و الزامی) است. | --- |
ویژگیهای تصویرimageConfig
|
نسبت ابعادی و وضوح تصاویر تولیدشده را مشخص میکند. |
مقادیر پشتیبانیشده: به پیکربندی تولید تصویر مراجعه کنید فقط هنگام استفاده از مدلهای Nano Banana قابلاجرا است. |
نسبت ابعادی ۱:۱ (مربع) وضوح ۱۰۲۴x۱۰۲۴ |
گفتار (صدا)speechConfig
|
صدای مورداستفاده برای خروجی صوتی را مشخص میکند. |
فقط هنگام استفاده از مدلهای «تبدیل نوشتار به گفتار» و مدلهای Live API قابلاجرا است. برای مدلهای TTS لازم است. |
Puck
|
تشخیص فعالیت گفتاری (VAD)realtimeInputConfig
|
تشخیص فعالیت گفتاری (VAD)، مدیریت وقفه، و پوشش بافت نوبت را پیکربندی میکند، یا VAD خودکار را غیرفعال میکند. |
مقادیر پشتیبانیشده: به پیکربندی VAD مراجعه کنید فقط هنگام استفاده از مدلهای Live API قابلاجرا است. |
VAD فعال است مقادیر پیشفرض را برای تنظیمات جداگانه ببینید. |
گزینههای دیگر برای کنترل تولید محتوا
- درباره طراحی پیامواره بیشتر بدانید تا بتوانید بر مدل تأثیر بگذارید تا خروجی خاصی را برای نیازهایتان تولید کند.
- از تنظیمات ایمنی برای تنظیم احتمال دریافت پاسخهایی که ممکن است مضر تلقی شوند، ازجمله سخنان مشوق عداوت و تنفر و محتوای صریح جنسی، استفاده کنید.
- دستورالعملهای سیستم را تنظیم کنید تا رفتار مدل را هدایت کنید. این ویژگی مانند مقدمهای است که قبلاز اینکه مدل درمعرض دستورالعملهای بیشتر ازسوی کاربر نهایی قرار گیرد، اضافه میکنید.
- یک طرحواره پاسخ را همراه با پیامواره ارسال کنید تا طرحواره برونداد خاصی را مشخص کنید. این ویژگی بیشتر هنگام تولید خروجی JSON استفاده میشود، اما میتوان از آن برای تکالیف طبقهبندی نیز استفاده کرد (مثلاً وقتی میخواهید مدل از برچسبها یا برچسبهای خاصی استفاده کند).