Petunjuk sistem ibarat pembukaan yang Anda tambahkan sebelum LLM mengetahui terpapar instruksi lebih lanjut dari pengguna. Hal ini memungkinkan pengguna mengarahkan perilaku model berdasarkan kebutuhan dan kasus penggunaannya yang spesifik. Saat Anda menetapkan instruksi sistem, Anda memberikan konteks tambahan kepada model untuk memahami tugas, memberikan tanggapan yang lebih disesuaikan, dan mematuhi pedoman spesifik interaksi pengguna secara penuh dengan model. Bagi developer, perilaku tingkat produk dapat ditentukan dalam petunjuk sistem, terpisah dari prompt yang diberikan oleh pengguna. Misalnya, Anda dapat menyertakan hal-hal seperti peran atau persona, informasi, dan petunjuk pemformatan:
You are a friendly and helpful assistant.
Ensure your answers are complete, unless the user requests a more concise approach.
When generating code, offer explanations for code segments as necessary and maintain good coding practices.
When presented with inquiries seeking information, provide answers that reflect a deep understanding of the field, guaranteeing their correctness.
For any non-english queries, respond in the same language as the prompt unless otherwise specified by the user.
For prompts involving reasoning, provide a clear explanation of each step in the reasoning process before presenting the final answer.
Model Gemini berikut mendukung petunjuk sistem:
gemini-1.5-flash-001
gemini-1.5-pro-001
gemini-1.0-pro-002
Jika Anda menggunakan model yang berbeda, lihat Menetapkan peran sebagai gantinya.
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, formalitas, dan target tingkat bacaan)
- Menentukan sasaran atau aturan untuk tugas (misalnya, menampilkan cuplikan kode tanpa penjelasan lebih lanjut)
- Menyediakan konteks tambahan untuk perintah (misalnya, batas pengetahuan)
Jika ditetapkan, petunjuk sistem akan berlaku untuk seluruh permintaan. Bisa di beberapa pengguna dan model secara bergantian saat disertakan dalam perintah. Meskipun sistem instruksi terpisah dari konten prompt, mereka masih menjadi bagian Anda seluruh perintah Anda, dan oleh karena itu, tunduk pada kebijakan penggunaan data standar.
Contoh kode
Contoh kode di tab berikut menunjukkan cara menggunakan sistem petunjuk dalam aplikasi AI generatif Anda.
Python
Untuk mempelajari cara menginstal atau mengupdate Vertex AI SDK untuk Python, lihat Menginstal Vertex AI SDK untuk Python. Untuk informasi selengkapnya, lihat Vertex AI SDK untuk Python dokumentasi referensi API.
Respons streaming dan non-streaming
Anda dapat memilih apakah model akan menghasilkan respons streaming atau non-streaming. Untuk respons bertahap, Anda menerima setiap respons segera setelah token output-nya dibuat. Untuk respons non-streaming, Anda menerima semua respons setelah semua token output dibuat.
Untuk respons streaming, gunakan parameter stream
di
generate_content
.
response = model.generate_content(contents=[...], stream = True)
Untuk respons non-streaming, hapus parameter, atau setel parameter ke
False
.
Kode contoh
Node.js
Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Node.js di halaman AI Generatif panduan memulai menggunakan Node.js SDK. Untuk informasi selengkapnya, lihat referensi Node.js SDK untuk Gemini dokumentasi tambahan.
Untuk mengautentikasi ke Vertex AI, siapkan Application Default Kredensial. Untuk informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.
Respons streaming dan non-streaming
Anda dapat memilih apakah model akan menghasilkan respons streaming atau non-streaming. Untuk respons bertahap, Anda menerima setiap respons segera setelah token output-nya dibuat. Untuk respons non-streaming, Anda menerima semua respons setelah semua token output dibuat.
Untuk respons streaming, gunakan
generateContentStream
.
const streamingResp = await generativeModel.generateContentStream(request);
Untuk respons non-streaming, gunakan metode
generateContent
.
const streamingResp = await generativeModel.generateContent(request);
Kode contoh
Java
Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Java di Vertex AI panduan memulai. Untuk informasi lebih lanjut, lihat Vertex AI Dokumentasi referensi Java SDK untuk Gemini.
Untuk mengautentikasi ke Vertex AI, siapkan Application Default Kredensial. Untuk informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.
Respons streaming dan non-streaming
Anda dapat memilih apakah model akan menghasilkan respons streaming atau non-streaming. Untuk respons bertahap, Anda menerima setiap respons segera setelah token output-nya dibuat. Untuk respons non-streaming, Anda menerima semua respons setelah semua token output dibuat.
Untuk respons streaming, gunakan metode
generateContentStream
.
public ResponseStream<GenerateContentResponse> generateContentStream(Content content)
Untuk respons non-streaming, gunakan metode
generateContent
.
public GenerateContentResponse generateContent(Content content)
Kode contoh
Go
Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Go di Vertex AI panduan memulai. Untuk informasi lebih lanjut, lihat Vertex AI Go SDK untuk dokumentasi referensi Gemini.
Untuk melakukan autentikasi ke Vertex AI, siapkan Kredensial Default Aplikasi. Untuk informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.
Respons streaming dan non-streaming
Anda dapat memilih apakah model akan menghasilkan respons streaming atau non-streaming. Untuk respons bertahap, Anda menerima setiap respons segera setelah token output-nya dibuat. Untuk respons non-streaming, Anda menerima semua respons setelah semua token output dibuat.
Untuk respons streaming, gunakan
GenerateContentStream
.
iter := model.GenerateContentStream(ctx, genai.Text("Tell me a story about a lumberjack and his giant ox. Keep it very short."))
Untuk respons non-streaming, gunakan metode GenerateContent
.
resp, err := model.GenerateContent(ctx, genai.Text("What is the average size of a swallow?"))
Kode contoh
C#
Sebelum mencoba contoh ini, ikuti petunjuk penyiapan C# di Vertex AI panduan memulai. Untuk informasi lebih lanjut, lihat Vertex AI Dokumentasi referensi C#.
Untuk mengautentikasi ke Vertex AI, siapkan Application Default Kredensial. Untuk informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.
Respons streaming dan non-streaming
Anda dapat memilih apakah model akan menghasilkan respons streaming atau non-streaming. Untuk respons bertahap, Anda menerima setiap respons segera setelah token output-nya dibuat. Untuk respons non-streaming, Anda menerima semua respons setelah semua token output dibuat.
Untuk respons streaming, gunakan metode
StreamGenerateContent
.
public virtual PredictionServiceClient.StreamGenerateContentStream StreamGenerateContent(GenerateContentRequest request)
Untuk respons non-streaming, gunakan metode
GenerateContentAsync
.
public virtual Task<GenerateContentResponse> GenerateContentAsync(GenerateContentRequest request)
Untuk informasi selengkapnya tentang cara server dapat menstreaming respons, lihat RPC Streaming.
Kode contoh
REST
Setelah Anda menyiapkan lingkungan Anda, Anda dapat menggunakan REST untuk menguji prompt teks. Contoh berikut mengirim permintaan ke penayang endpoint model Google Cloud.
Sebelum menggunakan salah satu data permintaan, lakukan penggantian berikut:
GENERATE_RESPONSE_METHOD
: Jenis respons yang Anda inginkan untuk dihasilkan model. Pilih metode yang menghasilkan cara menampilkan respons model:streamGenerateContent
: Respons di-streaming saat dibuat untuk mengurangi persepsi latensi kepada audiens manusia.generateContent
: Respons ditampilkan setelah dibuat sepenuhnya.
LOCATION
: Region untuk memproses permintaan. Tersedia opsi ini meliputi:Klik untuk meluaskan daftar sebagian wilayah yang tersedia
us-central1
us-west4
northamerica-northeast1
us-east4
us-west1
asia-northeast3
asia-southeast1
asia-northeast1
PROJECT_ID
: Project ID Anda.MODEL_ID
: ID model untuk model multimodal yang ingin Anda gunakan. Beberapa opsinya adalah sebagai berikut:gemini-1.0-pro-002
gemini-1.0-pro-vision-001
gemini-1.5-pro-001
gemini-1.5-flash
ROLE
: Peran dalam percakapan yang terkait dengan konten. Menentukan peran diperlukan bahkan dalam kasus penggunaan singleturn. Nilai yang dapat diterima mencakup:USER
: Menentukan konten yang Anda kirimkan.MODEL
: Menentukan respons model.
Petunjuk teks yang harus disertakan dalam perintah. Contoh,TEXT
User input: I like bagels
.SAFETY_CATEGORY
: Kategori keamanan yang akan dikonfigurasi batasnya. Nilai yang dapat diterima mencakup:Klik untuk meluaskan kategori keamanan
HARM_CATEGORY_SEXUALLY_EXPLICIT
HARM_CATEGORY_HATE_SPEECH
HARM_CATEGORY_HARASSMENT
HARM_CATEGORY_DANGEROUS_CONTENT
THRESHOLD
: Ambang batas untuk memblokir respons yang dapat termasuk dalam kategori keamanan yang ditentukan berdasarkan probabilitas tertinggi. Nilai yang dapat diterima mencakup:Klik untuk memperluas nilai minimum pemblokiran
BLOCK_NONE
BLOCK_ONLY_HIGH
BLOCK_MEDIUM_AND_ABOVE
(default)BLOCK_LOW_AND_ABOVE
BLOCK_LOW_AND_ABOVE
memblokir paling banyak sementaraBLOCK_ONLY_HIGH
blok yang paling kecil. (Opsional) Hanya tersedia untuk model tertentu. Petunjuk bagi model untuk mengarahkannya ke performa yang lebih baik. JSON tidak mendukung jeda baris. Ganti semua baris baru di kolom ini denganSYSTEM_INSTRUCTION
\n
. Misalnya,You are a helpful language translator.\nYour mission is to translate text in English to French.
TEMPERATURE
: Suhu digunakan untuk pengambilan sampel selama pembuatan respons, yang terjadi saattopP
dantopK
diterapkan. Suhu mengontrol tingkat keacakan dalam pemilihan token. Suhu yang lebih rendah cocok untuk perintah yang memerlukan respons yang kurang terbuka atau kreatif, sedangkan suhu yang lebih tinggi dapat memberikan hasil yang lebih beragam atau kreatif. Suhu0
berarti token probabilitas tertinggi selalu dipilih. Dalam hal ini, respons untuk permintaan tertentu sebagian besar deterministik, tetapi sedikit variasi masih dapat dilakukan.Jika model menampilkan respons yang terlalu umum, terlalu pendek, atau model memberikan fallback respons, coba tingkatkan suhunya.
TOP_P
: Top-P mengubah cara model memilih token untuk output. Token dipilih dari yang paling mungkin (lihat top-K) hingga yang paling tidak mungkin sampai jumlah probabilitasnya sama dengan nilai top-P. Misalnya, jika token A, B, dan C memiliki probabilitas 0,3, 0,2, dan 0,1 dengan nilai top-P adalah0.5
, model akan memilih A atau B sebagai token berikutnya dengan menggunakan suhu dan mengecualikan C sebagai kandidat.Tentukan nilai yang lebih rendah untuk respons acak yang lebih sedikit dan nilai yang lebih tinggi untuk respons acak yang lebih banyak.
TOP_K
: Top-K mengubah cara model memilih token untuk output. Top-K dari1
berarti token yang dipilih berikutnya adalah yang paling mungkin di antara semua token dalam kosakata model (juga disebut decoding greedy), sedangkan nilai top-K dari3
berarti token berikutnya dipilih di antara tiga token yang paling mungkin menggunakan suhu.Untuk setiap langkah pemilihan token, token top-K dengan probabilitas tertinggi akan diambil sampelnya. Kemudian token akan difilter lebih lanjut berdasarkan top-P dengan token akhir yang dipilih menggunakan pengambilan sampel suhu.
Tentukan nilai yang lebih rendah untuk respons acak yang lebih sedikit dan nilai yang lebih tinggi untuk respons acak yang lebih banyak.
MAX_OUTPUT_TOKENS
: Jumlah token maksimum yang dapat dibuat dalam respons. Token terdiri dari sekitar empat karakter. 100 token setara dengan sekitar 60-80 kata.Tentukan nilai yang lebih rendah untuk respons yang lebih singkat dan nilai yang lebih tinggi untuk respons yang berpotensi lebih lama yang dihasilkan.
STOP_SEQUENCES
: Menentukan daftar string yang memberi tahu model untuk berhenti menghasilkan teks jika ada string ditemui dalam respons. Jika string muncul beberapa kali dalam respons, respons akan dipotong di tempatnya pertama kali ditemukan. String peka huruf besar/kecil.
Misalnya, jika berikut ini adalah respons yang ditampilkan saatstopSequences
tidak ditentukan:public static string reverse(string myString)
Kemudian, respons yang ditampilkan denganstopSequences
yang ditetapkan ke["Str", "reverse"]
adalah:
public static string
Tentukan array kosong ([]
) untuk menonaktifkan urutan perhentian.
Untuk mengirim permintaan Anda, pilih salah satu opsi berikut:
curl
Simpan isi permintaan dalam file bernama request.json
.
Jalankan perintah berikut di terminal untuk membuat atau menimpa file ini di direktori saat ini:
cat > request.json << 'EOF' { "contents": { "role": "ROLE", "parts": { "text": "TEXT" } }, "system_instruction": { "parts": [ { "text": "SYSTEM_INSTRUCTION" } ] }, "safety_settings": { "category": "SAFETY_CATEGORY", "threshold": "THRESHOLD" }, "generation_config": { "temperature": TEMPERATURE, "topP": TOP_P, "topK": TOP_K, "candidateCount": 1, "maxOutputTokens": MAX_OUTPUT_TOKENS, "stopSequences": STOP_SEQUENCES } } EOF
Kemudian, jalankan perintah berikut untuk mengirim permintaan REST Anda:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/MODEL_ID:GENERATE_RESPONSE_METHOD"
PowerShell
Simpan isi permintaan dalam file bernama request.json
.
Jalankan perintah berikut di terminal untuk membuat atau menimpa file ini di direktori saat ini:
@' { "contents": { "role": "ROLE", "parts": { "text": "TEXT" } }, "system_instruction": { "parts": [ { "text": "SYSTEM_INSTRUCTION" } ] }, "safety_settings": { "category": "SAFETY_CATEGORY", "threshold": "THRESHOLD" }, "generation_config": { "temperature": TEMPERATURE, "topP": TOP_P, "topK": TOP_K, "candidateCount": 1, "maxOutputTokens": MAX_OUTPUT_TOKENS, "stopSequences": STOP_SEQUENCES } } '@ | Out-File -FilePath request.json -Encoding utf8
Kemudian, jalankan perintah berikut untuk mengirim permintaan REST Anda:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/MODEL_ID:GENERATE_RESPONSE_METHOD" | Select-Object -Expand Content
Anda akan menerima respons JSON yang mirip dengan berikut ini.
Perhatikan hal berikut dalam URL untuk contoh ini:- Gunakan
generateContent
untuk meminta agar respons ditampilkan setelah dibuat sepenuhnya. Untuk mengurangi persepsi latensi kepada audiens manusia, streaming respons secara langsung yang dibuat dengan menggunakanstreamGenerateContent
. - ID model multimodal terletak di akhir URL sebelum metode
(misalnya,
gemini-1.5-flash
ataugemini-1.0-pro-vision
). Contoh ini dapat mendukung seperti model AI generatif.
Contoh perintah
Berikut adalah contoh dasar dari setelan instruksi sistem menggunakan Python SDK untuk Gemini API:
model=genai.GenerativeModel(
model_name="gemini-1.5-pro-001",
system_instruction="You are a cat. Your name is Neko.")
Berikut adalah contoh perintah sistem yang menentukan perilaku yang diharapkan model.
Pembuatan kode
Pembuatan kode |
---|
You are a coding expert that specializes in rendering code for front-end 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. Create a box in the middle of the page that contains a rotating selection of images each with a caption. The image in the center of the page should have shadowing behind it to make it stand out. It should also link to another page of the site. Leave the URL blank so that I can fill it in. |
Pembuatan data terformat
Pembuatan data terformat |
---|
You are an assistant for home cooks. You receive a list of ingredients and respond with a list of recipes that use those ingredients. Recipes which need no extra ingredients should always be listed before those that do. Your response must be a JSON object containing 3 recipes. A recipe object has the following schema: * name: The name of the recipe * usedIngredients: Ingredients in the recipe that were provided in the list * otherIngredients: Ingredients in the recipe that were not provided in the list (omitted if there are no other ingredients) * description: A brief description of the recipe, written positively as if to sell it * 1 lb bag frozen broccoli * 1 pint heavy cream * 1 lb pack cheese ends and pieces |
Chatbot musik
Chatbot musik |
---|
You will respond as a music historian, demonstrating comprehensive knowledge across diverse musical genres and providing relevant examples. Your tone will be upbeat and enthusiastic, spreading the joy of music. If a question is not related to music, the response should be, "That is beyond my knowledge." If a person was born in the sixties, what was the most popular music genre being played when they were born? List five songs by bullet point. |
Analisis keuangan
Analisis keuangan |
---|
As a financial analysis expert, your role is to interpret complex financial data, offer personalized advice, and evaluate investments using statistical methods to gain insights across different financial areas. Accuracy is the top priority. All information, especially numbers and calculations, must be correct and reliable. Always double-check for errors before giving a response. The way you respond should change based on what the user needs. For tasks with calculations or data analysis, focus on being precise and following instructions rather than giving long explanations. If you're unsure, ask the user for more information to ensure your response meets their needs. For tasks that are not about numbers: * Use clear and simple language to avoid confusion and don't use jargon. * Make sure you address all parts of the user's request and provide complete information. * Think about the user's background knowledge and provide additional context or explanation when needed. Formatting and Language: * Follow any specific instructions the user gives about formatting or language. * Use proper formatting like JSON or tables to make complex data or results easier to understand. Please summarize the key insights of given numerical tables. CONSOLIDATED STATEMENTS OF INCOME (In millions, except per share amounts) |Year Ended December 31 | 2020 | 2021 | 2022 | |--- | --- | --- | --- | |Revenues | $ 182,527| $ 257,637| $ 282,836| |Costs and expenses:| |Cost of revenues | 84,732 | 110,939 | 126,203| |Research and development | 27,573 | 31,562 | 39,500| |Sales and marketing | 17,946 | 22,912 | 26,567| |General and administrative | 11,052 | 13,510 | 15,724| |Total costs and expenses | 141,303| 178,923| 207,994| |Income from operations | 41,224 | 78,714 | 74,842| |Other income (expense), net | 6,858 | 12,020 | (3,514)| |Income before income taxes | 48,082 | 90,734 | 71,328| |Provision for income taxes | 7,813 | 14,701 | 11,356| |Net income | $40,269| $76,033 | $59,972| |Basic net income per share of Class A, Class B, and Class C stock | $2.96| $5.69| $4.59| |Diluted net income per share of Class A, Class B, and Class C stock| $2.93| $5.61| $4.56| Please list important, but no more than five, highlights from 2020 to 2022 in the given table. Please write in a professional and business-neutral tone. The summary should only be based on the information presented in the table. |
Analisis sentimen pasar
Analisis sentimen pasar |
---|
You are a stock market analyst who analyzes market sentiment given a news snippet. Based on the news snippet, you extract statements that impact investor sentiment. Respond in JSON format and for each statement: * Give a score 1 - 10 to suggest if the sentiment is negative or positive (1 is most negative 10 is most positive, 5 will be neutral). * Reiterate the statement. * Give a one sentence explanation. Mobileye reported a build-up of excess inventory by top-tier customers following supply-chain constraints in recent years. Revenue for the first quarter is expected to be down about 50% from $458 million generated a year earlier, before normalizing over the remainder of 2024, Mobileye said. Mobileye forecast revenue for full-year 2024 at between $1.83 billion and $1.96 billion, down from the about $2.08 billion it now expects for 2023. |
Langkah selanjutnya
- Pelajari contoh perintah lainnya di Galeri perintah.