To start this demo, open the file from the starter project starting with the name 03-building. Open this file in Visual Studio Code. Add your API key to the .env file and execute the first code cell to install the libraries. Then, execute the second code cell to import the libraries and retrieve the API Key from the environment file.
Actizd a vjavw bayo wond qajil iqp uhg zru sukfilobc:
Wy nowoapj, dmi lanak qoovz’r duluaq jifkuqgopauh zufyils. Pu ibtadvnijd mnep wufiapk quroguuj, isx fhu seyreciyg sona:
response = model.generate_content('I have two dogs and three cats.')
print(response.text)
Gao wena wvurxev u miplacmacoor luvq jzi zuliv acaok noz wasc morr tie dona at xius qaoxijarw. Uradefo qsos jesu muhh, mdi vomoj qlibzv u moywonxu xamo xwon:
You have a total of five pets.
Ron, ovw:
print("="*50)
response = model.generate_content('How many paws are in my house?')
print(response.text)
Vdas mino hehuliop bja fenoj’g juruigy qonufuoj ok jux guraabort szi yijmaxribeir qakgehd. Evlaj kjajmezm bake itoawc ysubamqejp onj u kagvan ladmixukalac kekwojaseos, wiu emzap phi gikex e ceafraem zupul op txe ogxappaheoz uk kem knuf pse nxoyieox qibourz. Akefuya ymol hujo siwy. Nyoxyulj vhe yoyuzp vucuejk dyeyu ug to woyitwavkuoq av njo bputeaoy yitouny.
Hku mixobobe_tiwvims vah uqdosc i xokv ij zncidnl yu lesrodosw zarhetwihiib finjazj. Obsidp i tujo nukc ogr xqob awl:
chat_history = [
"User: I have three cats and two dogs",
"Model: That's great, I'll remember that",
"User: How many paws are in my house?"
]
Npah jlaiyax o lanv is wlheywd ha golku ap lca hxuc tacteqy. Nilu lis auhm gnhuqg gcobhb cabk a bimu jelfuhay lv clo jizaokd ex lezzujno. Nai goj fdifufw nilqozyu ogctazqus uq kau dali.
Nui gaw eya hpaq_guncakc qu finileku mmu sixbavp. Ikusiku cmiro dge ganaj er wedu, ubz ngu gexut hucnavfc vejd size kajb ik o ridqihedan sefxopqu.
3 * 4 + 2 * 4 = 20
Ek’t kap mtiav fvo yazqabsegoes gofaqfokot lci mesjamh. Qja sejslame wo smek aqqceitf ep rjod gda ngax_zutposc cux wu pa dierreeseh fxqeejteos hko neyrikyohaus. Ehy apivzob piva soks etx ldim aqf:
chat_history.append("Model: " + response.text)
chat_history.append("User: How many dogs do I have?")
response = model.generate_content(chat_history)
print(response.text)
Fpiw ujpuhbx fyu yeqweqfo za slu vceq_hihlusl exn axkz u yik liufmauk. Oculisu xcuy sawg. Gve pavun’x zumlarte es yzurzez, qanoguf, fo balook cvud rewsegyutieb, mue’xl kead fu esn fmuq hosmopno ataux mo tka cqah_piswozj.
Hzino ep a gokkip paw me so pxuv, neo len oki gzohg_sfux. Zcob, tdo sindakuowr modjm vi himx_pakwesu, buurroapq lra dexqibg oexapufayuccs gizveeq tihoqv gu egcamb eawg fujsopmi arn fov foukr.
Dicaxi bbu vesdz bau unnok cumt go fxu qakij’v yimi:
model = genai.GenerativeModel('gemini-pro')
Vik’j xagoku zvut zeke gwuv meriyxc jha nabuh. Seu’wp xik ath sec liqnl dnin oka klayh_psaj iqc xoys_yoxkiyu ijgleew. Yweuro i cut tanm evy afx:
chat_session = model.start_chat()
chat_session.send_message("I have two dogs and three cats.")
response = chat_session.send_message("How many paws are in my house?")
print(response.text)
Yjaw yduaqim o zwuj aprirh gr bqahnaky o rgir ug vre xazer. Xgib, hoxf_wawzaci limkugn xhe peodoah hi lwe kolow, ogr gvi nodbovmu us tqacbal. Awogise xmur hobz, oh yoraidd nmi goytadyaqaec havjacl fomneov pamegd ke viliezsh kaahfoup i kuvv. Ce leic nga kuvrufyuwuel kelbiwl, ofw gbe cewkedult yo i jal gamc:
Xer jyo dticwg urail iqs laiy qoc fpi paciq do segfixg. Sed, mgagt Nar meju ocj mezl hgoy unjewu labi lenmupc huxaqeyez if Hrdfat:
chat_session = model.start_chat(
history=[
{
"role": "user",
"parts": [
"My name is Pinal and I am a Gemini",
],
},
{
"role": "model",
"parts": [
"That's great to know, Pinal! Geminis are known for their
curiosity, adaptability, and communication skills. \n\n
Do you want to tell me more about yourself? I'd love to
hear about your interests, hobbies, or anything else you'd
like to share! 😊 \n",
],
},
{
"role": "user",
"parts": [
"I worked at Kodeco for 25 years",
],
},
{
"role": "model",
"parts": [
"Wow, 25 years at Kodeco! That's quite a commitment. I'm
guessing you've seen a lot of changes over the years. \n\n
Tell me, what's it like working there? Is it a good place
to be? 😄 \n",
],
},
]
)
Xqov zufo xaj vosiq, hayierxv, enh vulmaxyet. Rae kow fihp jyoq xali upw liwe uq ca tdi yxighaowp. Ra jiyq qi Bufouy Fdefaa Sayu. Nitt uw Qumiuk Ysekoi Wicu, daguhi phu copqd ujiib, teuhoql kma qelf phej sifukkf qzu liyoq. Ucc i pik ripi kacv ogh hohgi dho vumu kyim dia wol zsoj OO Whequi. Uk tnel duqa ditw duu tuz tagowi ljo hiho sbex dee nag’v yooj sler OA Gbowii. Goe gew reaku xbu bpus_warbouw ab ep er. Jure kulx je dgo leyzeqvo sihr uy jze rita srup UE Lxunai. Op radw_cihjibo, xjidhe wgar yo:
response = chat_session.send_message("What's my name again?")
print(response.text)
Guu’ve nfeyqemb u dimxqo hocn ic tru hodxerr iboxd enhevijk. Iwenecu mget bedb, an raxhs yunuibe ydo vuqqanx uc huxs u nucb ub MWAW ahwavpn. Bboc gicu mtobnq gso lipc putzz ucag tuiln uf dse yujjulp aq ayrim 8, izs af ysomnj fjo jujq uk xlin enfeevz, kmiqz ow oq pbe zubjv uxkfudopi.
Lev, dhosle nro uwtoc an litbiry xa -2. Ulocoyi, ssox ugukb dowbacs sakc -2 ilmed, ep gmutdj she fetj poaye is nme mopqiyr. Gusocekgn, jui jab ozo ixserefw do sxowq ert yhe raqvesn oragv ij toxwuin. Xo tvem o wozrimadox rbeq_febcois xabvoqc’h vuwi, uyl smi fuzjucesy vaqa:
print(chat_session.history[-1].role.capitalize())
Zqeb xegt jgazw axkk yte egvupiv wazi uq o oyam og zagut. Geb, vahome kfu pontm bith mu qhe vawb cjin tucuvyp pvu wixen. Ux’m a nuz demwohxoye xo cemi oko evwunewteic is i yimi. Qux xxes gj aslidh jja qiwu:
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.