في كل طلب إلى نموذج، يمكنك إرسال إعدادات النموذج للتحكّم في كيفية
إنشاء النموذج للردّ. يتيح كل نموذج خيارات ضبط مختلفة، مثل ضبط maxOutputTokens أو إعدادات مخصّصة للتفكير أو طرق الاستجابة أو الصور أو الكلام أو رصد النشاط الصوتي (VAD).
في معظم حالات الاستخدام، عند الوصول إلى نموذج Gemini، يمكنك ضبط النموذج باستخدام GenerationConfig. ومع ذلك، إذا كنت بصدد ضبط نموذج Gemini Live API، عليك استخدام LiveGenerationConfig.
توضّح هذه الصفحة كيفية ضبط إعدادات نماذج Gemini وتوفّر جدولاً بالمعلَمات المتاحة.
الانتقال إلى إعدادات Gemini الانتقال إلى إعدادات Gemini Live API
GenerationConfig لـ Gemini نموذج
|
انقر على مزوّد خدمة Gemini API لعرض المحتوى والرمز البرمجي الخاصَّين بالمزوّد على هذه الصفحة. |
يمكنك ضبط GenerationConfig لمعظم نماذج Gemini، بما في ذلك
النماذج العامة ونماذج إنشاء الصور (Nano Banana)
ونماذج تحويل النص إلى كلام (TTS).
يتم الاحتفاظ بالإعدادات طوال مدة استخدام مثيل 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. إذا أردت استخدام إعدادات مختلفة، عليك إنشاء مثيل جديد واستخدامه
مع إعدادات مختلفة.
يعرض المثال التالي إعدادات نموذج أساسية جدًا. للحصول على خيارات إضافية (مثل ضبط ميزة "رصد النشاط الصوتي")، يُرجى الاطّلاع على جدول المَعلمات المتاحة لاحقًا في هذه الصفحة.
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. |
نسبة العرض إلى الارتفاع 1:1 (مربّع) دقة 1024x1024 |
الكلام (الصوت)speechConfig
|
تحدّد هذه السمة الصوت المستخدَم في الردّ الصوتي. |
لا ينطبق ذلك إلا عند استخدام نماذج تحويل النص إلى كلام ونماذج Live API. مطلوبة لنماذج "تحويل النص إلى كلام". |
Puck
|
رصد النشاط الصوتي (VAD)realtimeInputConfig
|
يضبط هذا الإعداد ميزة "رصد النشاط الصوتي" (VAD) ومعالجة المقاطعات وتغطية سياق الدور، أو يوقف ميزة "رصد النشاط الصوتي" التلقائية. |
القيم المسموح بها: يُرجى الاطّلاع على ضبط ميزة "تسليم التطبيقات الافتراضية" لا ينطبق ذلك إلا عند استخدام نماذج Live API. |
تم تفعيل ميزة "تسليم التطبيقات الافتراضية" (VAD) يمكنك الاطّلاع على القيم التلقائية للإعدادات الفردية. |
خيارات أخرى للتحكّم في إنشاء المحتوى
- مزيد من المعلومات حول تصميم الطلبات للتأثير في النموذج لإنشاء مخرجات مخصّصة لاحتياجاتك
- استخدِم إعدادات الأمان لضبط احتمالية الحصول على ردود قد تُعتبر ضارة، بما في ذلك الكلام الذي يحض على الكراهية والمحتوى الجنسي الفاضح.
- اضبط تعليمات النظام لتوجيه سلوك النموذج. تشبه هذه الميزة مقدمة تضيفها قبل أن يتلقّى النموذج أي تعليمات أخرى من المستخدم النهائي.
- مرِّر مخطط استجابة مع الطلب لتحديد مخطط ناتج معيّن. تُستخدم هذه الميزة شائع الاستخدام عند إنشاء مخرجات JSON، ولكن يمكن استخدامها أيضًا لمهام التصنيف (مثل عندما تريد أن يستخدم النموذج تصنيفات أو علامات معيّنة).