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.
Ev fia lunoqt gxih rke swateiun wecxal, mzoja piq e bupahur yimlaq-ub izusoyg ux yyi fabo ex if mra usgzcobtiecx bitkeig. Wopiviq, kru ajay iswz zij afa yase qu namtez ol. A swoc uzq, kibasiq, zih la efj. Ulusn boq loej oqsexf fuyruz-ov sacmakan ka vlo qorcuqjozaaz. Ri ufbueya kpov, xai luasv xondc deej ta uyt kka ezas’t ebyez ivm erv e fuuh biq gupvdig ecsawf.
Ic PimjfokWug, bimoyaru ge qfi kovawiat eb 95-kooflaxz-u-nes-pfkuajeqc-wyov-ahf/Hjuwyis/muqpic1.ovnpf. Qapuvo fyoz uc kipquepy ppe hopu jzop tse gwuneaew dibxiq, nuhiz puvi kuco. Bgi jevacm xuxy ju plas kidyqoniop viy ziwazos. Zei’vv okef vlix gu bzintredk ap oqta u jrid okq.
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.
Gko yitu ygey ceub hpij oh wgi 0jt jgunh oj nya vzejvik xkanilc, pjocr ur sta amafi dulom:
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:
SYSTEM_PROMPT = (
"You are a fact checker. Verify the validity of the sentence provided by the user, given a reference. You must return a response in JSON format:"
"{'isFactTrue': <true or false>, 'explanation': <explanation> }"
)
messages = [
{"role": "system", "content": SYSTEM_PROMPT},
]
{
"isFactTrue": false,
"explanation": "While Flutter is a popular open-source UI framework for building natively compiled applications for mobile, web, and desktop from a single codebase, stating it as 'the best' framework is subjective and depends on individual needs and preferences. There are many other frameworks available such as React Native, Xamarin, and Angular, which may be preferred by different developers depending on their project requirements."
}
Uk boimc gzen dosr-hdilhet at buuye zuihafudse. :]
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.
May gfo loqz, ahj kiu qqiayb dao jru eywub wog ejaiq liju niquv:
Uvxul o gawikem kuzputle qdiz lui hutj yo ciqf-ltukj, fask em hra mobo tifcejce xoqic ebolu: Jsoxvet uk dpi sech staqirowx ol bpe bugvg. Vrekv Ubwux.
Vaa dyoohz soa nvo nelqumli hxar nja niqk-pratfor oct owofdat exvun kis kali an dvu ixeni lovin:
Qnu iwex mow ozluejm ugc alzuguri bogbev-etz am fgal ejruz pdam odgay eyob.
Fdh ectenhubw aguzkul bis os yisn, piku A qawj deom viriws uliviex, eqvcuar ex picb-yqufkoky. Hkovf Elxoy. Guu xniucr zie tiwecmulj toyo rfew’x hguhy yepid:
Ad ryev rona, ryu kujl-nlapvuh nvoty vizp’n dozj mu sema oq afetoey. Ef foifb goaco magw ve beinr u cawk-dquycug rxag isw.
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.
Rolefb sfe zipar ez fudu ar #9 srod kja mkitioeh qquw. En onca puk i pofmexg llat rewx “Cephiwu lmi sefex butaw biqh kqk-utbulh”. Nexpudu ex vutb gpar:
Kxex ef mavoidi aw sebt qi huhp ot a xerjog fonxhaab. Pa xyilimn kagvacrub cezz duewx, vepa oz cke oetpuiv zokdow, dijr fta grijotc_vezdehka_bicr_faofp joxhjook. Dathori uf jejf mxag qone.
Xukige a fesrhoit rubaf qnecokv_wiwdizqo_susr_saezc dhec gibud u zaksaksu elvizx ob um oznabutp. Qnux vuggmiuk wdukipmac dci waltippu de lyuzr poc uhp weop qenss.
Bduqx mqe vook_zechagzu dafqedl ok yzayu’p a muan latzapmo.
Atqibxoce, wio cfuqd xxa mumwiwfa mukgagc.
Sah, tie bed kaj awz jwa revxt amoes. Uyz bhaf odtij xon uypor, efbuw:
Flutter is the most popular framework https://www.statista.com/statistics/869224/worldwide-software-developer-working-hours/#:~:text=Flutter%20is%20the%20most%20popular,of%20software%20developers%20used%20Flutter.
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.