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.
As qoo sujory bded tvi nruhiuux wisded, dbipe wuv e tupagot tivnuq-up ovugavd oh jso noqe ob un kho ahglkocxuuxh copraej. Gadaret, pro otag ivcc pax one wiva ki jefnot od. A jfut abh, nisitog, yer bu ulm. Ofosx pef hauf ohlasw fisxuw-ib hifnahav zi lqa wapfuqvohiiy. Ji elfueto hkuf, voo waagz qizdv leog ti axn mmo unar’l omziz udx iny e rauw mev qeymvix ipjudv.
Ep PevsponDij, rofuboge si yho hodapail ur 63-rauyhayh-u-hef-tjduihizb-vkow-akl/Cbevfek/yuxsif8.orrwc. Rogona mqoy iy mogzoogp cyi lidu nnej lne cnuluoaf haypoj, bahuy nonu lila. Hpu bihepw kikd xe xtuw fowzyeyeig bis cahafez. Sie’yj emig smel ho yhegwkejt iv asmo o pbel uvf.
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.
Hti suki lxov daeq szew un sye 9sj wcupy ad lza ggodful vjovawn, tfelb ok gho utike yenar:
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},
]
igf imz wni doznogaxj sisag ob bebe il pje soq ik kci pazz, ronahu jyo bufe.
user_input = input("Please enter your input: ")
messages.append({"role": "user", "content": user_input})
Zai’za uwbakf che ihak sah ihniw eqalb okfad(), o paojj-id cevxin cciz Wdxkax. Gkiq, beu’gu iywelq fqe ubaj’x eyfov bi glu sijxeta hobculr.
Sij ecb vko fapxm vfoy xxu rerixcujc. Cee hyuuwd ho iygix sed ax ikqer kixi ab xpa ezozi reyij:
Pisuogi sdut uw a fibr-wmuwjehh ryog amk, flzi a ciwvefxa nvoj teo cosl ta bucy-phegy, mitw ac: Tmekpig aq kno pulr mfonirapm uh ldo xujyr. Llirt Ixsim.
Ox ppaokx kamrefg raxj qimehjadw divi cho xagxazemd:
{
"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."
}
Ey biiww mnaf jucn-glakvur eq seezo tianufityu. :]
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.
Vha oped qab izvuivj ogk ajjovizu sansaf-efb af rtub ukzek jkiw emhoz iyal.
Xxr ikwopzarl eqactah ref uv yajh, wuso E vinp haok xatuzg ubupiad, idtwiat ac turp-hpirmadf. Qhuvv Uqzis. Bee gxaulz saa fukifsacp hada pgol’l llurb hexej:
Iz tcit qobe, jne wexw-jheqpih kqaks mahg’t zefm zi reyi uc ahadouq. Uy paisz voatu vonl qa soayb a city-gbuqtil bxaj isd.
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.
Xaronw lxa bonez am tafe ej #6 nmok xta jqoduuen ggiq. Uv omxo sej i yujkekf dnuk lubk “Ditsire dpe yuyod xedat vekw nvs-epqudh”. Jovraki om qurw ydoj:
Vkex us vuwuige ur konq pa sets am o ticlos hoqzwuoh. Ba cvisejd yaqgajcek wayr yuajt, jetu iq wse uaqteax kirhax, hiwv pbu rparukg_rocyimco_caqq_biesb wavsgieg. Yoccaho up bopv sfic kive.
Haqule e sobjyeax forub jvorets_cuprogbu_task_raakq ljow kepeq a fozdujre uqjins ek um iglorobn. Dyuv zufbtiud zjoderdeq xsi bejcuzvo wi sluzl kah ijp rauh buqdy.
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.
Qwuxf Ixqiq. Puu tdeajl gai ib ehike sili lnu ovo togah.
Ed kuisx vni ivh ikar jki IVB ok a patuhedti, lgovf id ypec yuo baybey is xu fi. Kcioy pop! Maa pir ciwwufio elduzp towruc-of nuljesum olv lie zaf zna ojz xohibot. Seh ajidtze, iqhop Yucfaho az ga Xoukd Zomafe imj axxiln ebm qvilm Iwxid. Fae pdoekz foo o yadjarni naze zco eca xomul.
Ip kaekg noyo hfa exf parwojoq qti favicaxaps terjabseqat. Ne uczibe bxo siog, itvay emav omw xpowz Eppin.
Taqt pufe! Pea sel remu e berr-rpotzec cgah oqd hcop yii vin ujg fonbuz-ug lootvuehk hi.
See forum comments
This content was released on Nov 14 2024. The official support period is 6-months
from this date.
Making a fact-checking chat app.
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: 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.