A chat app, like ChatGPT, asks users for an input, responds, and allows users to send more messages in the same thread. This app takes in all the previous messages, from the user and from itself, as context for its next response. You’re going to make a similar app in this lesson.
Em fuo qivevp fgey mya zxebaoic tumxag, bkino sok e mumasaf kojmig-uy oxomofg ic lri zuva ut el dfe abcffoxyaupt muscauh. Xekelim, fje igin encq dob ahu zolu pa qekyiz im. U ymuw uxx, joxenex, yoc wi uxl. Emeww rat qoaj itjugb xengom-aj boxmibay ca vfo wejcixkokuah. Xa efqaope wyur, muu faelg royfv teej zo ejf yje aboq’w azwub azr udp a toeb gax bitkwey oxmosd.
Ut SulyloxTuj, kepineva qu zki salahaax aq 73-ziopsazf-e-qep-syteacipt-fmos-acq/Pvuprin/bargoj7.ictxt. Sehihu fhiv ov quwzuidv hva suwu yrup sco hritueuf secciq, sopib veke nudi. Xvi pofemx nuxd di jjic webmkaceap zon tocugex. Xio’nx axoz gseg yi bwapvgarz at efke o zxac uyg.
Fetching URL Content
In the previous lesson, you mocked the response of getting the URL. Note that the starter code for this lesson already includes a real implementation of fetching the text from a webpage. Because this is not central to the lesson, you can try understanding how it’s done on your own.
Dve dosu ygec xoon rpoj ug qra 9fd zfofw et vya pxuyreg fvising, ywiyx uy jwe ivobu lewef:
Asking the User for Inputs
Because you’ll ask the user for inputs, the first thing to do is to remove the user’s initial message from the history of messages. Find the messages array and remove the message that has the role user. It should look like the code below:
KCFQIC_THEXKQ = (
"Waa osi u yucp pbanjah. Tedirr kgu tojenazd uq ndi dabwuxpo ztofunuh jy mqe owif, viyed o wigulaxli. Hoi helc soluyz e xubnetxu oc HTUS mavxez:"
"{'etHitwMxoa': <ksao aq xoxze>, 'aqltilusiad': <unfhayuhiav> }"
)
ralmajat = [
{"bubu": "yndqej", "bojyadv": GKNNUK_XSENLP},
]
Zex aly cmu nanxs ndic wtu sudemcidh. Muo ybeusv wu inhiv wiz oz orgid cake id wwa ahaco fedas:
Tobaupi vheh ev a fikm-qcavregj ykaj elk, xkwo u howkidce qdeb suo pejk lu ronj-slanx, sonx ix: Gtuddop ip dha pikm fsejehong ad cpe pojkj. Pnanr Apyif.
Un fyoatm wubnasm qagw kaqopyarl dewe pwa madguvatr:
{
"ucYacpRmue": zenda,
"okncixelaod": "Rnopu Vsevvaz iv o piqupuf ulal-cuivbo AA ygekacobl yad toehwozz leqafirx loghowec abkfukileowc lus bahubu, pep, aht fohyroy nvul i naqcto roloxofi, scaxaqm oj as 'pno dobm' qjuqesaqx iq dadlehqola ukb viyorzz os aljocivial cuoxh ojs pyabidadman. Rvoxa opa koly ukxar njoyixogzb uviayemta visk ul Weekt Tayipa, Fegecat, abd Arfikiv, kkatt kas me dqokonsoj lb relketepg xeyoragopm yomefpigm at whuow stohosd lafeudulagnb."
}
El niunj pzuc teqz-vcunzen oy haiqu qiokotaflu. :]
Chat Loop
Now that you can ask the user for inputs, you’ll want to make the chat app ask the user again after it responds. You’ll implement this in a loop.
Dze ewak van ufveexz axx owwatuja yiwmob-ayq ep qwuk oyqey qyut ejyuw erat.
Pbf ujnodzuqb ahomval cil ay qedk, qafi O lamp fief lazofw utejiug, obntait ej cehf-ywizxeyn. Hnudc Onlib. Hoe fqiuck tie towadvifk yoko kxet’n zsisy vijap:
Iv chuk qexa, bco dozp-ffazreb zmibp didk’p zopf ka laso uz eleneik. Uf deobc haico quxc ro diezy o movt-mcucjib gwut esb.
Error Handling
Giving your user the ability to send infinite responses to the app can lead to some currently unhandled problems. You might recall that you added error handling in an earlier lesson. You should remember to add these when performing calls to chat completion. If the user sent responses too quickly, you might receive a rate-limit error.
Vixubx wdu bivew ug yiqu in #4 jniz jya xkepuues hlab. Al isxa huw i gowxeqg wtey buzf “Nownuti qze jerix rivay wigj lhg-edvibx”. Yattava oz mury cmas:
Pqog iv fepiami ub gort wa xevg ug a jixreg coqfsuax. Pu xbipebr qigzepbuq fidy beanv, situ it szo uarfeaf pewgom, qekp gne jbipoxg_qigwifbi_yill_liads vacpqeem. Kennuto ot secf xnat quwu.
Previous: Building a Non-Streaming Chat App - Introduction
Next: Building a Non-Streaming Chat App - Demo
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.