במאמר הזה מוסבר איך משתמשים בהוראות מערכת. כדי לקבל מידע על הוראות למערכת ועל שיטות מומלצות לשימוש בהן, אפשר לעיין במאמר מבוא להוראות למערכת.
הוראות מערכת הן קבוצת הוראות שהמודל מעבד לפני שהוא מעבד הנחיות. מומלץ להשתמש בהוראות מערכת כדי להגדיר למודל איך רוצים שהוא יתנהג ויגיב להנחיות. לדוגמה, אפשר לכלול דברים כמו התפקיד או האישיות, נתוני הקשר והוראות עיצוב:
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.
כשמגדירים הוראה למערכת, היא חלה על כל הבקשה. הוא פועל בכמה תורות של משתמשים ומודלים כשהוא נכלל בהנחיה. ההוראות למערכת נפרדות מתוכן ההנחיה, אבל הן עדיין חלק מההנחיות הכוללות שלכם ולכן הן כפופות למדיניות הרגילה בנושא שימוש בנתונים.
תרחישים לדוגמה
אפשר להשתמש בהוראות מערכת בדרכים רבות, כולל:
- הגדרת פרסונה או תפקיד (לדוגמה, לצ'אטבוט)
- הגדרת פורמט הפלט (Markdown, YAML וכו')
- הגדרת סגנון וטון הפלט (לדוגמה, אריכות, רשמיות ורמת קריאה)
- הגדרת יעדים או כללים למשימה (לדוגמה, החזרת קטע קוד ללא הסברים נוספים)
- לספק הקשר נוסף להנחיה (לדוגמה, תאריך סיום הידע)
מציינים באיזו שפה המודל צריך להשיב (לפעמים המודלים יכולים להשיב בשפה המקומית, גם אם ההנחיה כתובה בשפה אחרת). כשמשתמשים בשפה שאינה אנגלית בהנחיות, מומלץ להוסיף את ההנחיות הבאות להוראות המערכת:
All questions should be answered comprehensively with details, unless the user requests a concise response specifically. Respond in the same language as the query.
דוגמאות קוד
בדוגמאות הקוד בכרטיסיות הבאות אפשר לראות איך להשתמש בהוראות מערכת באפליקציית AI גנרטיבי.
Python
התקנה
pip install --upgrade google-genai
מידע נוסף מופיע ב מאמרי העזרה בנושא SDK.
מגדירים משתני סביבה כדי להשתמש ב-Gen AI SDK עם Vertex AI:
# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values # with appropriate values for your project. export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT export GOOGLE_CLOUD_LOCATION=global export GOOGLE_GENAI_USE_VERTEXAI=True
Go
מידע נוסף מופיע ב מאמרי העזרה בנושא SDK.
מגדירים משתני סביבה כדי להשתמש ב-Gen AI SDK עם Vertex AI:
# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values # with appropriate values for your project. export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT export GOOGLE_CLOUD_LOCATION=global export GOOGLE_GENAI_USE_VERTEXAI=True
Node.js
התקנה
npm install @google/genai
מידע נוסף מופיע ב מאמרי העזרה בנושא SDK.
מגדירים משתני סביבה כדי להשתמש ב-Gen AI SDK עם Vertex AI:
# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values # with appropriate values for your project. export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT export GOOGLE_CLOUD_LOCATION=global export GOOGLE_GENAI_USE_VERTEXAI=True
Java
כך מתקינים או מעדכנים את Java.
מידע נוסף מופיע ב מאמרי העזרה בנושא SDK.
מגדירים משתני סביבה כדי להשתמש ב-Gen AI SDK עם Vertex AI:
# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values # with appropriate values for your project. export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT export GOOGLE_CLOUD_LOCATION=global export GOOGLE_GENAI_USE_VERTEXAI=True
REST
אחרי הגדרת הסביבה, אפשר להשתמש ב-REST כדי לבדוק הנחיית טקסט. בדוגמה הבאה נשלחת בקשה לנקודת הקצה של מודל בעל התוכן הדיגיטלי.
לפני שמשתמשים בנתוני הבקשה, צריך להחליף את הנתונים הבאים:
-
GENERATE_RESPONSE_METHOD: סוג התגובה שרוצים שהמודל ייצור. בוחרים שיטה שבה המודל יחזיר את התשובה הרצויה:-
streamGenerateContent: התשובה מוזרמת בזמן שהיא נוצרת כדי לצמצם את תפיסת זמן האחזור בקרב קהל אנושי. -
generateContent: התשובה מוחזרת אחרי שהיא נוצרת במלואה.
-
-
LOCATION: האזור שבו הבקשה תעובד. האפשרויות הזמינות כוללות את האפשרויות הבאות:כאן אפשר ללחוץ כדי להרחיב רשימה חלקית של אזורים זמינים
us-central1us-west4northamerica-northeast1us-east4us-west1asia-northeast3asia-southeast1asia-northeast1
-
PROJECT_ID: מזהה הפרויקט. -
MODEL_ID: מזהה המודל של המודל המולטי-מודאלי שבו רוצים להשתמש. ROLE: התפקיד בשיחה שמשויך לתוכן. חובה לציין תפקיד גם בתרחישי שימוש של תור אחד. הערכים הקבילים כוללים את האפשרויות הבאות:-
USER: מציין תוכן שנשלח על ידכם. -
MODEL: מציין את התשובה של המודל.
-
הוראות הטקסט שייכללו בהנחיה. לדוגמה,TEXT
User input: I like bagels.SAFETY_CATEGORY: קטגוריית הבטיחות שרוצים להגדיר לה ערך סף. הערכים הקבילים כוללים את האפשרויות הבאות:הרחבת קטגוריות הבטיחות
HARM_CATEGORY_SEXUALLY_EXPLICITHARM_CATEGORY_HATE_SPEECHHARM_CATEGORY_HARASSMENTHARM_CATEGORY_DANGEROUS_CONTENT
-
THRESHOLD: ערך הסף לחסימת תשובות שעשויות להשתייך לקטגוריית הבטיחות שצוינה על סמך הסתברות. הערכים הקבילים כוללים את האפשרויות הבאות: לוחצים כדי להרחיב את ספי החסימה
BLOCK_NONEBLOCK_ONLY_HIGHBLOCK_MEDIUM_AND_ABOVE(ברירת מחדל)BLOCK_LOW_AND_ABOVE
BLOCK_LOW_AND_ABOVEחוסם הכי הרבה, ו-BLOCK_ONLY_HIGHחוסם הכי מעט. -
(אופציונלי) לא זמין בכל הדגמים. הוראות למודל כדי לשפר את הביצועים. ב-JSON אין תמיכה במעברי שורה. החלפת כל מעברי השורה בשדה הזה ב-SYSTEM_INSTRUCTION
\n. לדוגמה,You are a helpful language translator.\nYour mission is to translate text in English to French. TEMPERATURE: רמת האקראיות משמשת לדגימה במהלך יצירת התשובה, שמתרחשת כשמחילים אתtopPו-topK. הטמפרטורה שולטת במידת האקראיות בבחירת האסימון. טמפרטורות נמוכות טובות להנחיות שדורשות תשובה פחות פתוחה או יצירתית, ואילו טמפרטורות גבוהות יכולות להוביל לתוצאות יותר מגוונות או יצירתיות. רמת אקראיות של0פירושה שהאסימונים עם ההסתברות הכי גבוהה תמיד נבחרים. במקרה כזה, התשובות להנחיה נתונה הן ברובן דטרמיניסטיות, אבל עדיין יכולות להיות וריאציות קלות.אם המודל מחזיר תשובה כללית מדי, קצרה מדי או תשובת ברירת מחדל, נסו להגדיל את רמת האקראיות. אם המודל נכנס ליצירה אינסופית, יכול להיות שהעלאת רמת האקראיות ל-
0.1לפחות תוביל לתוצאות טובות יותר.1.0הוא ערך הטמפרטורה המומלץ להתחלה.-
TOP_P: הפרמטר Top-P משנה את האופן שבו המודל בוחר אסימונים לפלט. האסימונים נבחרים מההסתברות הגבוהה ביותר להסתברות הנמוכה ביותר עד שסכום ההסתברויות שלהם שווה לערך של top-P. לדוגמה, אם לאסימונים A, B ו-C יש הסתברות של 0.3, 0.2 ו-0.1, והערך של top-P הוא0.5, אז המודל יבחר באסימון A או באסימון B כאסימון הבא באמצעות רמת אקראיות, ויפסול את C כמועמד.מציינים ערך נמוך יותר כדי לקבל תשובות פחות אקראיות, וערך גבוה יותר כדי לקבל תשובות יותר אקראיות.
-
TOP_K: ההגדרה Top-K משנה את האופן שבו המודל בוחר אסימונים לפלט. ערך של Top-K של1אומר שהאסימון הבא שנבחר הוא האסימון הסביר ביותר מבין כל האסימונים באוצר המילים של המודל (נקרא גם פענוח חמדני), בעוד שערך של Top-K של3אומר שהאסימון הבא נבחר מבין שלושת האסימונים הסבירים ביותר באמצעות רמת אקראיות.בכל שלב של בחירת אסימון, המערכת דוגמת את האסימונים המובילים מתוך K האסימונים עם ההסתברות הכי גבוהה. לאחר מכן, הטוקנים מסוננים עוד יותר על סמך Top-P, והטוקן הסופי נבחר באמצעות דגימת רמת אקראיות.
מציינים ערך נמוך יותר כדי לקבל תשובות פחות אקראיות, וערך גבוה יותר כדי לקבל תשובות יותר אקראיות.
-
MAX_OUTPUT_TOKENS: המספר המקסימלי של טוקנים שאפשר ליצור בתגובה. טוקן הוא בערך ארבעה תווים. 100 טוקנים תואמים בערך ל-60 עד 80 מילים.כדי לקבל תשובות קצרות יותר, מציינים ערך נמוך יותר, וכדי לקבל תשובות ארוכות יותר, מציינים ערך גבוה יותר.
STOP_SEQUENCES: רשימה של מחרוזות שאם אחת מהן מופיעה בתשובה, המודל מפסיק ליצור טקסט. אם מחרוזת מופיעה כמה פעמים בתשובה, התשובה תיחתך במקום שבו היא מופיעה בפעם הראשונה. המחרוזות הן תלויות אותיות רישיות (case-sensitive).
לדוגמה, אם זו התגובה שמתקבלת כשלא מציינים אתstopSequences:
public static string reverse(string myString)
אז התגובה שמתקבלת כשמגדירים אתstopSequencesלערך["Str", "reverse"]היא:
public static string
כדי להשבית את רצפי העצירה, מציינים מערך ריק ([]).
כדי לשלוח את הבקשה אתם צריכים לבחור אחת מהאפשרויות הבאות:
curl
שומרים את גוף הבקשה בקובץ בשם request.json.
כדי ליצור או להחליף את הקובץ הזה בספרייה הנוכחית, מריצים את הפקודה הבאה בטרמינל:
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לאחר מכן מבצעים את הפקודה הבאה כדי לשלוח את בקשת ה-REST:
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
שומרים את גוף הבקשה בקובץ בשם request.json.
כדי ליצור או להחליף את הקובץ הזה בספרייה הנוכחית, מריצים את הפקודה הבאה בטרמינל:
@'
{
"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לאחר מכן מבצעים את הפקודה הבאה כדי לשלוח את בקשת ה-REST:
$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
אתם אמורים לקבל תגובת JSON שדומה לזו:
שימו לב לפרטים הבאים בכתובת ה-URL של הדוגמה הזו:- משתמשים בשיטה
generateContentכדי לבקש שהתשובה תוחזר אחרי שהיא נוצרה במלואה. כדי לצמצם את תפיסת זמן האחזור בקרב קהל אנושי, צריך להזרים את התשובה בזמן שהיא נוצרת באמצעות השיטהstreamGenerateContent. - מזהה המודל הרב-אופני מופיע בסוף כתובת ה-URL לפני השיטה
(לדוגמה,
gemini-2.0-flash). יכול להיות שהדוגמה הזו תתמוך גם במודלים אחרים. - כשמשתמשים בנקודת קצה אזורית ל-API (לדוגמה,
us-central1), האזור מכתובת ה-URL של נקודת הקצה קובע איפה הבקשה תעובד. המערכת מתעלמת מכל מיקום שיוצר התנגשות בנתיב המשאב.
דוגמאות להנחיות
הדוגמאות הבאות הן הנחיות מערכת שמגדירות את ההתנהגות הצפויה של המודל.
יצירת קוד
| יצירת קוד |
|---|
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.
|
יצירת נתונים בפורמט מסוים
| יצירת נתונים מפורמטים |
|---|
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
|
צ'אט בוט למוזיקה
| צ'אטבוט מוזיקה |
|---|
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.
|
ניתוחים פיננסיים
| ניתוח פיננסי |
|---|
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.
|
ניתוח סנטימנטים בשוק
| ניתוח הסנטימנט בשוק |
|---|
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.
|
המאמרים הבאים
- דוגמאות נוספות להנחיות מופיעות בגלריית ההנחיות.