Gemini API का इस्तेमाल करके टोकन की गिनती करने के बारे में ज़्यादा जानकारी पाने के लिए, टोकन की गिनती करने से जुड़ी गाइड और कुकबुक की रेसिपी देखें. इसमें इमेज, ऑडियो, और वीडियो की गिनती करने के तरीके की जानकारी भी शामिल है.
तरीका: Model.countTokens
- एंडपॉइंट
- पाथ पैरामीटर
- अनुरोध का मुख्य हिस्सा
- जवाब का मुख्य हिस्सा
- अनुमति के दायरे
- अनुरोध का उदाहरण
- 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
शुरू करें
शेल
Kotlin
Swift
Dart
Java
चैट करें
Python
Node.js
शुरू करें
शेल
Kotlin
Swift
Dart
Java
इनलाइन मीडिया
Python
Node.js
शुरू करें
शेल
Kotlin
Swift
Dart
Java
वीडियो
Python
Node.js
शुरू करें
शेल
Python
कैश
Python
Node.js
शुरू करें
सिस्टम के लिए निर्देश
Python
Node.js
शुरू करें
Kotlin
Swift
Dart
Java
टूल
Python
Node.js
Kotlin
Swift
Dart
Java
जवाब का मुख्य भाग
models.countTokens
से मिला जवाब.
यह prompt
के लिए, मॉडल के tokenCount
दिखाता है.
अगर एपीआई सही से जुड़ जाता है, ताे जवाब के मुख्य भाग में नीचे दिए गए स्ट्रक्चर शामिल होता है.
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
s Function
और codeExecution
हैं. ज़्यादा जानने के लिए, फ़ंक्शन कॉलिंग और कोड लागू करने की सुविधा से जुड़ी गाइड देखें.
toolConfig
object (ToolConfig
)
ज़रूरी नहीं. अनुरोध में बताए गए किसी भी Tool
के लिए टूल कॉन्फ़िगरेशन. इस्तेमाल के उदाहरण के लिए, फ़ंक्शन कॉलिंग की गाइड देखें.
safetySettings[]
object (SafetySetting
)
ज़रूरी नहीं. असुरक्षित कॉन्टेंट को ब्लॉक करने वाले यूनीक SafetySetting
इंस्टेंस की सूची.
यह GenerateContentRequest.contents
और GenerateContentResponse.candidates
पर लागू किया जाएगा. हर SafetyCategory
टाइप के लिए एक से ज़्यादा सेटिंग नहीं होनी चाहिए. यह एपीआई ऐसे कॉन्टेंट और रिस्पॉन्स को ब्लॉक कर देगा जो इन सेटिंग के लिए तय थ्रेशोल्ड को पूरा नहीं कर पाते हैं. यह सूची, SafetySettings में दिए गए हर SafetyCategory
के लिए डिफ़ॉल्ट सेटिंग को बदल देती है. अगर सूची में दिए गए किसी SafetyCategory
के लिए कोई SafetySetting
नहीं है, तो एपीआई उस कैटगरी के लिए डिफ़ॉल्ट सुरक्षा सेटिंग का इस्तेमाल करेगा. नुकसान की कैटगरी HARM_CATEGORY_HATE_SPEECH, HARM_CATEGORY_SEXUALLY_EXPLICIT, HARM_CATEGORY_DANGEROUS_CONTENT, HARM_CATEGORY_HARASSMENT वाली कैटगरी. उपलब्ध सुरक्षा सेटिंग के बारे में ज़्यादा जानकारी के लिए, गाइड देखें. साथ ही, अपने एआई ऐप्लिकेशन में, सुरक्षा से जुड़ी ज़रूरी बातों का ध्यान रखने का तरीका जानने के लिए, सुरक्षा से जुड़े दिशा-निर्देश देखें.
systemInstruction
object (Content
)
ज़रूरी नहीं. डेवलपर ने सिस्टम से जुड़े निर्देश सेट किए हैं. फ़िलहाल, सिर्फ़ टेक्स्ट.
generationConfig
object (GenerationConfig
)
ज़रूरी नहीं. मॉडल जनरेशन और आउटपुट के लिए कॉन्फ़िगरेशन के विकल्प.
cachedContent
string
ज़रूरी नहीं. सुझाव देने के लिए, कॉन्टेक्स्ट के तौर पर इस्तेमाल करने के लिए कैश मेमोरी में सेव किए गए कॉन्टेंट का नाम. फ़ॉर्मैट: cachedContents/{cachedContent}
JSON के काेड में दिखाना |
---|
{ "model": string, "contents": [ { object ( |