במדריך מפורט לגבי ספירת אסימונים באמצעות Gemini API, כולל האופן שבו נספרים תמונות, אודיו וסרטונים, אפשר לעיין במדריך לספירת אסימונים ובמתכון של ספר המתכונים שנלווה אליו.
שיטה: models.countTokens
- נקודת קצה (endpoint)
- פרמטרים של נתיב
- גוף הבקשה
- גוף התשובה
- היקפי ההרשאות
- דוגמה לבקשה
- GenerateContentRequest
מריצה את ההמרה לאסימונים של מודל בקלט Content
ומחזירה את מספר האסימונים. מידע נוסף על אסימונים זמין במדריך בנושא אסימונים.
נקודת קצה
לשלוח
https://generativelanguage.googleapis.com/v1beta/{model=models/*}:countTokens
פרמטרים של נתיב
model
string
חובה. שם המשאב של המודל. המזהה הזה משמש את המודל.
השם הזה צריך להיות תואם לשם הדגם שהוחזר על ידי השיטה models.list
.
פורמט: models/{model}
הוא מופיע בפורמט models/{model}
.
גוף הבקשה
גוף הבקשה מכיל נתונים במבנה הבא:
contents[]
object (Content
)
זה שינוי אופציונלי. הקלט שניתן למודל כהנחיה. המערכת מתעלמת מהשדה הזה כאשר השדה generateContentRequest
מוגדר.
generateContentRequest
object (GenerateContentRequest
)
זה שינוי אופציונלי. הקלט הכולל שניתן ל-Model
. זה כולל את ההנחיה ומידע נוסף על היגוי של המודל, כמו הוראות מערכת או הצהרות לגבי פונקציות של הפעלת פונקציות. Model
/Content
ו-generateContentRequest
הם בלעדיים. אפשר לשלוח Model
+ Content
או generateContentRequest
, אבל אף פעם לא את שניהם.
דוגמה לבקשה
טקסט
Python
Node.js
Go
קונכייה
Kotlin
Swift
Dart
Java
צ'אט
Python
Node.js
Go
קונכייה
Kotlin
Swift
Dart
Java
מדיה מוטבעת
Python
Node.js
Go
קונכייה
Kotlin
Swift
Dart
Java
וידאו
Python
Node.js
Go
קונכייה
Python
מטמון
Python
Node.js
Go
הוראה למערכת
Python
Node.js
Go
Kotlin
Swift
Dart
Java
כלים
Python
Node.js
Kotlin
Swift
Dart
Java
גוף התשובה
תשובה של models.countTokens
.
היא מחזירה את הערך tokenCount
של המודל במסגרת prompt
.
אם הפעולה בוצעה ללא שגיאות, גוף התגובה יכיל נתונים במבנה הבא:
totalTokens
integer
מספר האסימונים שאליהם Model
מוסיף את האסימון prompt
. תמיד לא שלילי.
ייצוג JSON |
---|
{ "totalTokens": integer } |
GenerateContentRequest
בקשה ליצירת השלמה מהמודל.
model
string
חובה. השם של Model
שישמש ליצירת ההשלמה.
פורמט: name=models/{model}
contents[]
object (Content
)
חובה. תוכן השיחה הנוכחית עם המודל.
בשאילתות עם סיבוב אחד, מדובר באירוע יחיד. בשאילתות מרובות תורות כמו צ'אט, זהו שדה חוזר שמכיל את היסטוריית השיחות ואת הבקשה האחרונה.
tools[]
object (Tool
)
זה שינוי אופציונלי. רשימה של Tools
ש-Model
עשוי להשתמש בהם כדי ליצור את התשובה הבאה.
Tool
הוא קטע קוד שמאפשר למערכת לקיים אינטראקציה עם מערכות חיצוניות כדי לבצע פעולה או קבוצת פעולות, שלא במסגרת הידע וההיקף של Model
. סוגי Tool
הנתמכים הם Function
ו-codeExecution
. מידע נוסף זמין במדריכים קריאות לפונקציה והפעלת קוד.
toolConfig
object (ToolConfig
)
זה שינוי אופציונלי. הגדרת הכלי לכל Tool
שצוין בבקשה. דוגמה לשימוש זמינה במדריך להפעלת פונקציות.
safetySettings[]
object (SafetySetting
)
זה שינוי אופציונלי. רשימה של מופעים ייחודיים של SafetySetting
לחסימת תוכן לא בטוח.
המדיניות הזו תיאכף בGenerateContentRequest.contents
ובGenerateContentResponse.candidates
. לכל סוג של SafetyCategory
יכולה להיות הגדרה אחת לכל היותר. ה-API יחסום תוכן ותשובות שלא יעמדו בערכי הסף שהוגדרו על ידי ההגדרות האלה. הרשימה הזו מבטלת את הגדרות ברירת המחדל לכל SafetyCategory
שצוינו בהגדרות הבטיחות. אם לא צוין SafetySetting
עבור SafetyCategory
מסוים ברשימה, ה-API ישתמש בהגדרת ברירת המחדל של בטיחות לקטגוריה הזו. קיימת תמיכה בקטגוריות פגיעה HARM_CATEGORY_HATE_SPEECH, HARM_CATEGORY_SEXUALLY_EXPLICIT, HARM_CATEGORY_DANGEROUS_CONTENT ו-HARM_CATEGORY_HARASSMENT. כדאי לעיין במדריך לקבלת מידע מפורט על הגדרות הבטיחות הזמינות. כדאי גם לעיין בהנחיות הבטיחות כדי ללמוד איך לשלב שיקולי בטיחות באפליקציות ה-AI.
systemInstruction
object (Content
)
זה שינוי אופציונלי. הוראות המערכת של המפתחים. כרגע אפשר להשתמש רק בטקסט.
generationConfig
object (GenerationConfig
)
זה שינוי אופציונלי. אפשרויות תצורה ליצירת מודל ולפלט שלו.
cachedContent
string
זה שינוי אופציונלי. שם התוכן שנשמר במטמון לשימוש כהקשר להצגת החיזוי. פורמט: cachedContents/{cachedContent}
ייצוג JSON |
---|
{ "model": string, "contents": [ { object ( |