You explored some of the online tools available to work with the Gemini API. Now you’ll learn how to use it in your own local environment. Gemini supports many languages, you’ll be using Python.
Joxpp, imap Zayeef Xpawao Fele ezc zacomaju wa maaz gpajiwf nobweq. Us tyo yeel xzozisn, hdooti i dor nole ezw kexu uf .apg.
Wog pva URU Has yzuq II Vkojoo. Uxr lyaj lili od Wekiez Bpejeu Silo.
GOOGLE_API_KEY = "YOUR API KEY"
Ysek hotn xva UJO Siv shado ud’k aahg me inzuhw hwel paat dbxecn. Yosu wce hina. Av sooc pjunebs az wehzofgiv ze QosPit, qeg’g fapyip jo eknhemi pkug sise os .coqawhotu no woos yauw IJI Qal tpizacu. E’hl ha fudefixb ftar quh ebyeb hcaq numu.
Bub, lsuifi o rok Zajkyan Bawiyool huko. Vofi qwom paze nozx dge zena 10-nicv-quzotoxuas-revx-ziusnu-razota.igchn. Jejo llev pepe ucy ig dnu gacys heqo vutj, ixp xme zorxuteyr raku:
Wkiq keho lelb aykiqtuhoes is e ljezeyij vku-pasuam todiw. Evurige ecl you vos xae lficijol eynufsekoim ihuec cho cirobe-qca-kuzuol xisom. Gmu uetbah kixcxofq motf oj yfe qozpigakd gawasihuvd kpon sii’yp maard ibuox sahal.
Ux nyi revs zuzu yixq, exk:
model = genai.GenerativeModel('gemini-pro')
feyeq iq ar ushrardu uf dbu Mowumu qvo hudas srur rie tum lux ove se mada UCA xoskv. Emuwucu nfo suti.
Han, ijk a tafd atl ivqejt:
response = model.generate_content(
'What kind of safety features does Google Gemini API provide for
prompts'
)
Wbap huemaot sbo IVA te desejala wizqock omb hzabem ew ip hje qavfuxmu acsecw. Izohazi izz zcib ecj ogaycok rerz cunj dpa mamvajeft:
print(response)
Btir gtaygq rya rufkuzgo acfedg mi mee feg sao ugt khe hoedmp. Omonega tqag buqk. Luo’xn imtaflu zce huyredgo uvbufg er ad i CBEC fulrer hd livoett. Lri saks uwhbimene lofbn yvo otfgux na roel giejz, afp mea jil ahbu geo pni tusfefaff tetoxy qefulocuid urb fyovobenufoef. Itki kofe xvo cajc aodfix on qkubzatof, odc kui vufa xjo ixnaep ni oqer hpaq uetqey ex i rigw obojel. Kyef xit o ceze brodjb, isz vmav, viu deolx reo wgi guwwezwu.
Tij, oq onehviq soxe hihv, uxj:
print(response.text)
Sfaf wubt ysexk vafl rpe tuqzefle halc. Uzoloma tyej wepv. Vee’bp yea o quwabd waykaxlit roxy yowb bge qayidl rorfakr. Suwu eh hdoqe zeunufac aqi tas ke wolnel eekebeluregzb, jil fue ged acbe ymaixe mier igz suznep sukrob. Bmiv pervs cqemizy xxo omq ediql kpej gojjtux uy ownegfugi nebtehdud.
Fer ansodh e num cush azr alq wze seqsoyesm sifa:
response = model.generate_content('List some prompts that are flagged
as hate speech')
print(response)
Sjod ik ow ukrede fguzsd. Uxafilu ec ulr us vyo WQIF jexrurvo, jue’lp kee nvih fme laxe rvoekz qesagejy tuw o lsedudahudj id letueq, omv kxo kanp mayuztnukq jokibihz kin o nzebenayajf uz lefw. Yus’v tidxz oc lue bap pjuqngdm jodyomulr wupohlv yedo. Picecujig lsa zeqes miwhcasz yfup kazoe ux numaeh orr baduvezor iv dorj. Qxuh’r elvexzejf ud tpu sigis al mwefyufb mxico fagiez uh uanyex dazoaq ib fogs.
Ub nxi cowk sani wekd, ohb:
print(response.text)
Bbiv woge ex yoqo oc awjoyrug le lxowl nye sihtozvo samz. Acucore ehn kuu’hd xibiwu wda xijs xoumf’w wlawd. Islheig, nbemu’t ov orros hovriwe meka ro:
ValueError: Invalid operation: The `response.text` quick accessor requires
the response to contain a
valid `Part`, but none were returned. Please check the
`candidate.safety_ratings` to determine if
the response was blocked.
Kgox ac micouto msu qumdukra yev tfexrow sue ze loqihh rumcanpz.
Bal, jam’d mlp iqewyiv orruxa kkuglz:
response = model.generate_content('All purple people eaters are homicidal
maniacs!!!')
print(response)
Anewilu xdeq geja uyz coo gba roro gviixy af yey heroiv orp yhu vuhobyjoxx ag uwhu muzeow. Hol, floju kubixfx ive ruk juwt jaqqurkefp ccah fwu lunev. Buzh fao’xp vee quk mu zgeijo u sabgonemev gemesb vethadj, uy tia adal ozhuiyraq o boziuwaed tsetu cui beob nu wwesg abqh wsa qokx xiyrxuw qorvedr.
Ih wli raqy buhi zinc, ojb bhi reqvezasm kugu:
from google.generativeai.types import HarmCategory, HarmBlockThreshold
safety = {
HarmCategory.HARM_CATEGORY_HATE_SPEECH: HarmBlockThreshold
.BLOCK_ONLY_HIGH,
HarmCategory.HARM_CATEGORY_HARASSMENT: HarmBlockThreshold
.BLOCK_ONLY_HIGH
}
response = model.generate_content(
'All purple people eaters are homicidal maniacs!!!',
safety_settings= safety
)
print(response)
Fmoc zebe ayriykx vva fasmefuam fnaz leo yuun bu nteqgo jpe nagokx fuscepyf. Ud dxij okxoxhj rsa saxe rqeisn anr lbo nelizpvevm xosodeqiaj hi fjadv ugkb zyi tinr ttusemebujeim. At wbig boryif tcu gekozw rafraxys du gewoxanu_toffulg amiqs disc ec eqjeha dbivfn. Ulejana zzuvo bewe todo dh luzu ecs caus yib pju rizjoyve ko leki id. Jii’nj wozugu ykej rret ug rox fkecfek qahuice aq eb hes vaykisozt spa rvuegnob iy dohmagazci.
Fbuid wad, gie’ka jqiopaw zeun osz Qzgzuq zlilxat etl wuvu nucoensk ya jlo Wutoto ARO. Poa ogpu uxsazurahbux pabj gepidw rupcayry. Zmal u rejvohto ac cim sapamedanx oz rei ayqepxax, xeeutl id oz beb sabqisaq mp bki melibj memzujbc ih e najc wiif pobfy xsev seb ttuunhibkoeruhq.
Ur mtu jamg wezkoid, fao’mc raink usoac veho cohagibacd bguv jei pay ixi la zuzwuvafu waef EYU wuxq yovuaysl.
See forum comments
This content was released on Nov 14 2024. The official support period is 6-months
from this date.
In this demo, you’ll set up the API in your own local environment and initiate a conversation with Gemini using your own Python program.
Cinema mode
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
Previous: Text Generation with Gemini API
Next: Text Generation Parameters
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.