Petunjuk sistem seperti "preamble" yang Anda tambahkan sebelum model diekspos ke petunjuk lebih lanjut dari pengguna akhir. Dengan begitu, Anda dapat mengarahkan perilaku model berdasarkan kebutuhan dan kasus penggunaan spesifik Anda.
Petunjuk sistem didukung oleh semua model Gemini.
Saat Anda menetapkan petunjuk sistem, Anda memberi konteks tambahan kepada model untuk memahami tugas, memberikan respons yang lebih disesuaikan, dan mematuhi pedoman tertentu terkait interaksi pengguna secara penuh dengan model. Anda dapat menentukan perilaku tingkat produk dalam petunjuk sistem, terpisah dari perintah yang diberikan oleh pengguna akhir. Misalnya, Anda dapat menyertakan hal-hal seperti peran atau persona, informasi kontekstual, dan petunjuk pemformatan.
Anda dapat menggunakan petunjuk sistem dengan berbagai cara, termasuk:
- Menentukan persona atau peran (misalnya, untuk chatbot)
- Menentukan format output (Markdown, YAML, dll.)
- Menentukan gaya dan nuansa output (misalnya, panjang respons, formalitas, dan target tingkat bacaan)
- Menentukan sasaran atau aturan untuk tugas (misalnya, menampilkan cuplikan kode tanpa penjelasan lebih lanjut)
- Memberikan konteks tambahan untuk perintah (misalnya, batas informasi)
Saat petunjuk sistem ditetapkan, petunjuk tersebut akan berlaku untuk seluruh permintaan. Saat disertakan dalam perintah, fitur ini berfungsi di tiap percakapan yang terjadi antara pengguna dan model. Meskipun petunjuk sistem terpisah dari konten perintah, petunjuk tersebut tetap merupakan bagian dari perintah Anda secara keseluruhan dan oleh karena itu tunduk pada kebijakan penggunaan data standar.
Mengatur petunjuk sistem
|
Klik penyedia Gemini API untuk melihat konten dan kode khusus penyedia di halaman ini. |
Menetapkan petunjuk sistem untuk kasus penggunaan umum
Swift
Anda menentukan
systemInstruction
saat membuat instance GenerativeModel.
import FirebaseAILogic
// Specify the system instructions as part of creating the `GenerativeModel` instance
let model = FirebaseAI.firebaseAI(backend: .googleAI()).generativeModel(
modelName: "GEMINI_MODEL_NAME",
systemInstruction: ModelContent(role: "system", parts: "You are a cat. Your name is Neko.")
)
Kotlin
Anda menentukan
systemInstruction
saat membuat instance GenerativeModel.
// Specify the system instructions as part of creating the `GenerativeModel` instance.
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel(
modelName = "GEMINI_MODEL_NAME",
systemInstruction = content { text("You are a cat. Your name is Neko.") }
)
Java
Anda menentukan
systemInstruction
saat membuat instance GenerativeModel.
// Specify the system instructions as part of creating the `GenerativeModel` instance.
GenerativeModel ai = FirebaseAI.getInstance(GenerativeBackend.googleAI())
.generativeModel(
/* modelName */ "GEMINI_MODEL_NAME",
/* generationConfig (optional) */ null,
/* safetySettings (optional) */ null,
/* requestOptions (optional) */ new RequestOptions(),
/* tools (optional) */ null,
/* toolsConfig (optional) */ null,
/* systemInstruction (optional) */ new Content.Builder().addText("You are a cat. Your name is Neko.").build()
);
GenerativeModelFutures model = GenerativeModelFutures.from(ai);
Web
Anda menentukan
systemInstruction
saat membuat instance GenerativeModel.
// ...
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
// Specify the system instructions as part of creating the `GenerativeModel` instance
const model = getGenerativeModel(ai, {
model: "GEMINI_MODEL_NAME",
systemInstruction: "You are a cat. Your name is Neko."
});
Dart
Anda menentukan
systemInstruction
saat membuat instance GenerativeModel.
// ...
// Specify the system instructions as part of creating the `GenerativeModel` instance.
final model = FirebaseAI.googleAI().generativeModel(
model: 'GEMINI_MODEL_NAME',
systemInstruction: Content.system('You are a cat. Your name is Neko.'),
);
// ...
Unity
Anda menentukan
systemInstruction
saat membuat instance GenerativeModel.
// ...
var ai = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI());
// Specify the system instructions as part of creating the `GenerativeModel` instance.
var model = ai.GetGenerativeModel(
modelName: "GEMINI_MODEL_NAME",
systemInstruction: ModelContent.Text("You are a cat. Your name is Neko.")
);
Menetapkan petunjuk sistem untuk Gemini Live API
Swift
Anda menentukan
systemInstruction
saat membuat instance LiveModel.
// ...
// Specify the system instructions as part of creating the `liveModel` instance
let liveModel = FirebaseAI.firebaseAI(backend: .googleAI()).liveModel(
modelName: "GEMINI_LIVE_MODEL_NAME",
systemInstruction: ModelContent(role: "system", parts: "You are a cat. Your name is Neko."),
// ...
)
// ...
Kotlin
Anda menentukan
systemInstruction
saat membuat instance LiveModel.
// ...
// Specify the system instructions as part of creating the `LiveModel` instance.
val liveModel = Firebase.ai(backend = GenerativeBackend.googleAI()).liveModel(
modelName = "GEMINI_LIVE_MODEL_NAME",
systemInstruction = content { text("You are a cat. Your name is Neko.") },
// ...
)
// ...
Java
Anda menentukan
systemInstruction
saat membuat instance LiveModel.
// ...
// Specify the system instructions as part of creating the `LiveModel` instance.
LiveGenerativeModel lm = FirebaseAI.getInstance(GenerativeBackend.googleAI()).liveModel(
/* modelName */ "GEMINI_LIVE_MODEL_NAME",
/* systemInstruction (optional) */ new Content.Builder().addText("You are a cat. Your name is Neko.").build()
// ...
);
LiveModelFutures liveModel = LiveModelFutures.from(lm);
// ...
Web
Anda menentukan
systemInstruction
saat membuat instance LiveGenerativeModel.
// ...
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
// Specify the system instructions as part of creating the `LiveGenerativeModel` instance.
const liveModel = getLiveGenerativeModel(ai, {
model: "GEMINI_LIVE_MODEL_NAME",
systemInstruction: "You are a cat. Your name is Neko.",
// ...
});
// ...
Dart
Anda menentukan
systemInstruction
saat membuat instance LiveGenerativeModel.
// ...
// Specify the system instructions as part of creating the `liveGenerativeModel` instance.
final liveModel = FirebaseAI.googleAI().liveGenerativeModel(
model: 'GEMINI_LIVE_MODEL_NAME',
systemInstruction: Content.system('You are a cat. Your name is Neko.'),
// ...
);
// ...
Unity
Anda menentukan
systemInstruction
saat membuat instance LiveModel.
// ...
// Specify the system instructions as part of creating the `LiveModel` instance.
var liveModel = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI()).GetLiveModel(
modelName: "GEMINI_LIVE_MODEL_NAME",
systemInstruction: ModelContent.Text("You are a cat. Your name is Neko."),
// ...
);
// ...
Contoh petunjuk sistem
Berikut beberapa contoh petunjuk sistem yang membantu mengarahkan perilaku model yang diharapkan. Beberapa contoh juga menunjukkan contoh perintah yang dapat dibantu oleh petunjuk sistem.
Pembuatan kode
System instruction:
You are a coding expert that specializes in rendering code for frontend interfaces. When I describe a component of a website I want to build, please return the HTML and CSS needed to do so. Do not give an explanation for this code. Also offer some UI design suggestions.Perintah pengguna:
Buat kotak di tengah halaman yang berisi pilihan gambar yang berputar, masing-masing dengan teks. Gambar di tengah halaman harus memiliki bayangan di belakangnya agar terlihat menonjol. Halaman ini juga harus ditautkan ke halaman lain di situs tersebut. Biarkan URL kosong agar saya dapat mengisinya.
Chatbot musik
System instruction:
You will respond as a music historian, demonstrating comprehensive knowledge across diverse musical genres and providing relevant examples. Gaya bahasa Anda akan ceria dan antusias, menyebarkan kegembiraan musik. Jika pertanyaan tidak terkait dengan musik, responsnya harus, "Hal itu di luar pengetahuan saya".Perintah pengguna:
Jika seseorang lahir pada tahun enam puluhan, apa genre musik paling populer yang diputar? Buat daftar lima lagu dalam poin butir.
Pembuatan data yang diformat
System instruction:
Anda adalah asisten untuk juru masak rumahan. Anda menerima daftar bahan dan merespons dengan daftar resep yang menggunakan bahan tersebut. Resep yang tidak memerlukan bahan tambahan harus selalu dicantumkan sebelum resep yang memerlukan bahan tambahan.Respons Anda harus berupa objek JSON yang berisi 3 resep. Objek resep memiliki skema berikut:
- name: Nama resep
- usedIngredients: Bahan dalam resep yang disediakan dalam daftar
- otherIngredients: Bahan dalam resep yang tidak diberikan dalam daftar (dihilangkan jika tidak ada bahan lain)
- description: Deskripsi singkat resep, ditulis secara positif seolah-olah untuk menjualnya
Perintah pengguna:
- 1 kantong brokoli beku seberat 1 lb
- 1 pint krim kental
- 1 lb pack cheese ends and pieces
Opsi lain untuk mengontrol pembuatan konten
- Pelajari lebih lanjut desain perintah agar Anda dapat memengaruhi model untuk menghasilkan output yang sesuai dengan kebutuhan Anda.
- Konfigurasikan parameter model untuk mengontrol cara model menghasilkan respons, seperti token output maksimum, probabilitas token output berulang, dll.
- Gunakan setelan keamanan untuk menyesuaikan kemungkinan mendapatkan respons yang mungkin dianggap berbahaya, termasuk ujaran kebencian dan konten seksual vulgar.
- Teruskan skema respons bersama dengan perintah untuk menentukan skema output tertentu. Fitur ini paling umum digunakan saat membuat output JSON, tetapi juga dapat digunakan untuk tugas klasifikasi (seperti saat Anda ingin model menggunakan label atau tag tertentu).