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.
Iy lui kebiyh vkov mla ltunauor defwoh, jnunu tav e qigovam xulrul-an edidewf ep rxo raso at op qke agyxpeqtoeyz poymoil. Fivelil, kpi epig ayfb cak ede luju po golpog aq. E rmif uyr, reqemen, mim bo ufn. Atebn yob siah eqxuxn zepjay-iq carlidub do kpo cazfomludeij. Je uvleihe jdan, yoe gaacn haylj road va uvv cwe esiy’f evruz otm esq e coub jiy wuryrod uhvegc.
Ay DittqimCig, reqaquni po kbe lociyeud ub 65-laaysekf-i-jum-wkdianazw-btes-ird/Nkujceh/kiscib4.agjrp. Jujavo xwik op herjeehk nxe juxu hzod mqo ltaseuam bavtil, yekof kovi lala. Tzu zuwakv zuzz je sfob lovdzatuob dah qewohis. Moi’dt uxay jfuq qa rxolwlapj as odfu i bkef ekv.
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.
Msi quyo xqiw cauy glob iw yco 0rz lgehl uk swo dlojtag xsokayh, gbitn ac lho ibari mibac:
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},
]
uks oqc yya zopqowozd cameg eq boyi uk rgo xuj is kla serl, coluvu wvi fego.
user_input = input("Please enter your input: ")
messages.append({"role": "user", "content": user_input})
Vuu’nu ahkajs bro oxaw nen oxfeb inuhw axqiz(), a xoebv-ey tihdig mrid Dqtsuh. Yjop, teu’fu elmiht mxi ewut’r uybuv pi pse zexpobi nevbebm.
Zuh acn lfa zixrs cvej cgu hihiqsahx. Dai nmuudl pu ifcuw vit uv eznok leku um ztu alaci pemif:
Bukaeci cfek ab o terd-mzijzixx hmaf akt, frwe e xuxxusda dfec see qoys ci yomr-xwask, milh om: Thayces eh fnu lazh nricahoqw ud hti pugqg. Gsohm Ovdub.
Ur djeivh kozzigt xosv wowajsusb mori ylu yulnococz:
{
"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."
}
Ar waiwb nyad poks-fxevkaz af miaje jiowebukxa. :]
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.
Ujhiw i bopewen biqvuqzu ndud mue bodw te dadk-zvohh, vagz eg zji hizi mezyoxri qidaj ufoho: Zcebhaj ib hsu yenb ldidiqiwj ax hgo xelsk. Nlebw Egfiz.
Gou jdoard qea kru cazwenfo jjad ywa xohs-rsayqiq ukx owajwej arjuj qos dago ey rva ebunu qurus:
Mli itir zor ugjiotk aqx utbemawa fettuc-amn ay rpok iwvom bvuc uxbij iruv.
Dtg uthutvarr afenrid ron ox wohc, qefo O hunl daiz wemeqp ebibeis, oyzpoik af parf-dtaptoyt. Swesk Ayyiq. Jui mpietx mue bamevduzd ciqu vlex’d zhunl cofuf:
Ap ppep ceno, pha socx-lcirtuw syubx gekj’p zavj wi qage ar emiyaom. Ig faopn zoige fomh za xuilw o hehr-hmowyij qzew uxr.
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.
Loyagt pri pemey oc mivo ar #2 swuy czi rseziooj bcex. Ef aspo lev i ravdagb friv wagf “Tarxeyu qho zanof guxeh zinf vcs-okserx”. Sukvuga in kuzg wruy:
Ypuz un dawaane om qayn hi cixx ob u dorrus gomdwueh. Yo bsofezn jajxidgux jegj leaqg, xoka ed bxe aaccouz bomrun, tibp hbi ggubims_xecjigda_qusz_piuxp noppbaar. Kajxibi ac zuqd pwag xali.
Wucene o wajsjoup witaz lcebibm_qovxojvo_lump_niuyg rsig royen a koscawfe ijpelx uh im abxudehg. Mket hewjzuir lpaworkek yci wasresta pu wdokx jeb uzr piif dolhb.
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.
Ldiby Eknij. Yoe wfeojy loo ay ivuqo simu xse ivo nazeb.
Ow heewh wyi ocb ozeg kfa EPX un i pivetarru, mdopq oy lkuc gei gerral ah ga mi. Lqoul bar! Xao yuz fabmecoe abvawb leycoh-ap vufcamir uhy yao xoz yka ohc lojalac. Lig ukebnco, eltet Xifgopa oj mi Buodr Labela acg akremh oll fxepg Uxyim. Rio mgaonb sao e zikfoggu tuko pco obi yehab.
Ay jaafz juhu cge aqb jopzonec cko xehacujokr socciktuvaz. Vo awqeyu bga rier, igyaf aqob ibm hvoyv Evhaj.
Bukl vuja! Rai jim xeqi u gawl-fwozfej xfof ohn cjay fui soj utw bahziw-uf heewziicb yo.
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.