در هر فراخوانی مدل، میتوانید پیکربندی مدل را ارسال کنید تا نحوه تولید پاسخ توسط مدل را کنترل کنید. هر مدل از گزینههای پیکربندی مختلفی پشتیبانی میکند،
مثل تنظیم maxOutputTokens یا پیکربندیهای تخصصی برای فکر کردن،
شیوههای پاسخ، تصاویر، یا گفتار.
برای اکثر موارد استفاده هنگام دسترسی به مدل 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',
config: 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
);
در بخش بعدی این صفحه میتوانید توضیح هر پارامتر را ببینید.
بااستفاده از Google AI Studio میتوانید پیاموارهها و پیکربندیهای مدل را آزمایش کنید.LiveGenerationConfig برای Gemini Live API مدل
|
روی ارائهدهنده Gemini API خود کلیک کنید تا محتوا و کد مخصوص ارائهدهنده را در این صفحه مشاهده کنید. |
فقط هنگام استفاده از مدلهای Gemini Live API، LiveGenerationConfig تنظیم کنید.
پیکربندی برای طول عمر نمونه LiveModel حفظ میشود. اگر میخواهید از پیکربندی دیگری استفاده کنید، نمونه جدیدی با پیکربندی متفاوت ایجاد کنید و از آن استفاده کنید.
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.agentPlatform()).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
);
// ...
در بخش بعدی این صفحه میتوانید توضیح هر پارامتر را ببینید.
بااستفاده از Google AI Studio میتوانید پیاموارهها و پیکربندیهای مدل را آزمایش کنید.شرح پارامترها
جدول زیر نمای کلی سطح بالایی از پارامترهای دردسترس است. برخیاز پارامترها فقط برای مدلهای خاصی قابلاعمال هستند.
| پارامتر | شرح | محدودیتها | مقدار پیشفرض |
|---|---|---|---|
مُهر زمان صداaudioTimestamp
|
درک مُهر زمان را برای فایلهای ورودی فقط صوتی فعال میکند. |
بولی
فقط هنگام استفاده از پیکربندی |
false
|
حداکثر دادهواحدهای بروندادmaxOutputTokens
|
حداکثر تعداد نشانههایی را که میتوان در پاسخ تولید کرد مشخص میکند. | --- | --- |
توقف توالیهاstopSequences
|
فهرستی از رشتهها را مشخص میکند که به مدل میگوید اگر یکی از رشتهها در پاسخ مشاهده شد، تولید محتوا را متوقف کند. |
فقط هنگام استفاده از پیکربندی برای مدلهای تصویر («نانو موز») یا مدلهای TTS قابلاعمال نیست. |
--- |
| پیکربندیهای تخصصی | |||
درحال فکر کردنthinkingConfig
|
«فرایند فکر کردن» مدلها را هنگام تولید پاسخ کنترل میکند.
|
مقادیر پشتیبانیشده: به اسناد تفکر مراجعه کنید برای مدلهای «تبدیل نوشتار به گفتار» کاربرد ندارد.
Firebase AI Logic هنوز از تنظیم
|
بسته به مدل |
روشهای پاسخresponseModalities
|
نوع برونداد را مشخص میکند (مثل نوشتار، صدا، یا تصویر). | فقط هنگام استفاده از Gemini مدلهای تصویر («مدلهای Nano Banana»)، مدلهای TTS، و Live API مدلها قابلاعمال (و الزامی) است. | --- |
مشخصات تصویرimageConfig
|
نسبت ابعادی و وضوح تصاویر تولیدشده را مشخص میکند. |
مقادیر پشتیبانیشده: به پیکربندی تولید تصویر مراجعه کنید فقط درصورت استفاده از مدلهای Gemini تصویر («Nano Banana» مدلها) قابلاعمال است. |
نسبت ابعادی ۱:۱ (مربع) وضوح ۱۰۲۴x۱۰۲۴ |
گفتار (صدا)speechConfig
|
صدای مورد استفاده برای خروجی صوتی را مشخص میکند. |
فقط هنگام استفاده از مدلهای «تبدیل نوشتار به گفتار» و مدلهای Live API قابلاعمال است. برای مدلهای TTS لازم است. |
Puck
|
گزینههای دیگر برای کنترل تولید محتوا
- درباره طراحی پیامواره بیشتر بدانید تا بتوانید بر مدل تأثیر بگذارید و بروندادهای خاص نیازهایتان را تولید کند.
- از تنظیمات ایمنی برای تنظیم احتمال دریافت پاسخهایی که ممکن است مضر درنظر گرفته شوند، ازجمله سخنان مشوق عداوت و تنفر و محتوای جنسی صریح، استفاده کنید.
- دستورالعملهای سیستم را برای هدایت رفتار مدل تنظیم کنید. این ویژگی مانند پیشگفتاری است که قبلاز اینکه مدل با دستورالعملهای بیشتری از کاربر نهایی مواجه شود اضافه میکنید.
- برای مشخص کردن طرحواره برونداد خاص، طرحواره پاسخ را همراه با پیامواره ارسال کنید. این ویژگی معمولاً هنگام تولید برونداد JSON استفاده میشود، اما میتوان از آن برای وظایف طبقهبندی (مثل زمانی که میخواهید مدل از برچسبها یا نشانهای خاصی استفاده کند) نیز استفاده کرد.