Gemini API का इस्तेमाल शुरू करें: Python

Google के एआई पर देखें Google Colab में चलाएं GitHub पर सोर्स देखें

यह क्विकस्टार्ट, Gemini API के लिए Python SDK टूल इस्तेमाल करने के तरीके के बारे में बताता है. इससे आपको Google के Gemini के बड़े लैंग्वेज मॉडल का ऐक्सेस मिलता है. इस क्विकस्टार्ट में, आपको यह पता चलेगा कि कैसे:

  1. Gemini का इस्तेमाल करने के लिए, अपना डेवलपमेंट एनवायरमेंट और एपीआई ऐक्सेस सेट अप करें.
  2. टेक्स्ट इनपुट से टेक्स्ट वाले जवाब जनरेट करें.
  3. मल्टीमोडल इनपुट (टेक्स्ट और इमेज) की मदद से टेक्स्ट वाले जवाब जनरेट करें.
  4. बारी-बारी से बातचीत (चैट) करने के लिए, Gemini का इस्तेमाल करें.
  5. बड़े लैंग्वेज मॉडल के लिए एम्बेड करने की सुविधा का इस्तेमाल करें.

ज़रूरी शर्तें

इस क्विकस्टार्ट की सुविधा को Google Colab में चलाया जा सकता है. यह notebook सीधे ब्राउज़र में चलती है. इसके लिए, अतिरिक्त एनवायरमेंट कॉन्फ़िगरेशन की ज़रूरत नहीं होती.

इसके अलावा, इस क्विकस्टार्ट को स्थानीय तौर पर पूरा करने के लिए, पक्का करें कि आपका डेवलपमेंट एनवायरमेंट नीचे दी गई ज़रूरी शर्तों को पूरा करता हो:

  • Python 3.9 और इसके बाद के वर्शन
  • notebook चलाने के लिए jupyter का इंस्टॉलेशन.

सेटअप

Python SDK टूल इंस्टॉल करें

Gemini API के लिए Python SDK टूल, google-generativeai पैकेज में शामिल होता है. पीआईपी (पिक्चर में पिक्चर) का इस्तेमाल करके डिपेंडेंसी इंस्टॉल करें:

pip install -q -U google-generativeai

पैकेज इंपोर्ट करें

ज़रूरी पैकेज इंपोर्ट करें.

import pathlib
import textwrap

import google.generativeai as genai

from IPython.display import display
from IPython.display import Markdown


def to_markdown(text):
  text = text.replace('•', '  *')
  return Markdown(textwrap.indent(text, '> ', predicate=lambda _: True))
# Used to securely store your API key
from google.colab import userdata

एपीआई पासकोड सेटअप करें

Gemini API का इस्तेमाल करने से पहले, आपको एपीआई पासकोड हासिल करना होगा. अगर आपके पास पहले से कोई कुंजी नहीं है, तो Google AI Studio में सिर्फ़ एक क्लिक करके कुंजी बनाएं.

एपीआई पासकोड पाएं

Colab में, सीक्रेट मैनेजर में बाईं ओर मौजूद पैनल में " दिलचस्पी" में जाकर कुंजी जोड़ें. इसे GOOGLE_API_KEY नाम दें.

एपीआई पासकोड मिलने के बाद, उसे SDK टूल को पास करें. आप इसे दो तरीकों से कर सकते हैं:

  • कुंजी को GOOGLE_API_KEY के एनवायरमेंट वैरिएबल में डालें. SDK टूल इसे वहां से अपने-आप चुन लेगा.
  • कुंजी को genai.configure(api_key=...) पर पास करें
# Or use `os.getenv('GOOGLE_API_KEY')` to fetch an environment variable.
GOOGLE_API_KEY=userdata.get('GOOGLE_API_KEY')

genai.configure(api_key=GOOGLE_API_KEY)

मॉडल की सूची बनाएं

अब आप Gemini API को कॉल करने के लिए तैयार हैं. Gemini के उपलब्ध मॉडल देखने के लिए, list_models का इस्तेमाल करें:

  • gemini-pro: इसे सिर्फ़ टेक्स्ट वाले प्रॉम्प्ट के लिए ऑप्टिमाइज़ किया गया है.
  • gemini-pro-vision: इसे टेक्स्ट और इमेज प्रॉम्प्ट के लिए ऑप्टिमाइज़ किया गया है.
for m in genai.list_models():
  if 'generateContent' in m.supported_generation_methods:
    print(m.name)

genai पैकेज, मॉडल के PaLM फ़ैमिली के साथ भी काम करता है. हालांकि, सिर्फ़ Gemini मॉडल में generateContent तरीके की सामान्य और मल्टीमोडल सुविधाएं काम करती हैं.

टेक्स्ट इनपुट से टेक्स्ट जनरेट करें

सिर्फ़ टेक्स्ट वाले प्रॉम्प्ट के लिए, gemini-pro मॉडल का इस्तेमाल करें:

model = genai.GenerativeModel('gemini-pro')

generate_content वाला तरीका, कई तरह के इस्तेमाल के उदाहरणों को मैनेज कर सकता है. इनमें मल्टी-टर्न चैट और मल्टीमोडल इनपुट शामिल हैं. यह इस बात पर निर्भर करता है कि मॉडल किस तरह से काम करता है. उपलब्ध मॉडल, इनपुट के तौर पर सिर्फ़ टेक्स्ट और इमेज और आउटपुट के तौर पर टेक्स्ट का इस्तेमाल करते हैं.

सबसे आसान मामले में, GenerativeModel.generate_content तरीके में प्रॉम्प्ट स्ट्रिंग पास की जा सकती है:

%%time
response = model.generate_content("What is the meaning of life?")
CPU times: user 110 ms, sys: 12.3 ms, total: 123 ms
Wall time: 8.25 s

सामान्य मामलों में, आपको सिर्फ़ response.text ऐक्सेसर की ज़रूरत है. फ़ॉर्मैट किए गए मार्कडाउन टेक्स्ट को दिखाने के लिए, to_markdown फ़ंक्शन का इस्तेमाल करें:

to_markdown(response.text)

जीवन के उद्देश्य ने सदियों, संस्कृतियों, और महाद्वीपों पर लोगों को हैरान कर दिया है. ऐसी कोई प्रतिक्रिया नहीं मिली जिसे सभी लोग स्वीकार कर सकें, लेकिन बहुत से विचार सामने आए हैं. ये जवाब अक्सर व्यक्तिगत विचारों, मान्यताओं, और ज़िंदगी के अनुभवों पर निर्भर करते हैं.

  1. खुशियां और खुशहाली: बहुत से लोग मानते हैं कि ज़िंदगी का लक्ष्य निजी खुशी और सेहत पाना है. इसके लिए, हमें ऐसी गतिविधियों की तलाश करनी होगी जो खुद को खुश रखें, अहम रिश्ते बनाएं, अपने शारीरिक और मानसिक स्वास्थ्य की देखभाल करें, और अपने निजी लक्ष्यों और दिलचस्पियों को पूरा करें.

  2. सच में योगदान: कुछ लोग मानते हैं कि ज़िंदगी का मकसद दुनिया के लिए फ़ायदेमंद योगदान देना है. इसका मकसद, दूसरों को फ़ायदा पहुंचाने वाले काम करना, स्वयंसेवा या चैरिटी से जुड़ी गतिविधियां करना, कला या साहित्य तैयार करना या आविष्कार करना शामिल है.

  3. खुद का एहसास और खुद का विकास: खुद को साकार करना और खुद का विकास करना, ज़िंदगी का एक और लक्ष्य है. इसके लिए, हमें नए कौशल सीखने, अपनी सीमाओं को पार करने, निजी रुकावटों का सामना करने, और एक व्यक्ति के तौर पर बेहतर बनने की ज़रूरत होती है.

  4. नैतिक और नैतिक व्यवहार: कुछ लोगों का मानना है कि जीवन का लक्ष्य नैतिकता और नैतिक व्यवहार है. इसके लिए हमें अपने नैतिक सिद्धांतों का पालन करना होगा. मुश्किल होने पर भी सही काम करना होगा और दुनिया को एक बेहतर जगह बनाने की कोशिश करनी होगी.

  5. आध्यात्मिक संतुष्टि: कुछ लोगों के लिए, जीवन का उद्देश्य आध्यात्मिक या धार्मिक मान्यताओं से जुड़ा होता है. ऐसा करने के लिए, आपको ज़्यादा ताकत हासिल करने, धार्मिक रीति-रिवाज़ करने या आध्यात्मिक शिक्षाओं का पालन करने की ज़रूरत होगी.

  6. ज़िंदगी को पूरी तरह से देखना: कुछ लोग मानते हैं कि ज़िंदगी का लक्ष्य सिर्फ़ वही अनुभव पाना है जो इसमें मौजूद है. इसके लिए सफ़र करना, नई चीज़ें आज़माना, जोखिम उठाना, और नई-नई चीज़ों का सामना करना पड़ सकता है.

  7. लेगसी और असर: दूसरे लोगों का मानना है कि ज़िंदगी का मकसद एक यादगार विरासत और दुनिया पर असर छोड़ना होता है. इसके लिए, हमें कुछ अहम काम करना, अपने योगदान के लिए याद रखना या दूसरों को प्रेरित करना और प्रेरित करना शामिल हो सकता है.

  8. संतुलन और सामंजस्य तलाशना: कुछ लोगों के लिए, जीवन का मकसद अपनी ज़िंदगी के सभी पहलुओं में संतुलन और सामंजस्य तलाशना होता है. इसके लिए, ये लोगों को निजी, पेशेवर, और सामाजिक ज़िम्मेदारियों से लड़ना होगा और मन की शांति और संतुष्टि के लिए तलाश करनी पड़ सकती है. इसके अलावा, अपने मूल्यों और मान्यताओं के हिसाब से जीवन जीने की ज़रूरत भी पड़ सकती है.

आखिरकार, ज़िंदगी का मतलब एक निजी सफ़र होता है. ऐसे में अलग-अलग लोग अपने अनुभवों, भावनाओं को समझने, और अपने आस-पास की दुनिया के साथ बातचीत करके, अपने खास मकसद को खोज सकते हैं.

अगर एपीआई नतीजा नहीं दिखा सका, तो GenerateContentResponse.prompt_feedback पर जाकर देखें कि प्रॉम्प्ट से जुड़ी सुरक्षा से जुड़ी वजहों से उसे ब्लॉक तो नहीं किया गया है.

response.prompt_feedback
safety_ratings {
  category: HARM_CATEGORY_SEXUALLY_EXPLICIT
  probability: NEGLIGIBLE
}
safety_ratings {
  category: HARM_CATEGORY_HATE_SPEECH
  probability: NEGLIGIBLE
}
safety_ratings {
  category: HARM_CATEGORY_HARASSMENT
  probability: NEGLIGIBLE
}
safety_ratings {
  category: HARM_CATEGORY_DANGEROUS_CONTENT
  probability: NEGLIGIBLE
}

Gemini किसी एक सवाल के लिए कई संभावित जवाब जनरेट कर सकता है. इन संभावित जवाबों को candidates कहा जाता है. आपके पास इनकी समीक्षा करके, सबसे सही जवाब को चुनने का विकल्प होता है.

GenerateContentResponse.candidates के साथ जवाब देने वाले कैंडिडेट देखें:

response.candidates
[content {
  parts {
    text: "The query of life\'s purpose has perplexed people across centuries, cultures, and continents. While there is no universally recognized response, many ideas have been put forth, and the response is frequently dependent on individual ideas, beliefs, and life experiences.\n\n1. **Happiness and Well-being:** Many individuals believe that the goal of life is to attain personal happiness and well-being. This might entail locating pursuits that provide joy, establishing significant connections, caring for one\'s physical and mental health, and pursuing personal goals and interests.\n\n2. **Meaningful Contribution:** Some believe that the purpose of life is to make a meaningful contribution to the world. This might entail pursuing a profession that benefits others, engaging in volunteer or charitable activities, generating art or literature, or inventing.\n\n3. **Self-realization and Personal Growth:** The pursuit of self-realization and personal development is another common goal in life. This might entail learning new skills, pushing one\'s boundaries, confronting personal obstacles, and evolving as a person.\n\n4. **Ethical and Moral Behavior:** Some believe that the goal of life is to act ethically and morally. This might entail adhering to one\'s moral principles, doing the right thing even when it is difficult, and attempting to make the world a better place.\n\n5. **Spiritual Fulfillment:** For some, the purpose of life is connected to spiritual or religious beliefs. This might entail seeking a connection with a higher power, practicing religious rituals, or following spiritual teachings.\n\n6. **Experiencing Life to the Fullest:** Some individuals believe that the goal of life is to experience all that it has to offer. This might entail traveling, trying new things, taking risks, and embracing new encounters.\n\n7. **Legacy and Impact:** Others believe that the purpose of life is to leave a lasting legacy and impact on the world. This might entail accomplishing something noteworthy, being remembered for one\'s contributions, or inspiring and motivating others.\n\n8. **Finding Balance and Harmony:** For some, the purpose of life is to find balance and harmony in all aspects of their lives. This might entail juggling personal, professional, and social obligations, seeking inner peace and contentment, and living a life that is in accordance with one\'s values and beliefs.\n\nUltimately, the meaning of life is a personal journey, and different individuals may discover their own unique purpose through their experiences, reflections, and interactions with the world around them."
  }
  role: "model"
}
finish_reason: STOP
index: 0
safety_ratings {
  category: HARM_CATEGORY_SEXUALLY_EXPLICIT
  probability: NEGLIGIBLE
}
safety_ratings {
  category: HARM_CATEGORY_HATE_SPEECH
  probability: NEGLIGIBLE
}
safety_ratings {
  category: HARM_CATEGORY_HARASSMENT
  probability: NEGLIGIBLE
}
safety_ratings {
  category: HARM_CATEGORY_DANGEROUS_CONTENT
  probability: NEGLIGIBLE
}
]

जनरेट होने की पूरी प्रोसेस पूरी होने के बाद, मॉडल डिफ़ॉल्ट रूप से रिस्पॉन्स देता है. आपके पास, जनरेट होने वाले जवाब को स्ट्रीम करने का भी विकल्प है. जैसे ही जवाब जनरेट होगा, मॉडल उसके कई हिस्सों को दिखाएगा.

जवाबों को स्ट्रीम करने के लिए, GenerativeModel.generate_content(..., stream=True) का इस्तेमाल करें.

%%time
response = model.generate_content("What is the meaning of life?", stream=True)
CPU times: user 102 ms, sys: 25.1 ms, total: 128 ms
Wall time: 7.94 s
for chunk in response:
  print(chunk.text)
  print("_"*80)
The query of life's purpose has perplexed people across centuries, cultures, and
________________________________________________________________________________
 continents. While there is no universally recognized response, many ideas have been put forth, and the response is frequently dependent on individual ideas, beliefs, and life experiences
________________________________________________________________________________
.

1. **Happiness and Well-being:** Many individuals believe that the goal of life is to attain personal happiness and well-being. This might entail locating pursuits that provide joy, establishing significant connections, caring for one's physical and mental health, and pursuing personal goals and aspirations.

2. **Meaning
________________________________________________________________________________
ful Contribution:** Some believe that the purpose of life is to make a meaningful contribution to the world. This might entail pursuing a profession that benefits others, engaging in volunteer or charitable activities, generating art or literature, or inventing.

3. **Self-realization and Personal Growth:** The pursuit of self-realization and personal development is another common goal in life. This might entail learning new skills, exploring one's interests and abilities, overcoming obstacles, and becoming the best version of oneself.

4. **Connection and Relationships:** For many individuals, the purpose of life is found in their relationships with others. This might entail building
________________________________________________________________________________
 strong bonds with family and friends, fostering a sense of community, and contributing to the well-being of those around them.

5. **Spiritual Fulfillment:** For those with religious or spiritual beliefs, the purpose of life may be centered on seeking spiritual fulfillment or enlightenment. This might entail following religious teachings, engaging in spiritual practices, or seeking a deeper understanding of the divine.

6. **Experiencing the Journey:** Some believe that the purpose of life is simply to experience the journey itself, with all its joys and sorrows. This perspective emphasizes embracing the present moment, appreciating life's experiences, and finding meaning in the act of living itself.

7. **Legacy and Impact:** For others, the goal of life is to leave a lasting legacy or impact on the world. This might entail making a significant contribution to a particular field, leaving a positive mark on future generations, or creating something that will be remembered and cherished long after one's lifetime.

Ultimately, the meaning of life is a personal and subjective question, and there is no single, universally accepted answer. It is about discovering what brings you fulfillment, purpose, and meaning in your own life, and living in accordance with those values.
________________________________________________________________________________

स्ट्रीम करते समय, रिस्पॉन्स के कुछ एट्रिब्यूट तब तक उपलब्ध नहीं होते, जब तक कि सभी रिस्पॉन्स हिस्सों को दोहराया नहीं जाता. इसके बारे में यहां बताया गया है:

response = model.generate_content("What is the meaning of life?", stream=True)

prompt_feedback एट्रिब्यूट काम करता है:

response.prompt_feedback
safety_ratings {
  category: HARM_CATEGORY_SEXUALLY_EXPLICIT
  probability: NEGLIGIBLE
}
safety_ratings {
  category: HARM_CATEGORY_HATE_SPEECH
  probability: NEGLIGIBLE
}
safety_ratings {
  category: HARM_CATEGORY_HARASSMENT
  probability: NEGLIGIBLE
}
safety_ratings {
  category: HARM_CATEGORY_DANGEROUS_CONTENT
  probability: NEGLIGIBLE
}

हालांकि, text जैसे एट्रिब्यूट इस्तेमाल नहीं किए जाते:

try:
  response.text
except Exception as e:
  print(f'{type(e).__name__}: {e}')
IncompleteIterationError: Please let the response complete iteration before accessing the final accumulated
attributes (or call `response.resolve()`)

इमेज और टेक्स्ट इनपुट से टेक्स्ट जनरेट करें

Gemini एक मल्टीमोडल मॉडल (gemini-pro-vision) उपलब्ध कराता है. यह मॉडल टेक्स्ट, इमेज, और इनपुट, दोनों को स्वीकार करता है. GenerativeModel.generate_content एपीआई को मल्टीमोडल प्रॉम्प्ट मैनेज करने के लिए डिज़ाइन किया गया है. यह टेक्स्ट आउटपुट देता है.

चलिए, इमेज शामिल करते हैं:

curl -o image.jpg https://t0.gstatic.com/licensed-image?q=tbn:ANd9GcQ_Kevbk21QBRy-PgB4kQpS79brbmmEG7m3VOTShAn4PecDU5H5UxrJxE3Dw1JiaG17V88QIol19-3TM2wCHw
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  405k  100  405k    0     0  6982k      0 --:--:-- --:--:-- --:--:-- 7106k
import PIL.Image

img = PIL.Image.open('image.jpg')
img

png

gemini-pro-vision मॉडल का इस्तेमाल करें और इमेज को generate_content की मदद से मॉडल को पास करें.

model = genai.GenerativeModel('gemini-pro-vision')
response = model.generate_content(img)

to_markdown(response.text)

ब्राउन राइस, भुनी हुई ब्रोकोली, और शिमला मिर्च के साथ चिकन टेरियाकी मील प्रेप बोल.

किसी प्रॉम्प्ट में टेक्स्ट और इमेज, दोनों शामिल करने के लिए, स्ट्रिंग और इमेज वाली सूची पास करें:

response = model.generate_content(["Write a short, engaging blog post based on this picture. It should include a description of the meal in the photo and talk about my journey meal prepping.", img], stream=True)
response.resolve()
to_markdown(response.text)

खाने के लिए तैयारी करने से समय और पैसे बचाने में मदद मिलती है. यह सेहतमंद खाने में भी आपकी मदद कर सकता है. यह खाना, स्वादिष्ट और सेहतमंद भोजन का एक बेहतरीन उदाहरण है. इसे समय से पहले आसानी से तैयार किया जा सकता है.

इस खाने में ब्राउन चावल, भुनी हुई सब्ज़ियां, और चिकन टेरियाकी शामिल है. ब्राउन चावल एक पूरा दाना होता है, जिसमें फ़ाइबर और पोषक तत्व बहुत ज़्यादा होते हैं. भुनी हुई सब्ज़ियां, आपको हर दिन विटामिन और मिनरल की खुराक बढ़ाने का बेहतरीन तरीका हैं. चिकन टेरियाकी, प्रोटीन का एक स्रोत है. इसमें पूरे स्वाद की चीज़ें भी होती हैं.

इस पकवान को पहले से तैयार करना आसान है. बस ब्राउन चावल पकाएं, सब्ज़ियां भूनें, और चिकन टेरियाकी पकाएं. इसके बाद, खाने को अलग-अलग कंटेनर में रखें और उन्हें रेफ़्रिजरेटर में रखें. जब आप खाने के लिए तैयार हों, तो बस एक कंटेनर लें और उसे गर्म करें.

यह खाना उन व्यस्त लोगों के लिए बेहतरीन विकल्प है जिन्हें खाने के लिए सेहतमंद और स्वादिष्ट खाना चाहिए. यह उन लोगों के लिए भी बढ़िया खाना है जो वज़न कम करने या अपने वज़न को बनाए रखने की कोशिश कर रहे हैं.

अगर आपको कोई ऐसा पौष्टिक और स्वादिष्ट खाना चाहिए जिसे समय से पहले तैयार किया जा सके, तो यह खाना आपके लिए बेहतरीन विकल्प है. इसे आज ही आज़माएं!

चैट पर की गई बातचीत

Gemini आपको हर मोड़ पर बिना किसी शुल्क के बातचीत करने की सुविधा देगा. ChatSession क्लास, बातचीत की स्थिति को मैनेज करके प्रोसेस को आसान बनाती है. इसलिए, generate_content की तरह आपको बातचीत के इतिहास को सूची के तौर पर सेव करने की ज़रूरत नहीं होती.

चैट शुरू करें:

model = genai.GenerativeModel('gemini-pro')
chat = model.start_chat(history=[])
chat
<google.generativeai.generative_models.ChatSession at 0x7b7b68250100>

ChatSession.send_message तरीका वही GenerateContentResponse टाइप दिखाता है जो GenerativeModel.generate_content को दिखाता है. इसमें आपका मैसेज और चैट के इतिहास में जवाब भी जोड़ा जाता है:

response = chat.send_message("In one sentence, explain how a computer works to a young child.")
to_markdown(response.text)

कंप्यूटर एक बहुत ही स्मार्ट मशीन की तरह है, जो हमारे निर्देशों को समझ सकता है और उनका पालन कर सकता है. साथ ही, हमारे काम में हमारी मदद कर सकता है और हमारे साथ गेम भी खेल सकता है!

chat.history
[parts {
   text: "In one sentence, explain how a computer works to a young child."
 }
 role: "user",
 parts {
   text: "A computer is like a very smart machine that can understand and follow our instructions, help us with our work, and even play games with us!"
 }
 role: "model"]

बातचीत जारी रखने के लिए, मैसेज भेजना जारी रखा जा सकता है. चैट को स्ट्रीम करने के लिए, stream=True आर्ग्युमेंट का इस्तेमाल करें:

response = chat.send_message("Okay, how about a more detailed explanation to a high schooler?", stream=True)

for chunk in response:
  print(chunk.text)
  print("_"*80)
A computer works by following instructions, called a program, which tells it what to
________________________________________________________________________________
 do. These instructions are written in a special language that the computer can understand, and they are stored in the computer's memory. The computer's processor
________________________________________________________________________________
, or CPU, reads the instructions from memory and carries them out, performing calculations and making decisions based on the program's logic. The results of these calculations and decisions are then displayed on the computer's screen or stored in memory for later use.

To give you a simple analogy, imagine a computer as a
________________________________________________________________________________
 chef following a recipe. The recipe is like the program, and the chef's actions are like the instructions the computer follows. The chef reads the recipe (the program) and performs actions like gathering ingredients (fetching data from memory), mixing them together (performing calculations), and cooking them (processing data). The final dish (the output) is then presented on a plate (the computer screen).

In summary, a computer works by executing a series of instructions, stored in its memory, to perform calculations, make decisions, and display or store the results.
________________________________________________________________________________

glm.Content ऑब्जेक्ट में, glm.Part ऑब्जेक्ट की सूची होती है. हर ऑब्जेक्ट में टेक्स्ट (स्ट्रिंग) या inline_data (glm.Blob) मौजूद होता है. इस सूची में, ब्लॉब में बाइनरी डेटा और mime_type मौजूद होते हैं. चैट का इतिहास, ChatSession.history में glm.Content ऑब्जेक्ट की सूची के तौर पर उपलब्ध होता है:

for message in chat.history:
  display(to_markdown(f'**{message.role}**: {message.parts[0].text}'))

user: एक वाक्य में बताओ कि छोटे बच्चे के लिए कंप्यूटर कैसे काम करता है.

model: कंप्यूटर एक बहुत स्मार्ट मशीन की तरह होता है, जो हमारे निर्देशों को समझ सकता है और उनका पालन कर सकता है. साथ ही, हमारे काम में हमारी मदद कर सकता है और हमारे साथ गेम भी खेल सकता है!

user: ठीक है, हाई स्कूल के किसी छात्र/छात्रा को इस बारे में विस्तार से बताना कैसा रहेगा?

model: कंप्यूटर निर्देशों का पालन करके काम करता है. इसे प्रोग्राम कहते हैं. इससे कंप्यूटर को पता चलता है कि क्या करना है. इन निर्देशों को एक खास भाषा में लिखा जाता है, जिसे कंप्यूटर समझ सकता है. साथ ही, इन्हें कंप्यूटर की मेमोरी में सेव किया जाता है. कंप्यूटर का प्रोसेसर या सीपीयू, मेमोरी से मिले निर्देशों को पढ़ता है और उन्हें प्रोसेस करता है. साथ ही, प्रोग्राम के तर्क के आधार पर गिनती और फ़ैसले लेता है. फिर इन गणनाओं और फ़ैसलों के परिणाम कंप्यूटर की स्क्रीन पर प्रदर्शित किए जाते हैं या बाद में उपयोग के लिए मेमोरी में स्टोर किए जाते हैं.

मान लीजिए कि एक कंप्यूटर एक शेफ़ के तौर पर रेसिपी फ़ॉलो करता है. रेसिपी, किसी प्रोग्राम की तरह होती है और शेफ़ की कार्रवाइयां कंप्यूटर के निर्देशों के मुताबिक होती हैं. शेफ़, रेसिपी (प्रोग्राम) को पढ़ता है और चीज़ों को इकट्ठा करने (मेमोरी से डेटा फ़ेच करना), उन्हें आपस में मिलाना (कैलकुलेशन करना), और खाना पकाने (डेटा प्रोसेस करना) जैसी कार्रवाइयां करता है. आखिरी डिश (आउटपुट) को प्लेट (कंप्यूटर स्क्रीन) पर पेश किया जाता है.

जवाब में, कंप्यूटर अपनी मेमोरी में स्टोर किए गए निर्देशों की सीरीज़ को लागू करके, गिनती करता है, फ़ैसले लेता है, और नतीजे दिखाता है या सेव करता है.

टोकन गिनें

बड़े लैंग्वेज मॉडल में कॉन्टेक्स्ट विंडो होती है. कॉन्टेक्स्ट की लंबाई को अक्सर टोकन की संख्या के हिसाब से मापा जाता है. Gemini API की मदद से, किसी भी glm.Content ऑब्जेक्ट के लिए टोकन की संख्या तय की जा सकती है. सबसे आसान स्थिति में, GenerativeModel.count_tokens तरीके में क्वेरी स्ट्रिंग इस तरह पास की जा सकती है:

model.count_tokens("What is the meaning of life?")
total_tokens: 7

इसी तरह, अपने ChatSession के लिए token_count देखा जा सकता है:

model.count_tokens(chat.history)
total_tokens: 501

एम्बेड करने की सुविधा का इस्तेमाल करना

एम्बेड करना, जानकारी को किसी अरे में फ़्लोटिंग पॉइंट नंबर की सूची के तौर पर दिखाने के लिए इस्तेमाल की जाने वाली तकनीक है. Gemini की मदद से टेक्स्ट (शब्द, वाक्य, और टेक्स्ट के ब्लॉक) को वेक्टर फ़ॉर्मैट में दिखाया जा सकता है. इससे एम्बेड किए गए कॉन्टेंट की तुलना करना और उनमें अंतर दिखाना आसान हो जाता है. उदाहरण के लिए, एक जैसे विषय या भावना वाले दो टेक्स्ट में समान एम्बेडिंग होनी चाहिए, जिसे गणितीय तुलना तकनीकों जैसे कोसाइन समानता के ज़रिए पहचाना जा सकता है. एम्बेड करने का इस्तेमाल क्यों और कैसे करना चाहिए, इस बारे में ज़्यादा जानने के लिए एम्बेड करने की गाइड देखें.

एम्बेड करने की प्रोसेस जनरेट करने के लिए, embed_content तरीके का इस्तेमाल करें. यह तरीका, नीचे दिए गए टास्क (task_type) के लिए एम्बेड करने का काम करता है:

टास्क किस तरह का है ब्यौरा
RETRIEVAL_QUERY तय करता है कि दिया गया टेक्स्ट किसी खोज/उपयोगकर्ता हासिल करने की सेटिंग में मौजूद क्वेरी है.
RETRIEVAL_DOCUMENT तय करता है कि दिया गया टेक्स्ट खोज/वापस पाने की सेटिंग में मौजूद एक दस्तावेज़ है. इस टास्क टाइप का इस्तेमाल करने के लिए, title की ज़रूरत होती है.
SEMANTIC_SIMILARITY इससे यह तय होता है कि दिए गए टेक्स्ट का इस्तेमाल सिमैंटिक टेक्स्ट वाली समानता (एसटीएस) के लिए किया जाएगा.
कैटगरी तय करना इससे यह पता चलता है कि एम्बेड किए गए लिंक का इस्तेमाल, कैटगरी तय करने के लिए किया जाएगा.
क्लस्टरिंग इससे यह पता चलता है कि एम्बेड किए गए लिंक का इस्तेमाल, क्लस्टरिंग के लिए किया जाएगा.

यहां बताया गया तरीका, दस्तावेज़ वापस लाने के लिए एक स्ट्रिंग के लिए एम्बेडिंग जनरेट करता है:

result = genai.embed_content(
    model="models/embedding-001",
    content="What is the meaning of life?",
    task_type="retrieval_document",
    title="Embedding of single string")

# 1 input > 1 vector output
print(str(result['embedding'])[:50], '... TRIMMED]')
[-0.003216741, -0.013358698, -0.017649598, -0.0091 ... TRIMMED]

स्ट्रिंग के बैच को हैंडल करने के लिए, content में स्ट्रिंग की एक सूची पास करें:

result = genai.embed_content(
    model="models/embedding-001",
    content=[
      'What is the meaning of life?',
      'How much wood would a woodchuck chuck?',
      'How does the brain work?'],
    task_type="retrieval_document",
    title="Embedding of list of strings")

# A list of inputs > A list of vectors output
for v in result['embedding']:
  print(str(v)[:50], '... TRIMMED ...')
[0.0040260437, 0.004124458, -0.014209415, -0.00183 ... TRIMMED ...
[-0.004049845, -0.0075574904, -0.0073463684, -0.03 ... TRIMMED ...
[0.025310587, -0.0080734305, -0.029902633, 0.01160 ... TRIMMED ...

genai.embed_content फ़ंक्शन, सामान्य स्ट्रिंग या स्ट्रिंग की सूचियां स्वीकार करता है, लेकिन असल में इसे glm.Content टाइप (जैसे कि GenerativeModel.generate_content) के हिसाब से बनाया जाता है. glm.Content ऑब्जेक्ट, एपीआई में बातचीत की मुख्य यूनिट होते हैं.

glm.Content ऑब्जेक्ट, मल्टीमोडल है. हालांकि, embed_content वाला तरीका सिर्फ़ टेक्स्ट एम्बेड करने की सुविधा देता है. इस डिज़ाइन से एपीआई को मल्टीमोडल एम्बेड करने में मदद करने की संभावना मिलती है.

response.candidates[0].content
parts {
  text: "A computer works by following instructions, called a program, which tells it what to do. These instructions are written in a special language that the computer can understand, and they are stored in the computer\'s memory. The computer\'s processor, or CPU, reads the instructions from memory and carries them out, performing calculations and making decisions based on the program\'s logic. The results of these calculations and decisions are then displayed on the computer\'s screen or stored in memory for later use.\n\nTo give you a simple analogy, imagine a computer as a chef following a recipe. The recipe is like the program, and the chef\'s actions are like the instructions the computer follows. The chef reads the recipe (the program) and performs actions like gathering ingredients (fetching data from memory), mixing them together (performing calculations), and cooking them (processing data). The final dish (the output) is then presented on a plate (the computer screen).\n\nIn summary, a computer works by executing a series of instructions, stored in its memory, to perform calculations, make decisions, and display or store the results."
}
role: "model"
result = genai.embed_content(
    model = 'models/embedding-001',
    content = response.candidates[0].content)

# 1 input > 1 vector output
print(str(result['embedding'])[:50], '... TRIMMED ...')
[-0.013921871, -0.03504407, -0.0051786783, 0.03113 ... TRIMMED ...

इसी तरह, चैट के इतिहास में glm.Content ऑब्जेक्ट की एक सूची होती है, जिसे सीधे embed_content फ़ंक्शन में भेजा जा सकता है:

chat.history
[parts {
   text: "In one sentence, explain how a computer works to a young child."
 }
 role: "user",
 parts {
   text: "A computer is like a very smart machine that can understand and follow our instructions, help us with our work, and even play games with us!"
 }
 role: "model",
 parts {
   text: "Okay, how about a more detailed explanation to a high schooler?"
 }
 role: "user",
 parts {
   text: "A computer works by following instructions, called a program, which tells it what to do. These instructions are written in a special language that the computer can understand, and they are stored in the computer\'s memory. The computer\'s processor, or CPU, reads the instructions from memory and carries them out, performing calculations and making decisions based on the program\'s logic. The results of these calculations and decisions are then displayed on the computer\'s screen or stored in memory for later use.\n\nTo give you a simple analogy, imagine a computer as a chef following a recipe. The recipe is like the program, and the chef\'s actions are like the instructions the computer follows. The chef reads the recipe (the program) and performs actions like gathering ingredients (fetching data from memory), mixing them together (performing calculations), and cooking them (processing data). The final dish (the output) is then presented on a plate (the computer screen).\n\nIn summary, a computer works by executing a series of instructions, stored in its memory, to perform calculations, make decisions, and display or store the results."
 }
 role: "model"]
result = genai.embed_content(
    model = 'models/embedding-001',
    content = chat.history)

# 1 input > 1 vector output
for i,v in enumerate(result['embedding']):
  print(str(v)[:50], '... TRIMMED...')
[-0.014632266, -0.042202696, -0.015757175, 0.01548 ... TRIMMED...
[-0.010979066, -0.024494737, 0.0092659835, 0.00803 ... TRIMMED...
[-0.010055617, -0.07208932, -0.00011750793, -0.023 ... TRIMMED...
[-0.013921871, -0.03504407, -0.0051786783, 0.03113 ... TRIMMED...

बेहतर इस्तेमाल के उदाहरण

नीचे दिए सेक्शन में, Gemini API के लिए Python SDK टूल के इस्तेमाल के बेहतर उदाहरणों और निचले लेवल की जानकारी के बारे में बताया गया है.

सुरक्षा से जुड़ी सेटिंग

safety_settings आर्ग्युमेंट की मदद से, यह कॉन्फ़िगर किया जा सकता है कि मॉडल, प्रॉम्प्ट और रिस्पॉन्स, दोनों में क्या-क्या ब्लॉक करेगा. सुरक्षा सेटिंग, डिफ़ॉल्ट रूप से ऐसे कॉन्टेंट को ब्लॉक करती है जिसमें सभी डाइमेंशन में, असुरक्षित कॉन्टेंट होने की संभावना कम या ज़्यादा होती है. सुरक्षा सेटिंग के बारे में ज़्यादा जानें.

कोई संदिग्ध प्रॉम्प्ट डालें और मॉडल को डिफ़ॉल्ट सुरक्षा सेटिंग के साथ चलाएं, और इससे कोई भी कैंडिडेट नहीं दिखेगा:

response = model.generate_content('[Questionable prompt here]')
response.candidates
[content {
  parts {
    text: "I\'m sorry, but this prompt involves a sensitive topic and I\'m not allowed to generate responses that are potentially harmful or inappropriate."
  }
  role: "model"
}
finish_reason: STOP
index: 0
safety_ratings {
  category: HARM_CATEGORY_SEXUALLY_EXPLICIT
  probability: NEGLIGIBLE
}
safety_ratings {
  category: HARM_CATEGORY_HATE_SPEECH
  probability: NEGLIGIBLE
}
safety_ratings {
  category: HARM_CATEGORY_HARASSMENT
  probability: NEGLIGIBLE
}
safety_ratings {
  category: HARM_CATEGORY_DANGEROUS_CONTENT
  probability: NEGLIGIBLE
}
]

prompt_feedback से आपको पता चलेगा कि किस सुरक्षा फ़िल्टर ने प्रॉम्प्ट को ब्लॉक किया है:

response.prompt_feedback
safety_ratings {
  category: HARM_CATEGORY_SEXUALLY_EXPLICIT
  probability: NEGLIGIBLE
}
safety_ratings {
  category: HARM_CATEGORY_HATE_SPEECH
  probability: NEGLIGIBLE
}
safety_ratings {
  category: HARM_CATEGORY_HARASSMENT
  probability: NEGLIGIBLE
}
safety_ratings {
  category: HARM_CATEGORY_DANGEROUS_CONTENT
  probability: NEGLIGIBLE
}

अब नई सुरक्षा सेटिंग के साथ मॉडल के लिए वही प्रॉम्प्ट दें. इसके बाद, आपको जवाब मिल सकता है.

response = model.generate_content('[Questionable prompt here]',
                                  safety_settings={'HARASSMENT':'block_none'})
response.text

यह भी ध्यान रखें कि सवाल पास होने पर, हर उम्मीदवार के पास अपना safety_ratings होता है, लेकिन जवाब के लिए दिए गए जवाब, सुरक्षा जांच में पास नहीं हो पाते.

मैसेज को कोड में बदलें

पिछले सेक्शन, SDK टूल पर निर्भर थे, ताकि एपीआई को अनुरोध आसानी से भेजे जा सकें. इस सेक्शन में, पिछले उदाहरण की तरह ही पूरी तरह से टाइप की गई जानकारी दी गई है. इससे आपको नीचे मौजूद जानकारी को बेहतर तरीके से समझने में मदद मिलती है कि SDK टूल, मैसेज को कैसे कोड में बदलता है.

Python SDK टूल, google.ai.generativelanguage क्लाइंट लाइब्रेरी है:

import google.ai.generativelanguage as glm

SDK टूल, आपके मैसेज को glm.Content ऑब्जेक्ट में बदलने की कोशिश करता है. इस ऑब्जेक्ट में glm.Part ऑब्जेक्ट की एक सूची होती है. इस सूची में, हर ऑब्जेक्ट में ये चीज़ें शामिल होती हैं:

  1. text (स्ट्रिंग)
  2. inline_data (glm.Blob), जहां ब्लॉब में बाइनरी data और mime_type होते हैं.

इनमें से किसी भी क्लास को मिलते-जुलते शब्दकोश के तौर पर पास भी किया जा सकता है.

इसलिए, पिछले उदाहरण की तरह पूरी तरह से टाइप किया गया कोड यह है:

model = genai.GenerativeModel('gemini-pro-vision')
response = model.generate_content(
    glm.Content(
        parts = [
            glm.Part(text="Write a short, engaging blog post based on this picture."),
            glm.Part(
                inline_data=glm.Blob(
                    mime_type='image/jpeg',
                    data=pathlib.Path('image.jpg').read_bytes()
                )
            ),
        ],
    ),
    stream=True)
response.resolve()

to_markdown(response.text[:100] + "... [TRIMMED] ...")

खाने के लिए तैयारी करने से समय और पैसे बचाने में मदद मिलती है. यह सेहतमंद खाने में भी आपकी मदद कर सकता है. ... [काट-छांट की गई] ...

मल्टी-टर्न वाली बातचीत

हालांकि, genai.ChatSession क्लास को पहले दिखाया गया है, लेकिन यह इस्तेमाल के कई उदाहरणों को हैंडल कर सकता है. हालांकि, यह कुछ अनुमान लगाती है. अगर इस्तेमाल का उदाहरण इस चैट लागू करने के तरीके में फ़िट नहीं होता है, तो ध्यान रखें कि genai.ChatSession, GenerativeModel.generate_content का सिर्फ़ एक रैपर है. एक अनुरोध के अलावा, यह मल्टी-टर्न बातचीत को भी हैंडल कर सकता है.

अलग-अलग मैसेज glm.Content ऑब्जेक्ट या साथ काम करने वाले डिक्शनरी हैं, जैसा कि पिछले सेक्शन में दिखाया गया है. शब्दकोश के तौर पर, मैसेज के लिए role और parts कुंजियों की ज़रूरत है. बातचीत का role या तो user हो सकता है, जो संकेत देता है या model हो सकता है, जो जवाब देता है.

glm.Content ऑब्जेक्ट की सूची पास करें और इसे मल्टी-टर्न चैट माना जाएगा:

model = genai.GenerativeModel('gemini-pro')

messages = [
    {'role':'user',
     'parts': ["Briefly explain how a computer works to a young child."]}
]
response = model.generate_content(messages)

to_markdown(response.text)

मान लें कि एक कंप्यूटर वाकई आपका अच्छा दोस्त है और वह कई कामों में आपकी मदद कर सकता है. जिस तरह आपके पास सोचने और सीखने के लिए दिमाग होता है, उसी तरह कंप्यूटर के पास भी दिमाग होता है, जिसे प्रोसेसर कहते हैं. यह कंप्यूटर के बॉस की तरह है, जो उसे यह बताता है कि क्या करना है.

कंप्यूटर के अंदर, मेमोरी नाम की एक खास जगह होती है, जो एक बड़े स्टोरेज बॉक्स की तरह होती है. यह वे सभी चीज़ें याद रखता है जो आप उसे करने के लिए कहती हैं. जैसे, गेम खोलना या वीडियो चलाना.

कीबोर्ड पर बटन दबाने या माउस से स्क्रीन पर मौजूद चीज़ों पर क्लिक करने का मतलब है कि कंप्यूटर पर मैसेज भेजा जा रहा है. ये मैसेज खास तारों से होकर प्रोसेसर तक पहुंचते हैं. इन तारों को केबल कहा जाता है.

प्रोसेसर मैसेज पढ़ता है और कंप्यूटर को बताता है कि उसे क्या करना है. यह प्रोग्राम खोल सकता है, आपको तस्वीरें दिखा सकता है या आपके लिए संगीत चला सकता है.

स्क्रीन पर दिखने वाली सभी चीज़ें ग्राफ़िक्स कार्ड से बनाई जाती हैं, जो कंप्यूटर के अंदर किसी जादुई कलाकार की तरह है. यह प्रोसेसर के निर्देशों को ध्यान में रखता है और उन्हें रंगीन तस्वीरों और वीडियो में बदल देता है.

अपने पसंदीदा गेम, वीडियो या तस्वीरों को सेव करने के लिए, कंप्यूटर एक खास स्टोरेज का इस्तेमाल करता है. इस जगह को हार्ड ड्राइव कहते हैं. यह एक बड़ी लाइब्रेरी की तरह है, जहां कंप्यूटर आपकी सभी कीमती चीज़ें सुरक्षित रख सकता है.

साथ ही, जब दोस्तों के साथ गेम खेलने या मज़ेदार वीडियो देखने के लिए इंटरनेट से कनेक्ट करना हो, तो इंटरनेट केबल या वाई-फ़ाई सिग्नल की मदद से मैसेज भेजने और पाने के लिए, कंप्यूटर नेटवर्क कार्ड जैसी किसी चीज़ का इस्तेमाल करता है.

इसलिए, जिस तरह आपका दिमाग कुछ नया सीखने और खेलने में आपकी मदद करता है उसी तरह कंप्यूटर का प्रोसेसर, मेमोरी, ग्राफ़िक्स कार्ड, हार्ड ड्राइव, और नेटवर्क कार्ड सभी साथ मिलकर आपके कंप्यूटर को एक शानदार दोस्त बनाते हैं, जिससे आपको शानदार काम करने में मदद मिलती है!

बातचीत जारी रखने के लिए, जवाब के साथ-साथ कोई दूसरा मैसेज जोड़ें.

messages.append({'role':'model',
                 'parts':[response.text]})

messages.append({'role':'user',
                 'parts':["Okay, how about a more detailed explanation to a high school student?"]})

response = model.generate_content(messages)

to_markdown(response.text)

मुख्य रूप से, कंप्यूटर एक ऐसी मशीन है जिसे निर्देशों का एक सेट लागू करने के लिए प्रोग्राम किया जा सकता है. इसमें कई ज़रूरी कॉम्पोनेंट होते हैं जो जानकारी को प्रोसेस करने, सेव करने, और दिखाने के लिए एक साथ काम करते हैं:

1. प्रोसेसर (सीपीयू): - कंप्यूटर का दिमाग. - निर्देश लागू करता है और कैलकुलेशन करता है. - गीगाहर्ट्ज़ (गीगाहर्ट्ज़) में मापी गई स्पीड. - आम तौर पर, ज़्यादा GHz का मतलब है डेटा को तेज़ी से प्रोसेस करना.

2. मेमोरी (रैम): - प्रोसेस किए जा रहे डेटा को अस्थायी तौर पर सेव करने के लिए मेमोरी. - प्रोग्राम के चलने के दौरान निर्देश और डेटा होल्ड करता है. - गीगाबाइट (जीबी) में मापा गया. - ज़्यादा जीबी रैम, एक साथ कई प्रोग्राम चलाने की सुविधा देती है.

3. स्टोरेज (एचडी/एसएसडी): - डेटा के लिए स्थायी स्टोरेज. - ऑपरेटिंग सिस्टम, प्रोग्राम, और उपयोगकर्ता फ़ाइलों को सेव करता है. - गीगाबाइट (जीबी) या टेराबाइट (टीबी) में मापा गया. - हार्ड डिस्क ड्राइव (एचडीडी), पारंपरिक, धीमी, और सस्ती होती हैं. - सॉलिड स्टेट ड्राइव (एसएसडी) नई, तेज़, और ज़्यादा महंगी हैं.

4. ग्राफ़िक कार्ड (GPU): - इमेज को प्रोसेस करता है और दिखाता है. - यह गेमिंग, वीडियो एडिटिंग, और ग्राफ़िक से जुड़े अन्य कामों के लिए ज़रूरी है. - इसे वीडियो रैम (वीआरएम) और घड़ी की स्पीड से मापा जाता है.

5. मदरबोर्ड: - सभी कॉम्पोनेंट कनेक्ट करता है. - शक्ति और संचार का रास्ता देता है.

6. इनपुट/आउटपुट (I/O) डिवाइस: - उपयोगकर्ता को कंप्यूटर से इंटरैक्ट करने की अनुमति दें. - उदाहरण: कीबोर्ड, माउस, मॉनिटर, प्रिंटर.

7. ऑपरेटिंग सिस्टम (ओएस): - ऐसा सॉफ़्टवेयर जो कंप्यूटर के संसाधनों को मैनेज करता है. - यूज़र इंटरफ़ेस और बुनियादी सुविधाएं देता है. - उदाहरण: Windows, macOS, Linux.

जब किसी प्रोग्राम को अपने कंप्यूटर पर चलाया जाता है, तो ये होते हैं:

  1. प्रोग्राम के निर्देश, स्टोरेज से मेमोरी में लोड किए जाते हैं.
  2. प्रोसेसर, मेमोरी से निर्देशों को पढ़ता है और उन्हें एक-एक करके लागू करता है.
  3. अगर निर्देश में कैलकुलेशन शामिल हैं, तो प्रोसेसर अपने अंकगणितीय लॉजिक यूनिट (एएलयू) का इस्तेमाल करके उन्हें करता है.
  4. अगर निर्देश में डेटा शामिल है, तो प्रोसेसर मेमोरी में पढ़ या लिखता है.
  5. कैलकुलेशन या डेटा में बदलाव के नतीजे, मेमोरी में सेव होते हैं.
  6. अगर प्रोग्राम को स्क्रीन पर कुछ दिखाने की ज़रूरत होती है, तो वह ग्राफ़िक कार्ड को ज़रूरी डेटा भेज देता है.
  7. ग्राफ़िक्स कार्ड डेटा को प्रोसेस करता है और उसे मॉनिटर पर भेजता है, जो इसे दिखाता है.

यह प्रोसेस तब तक जारी रहती है, जब तक प्रोग्राम अपना टास्क पूरा नहीं कर लेता या उपयोगकर्ता उसे बंद नहीं कर देता.

जनरेट करने का कॉन्फ़िगरेशन

generation_config आर्ग्युमेंट की मदद से, जनरेशन के पैरामीटर में बदलाव किया जा सकता है. मॉडल को भेजे जाने वाले हर प्रॉम्प्ट में, पैरामीटर वैल्यू शामिल होती हैं. ये वैल्यू, मॉडल के जवाबों को जनरेट करने के तरीके को कंट्रोल करती हैं.

model = genai.GenerativeModel('gemini-pro')
response = model.generate_content(
    'Tell me a story about a magic backpack.',
    generation_config=genai.types.GenerationConfig(
        # Only one candidate for now.
        candidate_count=1,
        stop_sequences=['x'],
        max_output_tokens=20,
        temperature=1.0)
)
text = response.text

if response.candidates[0].finish_reason.name == "MAX_TOKENS":
    text += '...'

to_markdown(text)

एक समय की बात है, हरी-भरी पहाड़ियों के बीच बसे एक छोटे से शहर में एक बच्ची रहती थी...

आगे क्या करना है

  • प्रॉम्प्ट डिज़ाइन, प्रॉम्प्ट बनाने की ऐसी प्रोसेस है जिसमें भाषा के मॉडल से ज़रूरी जवाब आते हैं. अच्छी तरह से स्ट्रक्चर किए गए प्रॉम्प्ट लिखना, यह पक्का करने का एक ज़रूरी हिस्सा है कि किसी भाषा मॉडल से सटीक और अच्छी क्वालिटी के जवाब मिलें. प्रॉम्प्ट लिखने के सबसे सही तरीकों के बारे में जानें.
  • Gemini, अलग-अलग तरह की ज़रूरतों को पूरा करने के लिए, कई मॉडल उपलब्ध कराता है. जैसे: इनपुट टाइप और जटिलता, चैट या डायलॉग लैंग्वेज से जुड़े अन्य टास्क को लागू करना, और साइज़ की सीमाएं तय करना. Gemini के उपलब्ध मॉडल के बारे में जानें.
  • Gemini, अनुरोधों की दर की सीमा बढ़ाने का अनुरोध करने के विकल्प देता है. Gemini-Pro मॉडल के लिए, हर मिनट 60 अनुरोध प्रति मिनट (आरपीएम) की दर तय की जा सकती है.