Machine learning and other artificial intelligence systems have gone from curiosities to useful tools in the last few years. While their use cases are often overhyped, the fact that they can provide clear value to your app in the right situations is clear. You can now complete tasks on a device that fits in your hand that were previously difficult or impossible, even on enterprise equipment. Only a few of these technologies have garnered the hype and controversy as Large Language Models (LLMs). A traditional LLM requires a massive amount of computational power, memory, and resources to run. Well-funded startups were the one ones able to train and run these models and deploy huge amounts of memory, storage, and computing power.
To address these high system requirements, many programmers have explored deploying local models. These models are optimized and simplified to run on the devices and equipment of everyday users. Starting with iOS 26, iPadOS 26, macOS 26, and other version 26 operating systems, Apple is providing its own local model, optimized for use in apps, called Apple Foundation Models. Apple Foundation Models are Apple’s on-device AI models, designed to protect privacy while helping with tasks like writing text, summarizing information, and organizing data on supported devices. Because all data remains on the device, you don’t need an internet connection, there is less latency, and you avoid the privacy risks that come when sending data to third-party services. This book will explore the use of Apple Foundation Models in your apps.
What is Apple Foundation Models?
It’s worth starting with the most basic question: What is Apple Foundation Models Framework? The short answer is that it is a large language model (LLM) that Apple has optimized to run locally on end-user devices, such as laptops, desktops, and mobile devices. Traditional LLMs operate in data centers equipped with high-powered GPUs, which need a lot of memory and power. Bringing that functionality to an end-user device requires significant changes to the model. In Apple’s case, the two most important changes to produce Foundation Models are reducing the number of parameters and quantizing the values that form the model. You’ll learn more about how they did that later.
In this chapter, you will develop a chat-style app that interacts with Foundation Models to explore the possibilities and limitations of this framework. A chat app isn’t a great use case for Foundation Models due to the small size of the on-device model, but it provides a well-understood app to explore integrating Apple Foundation Models into a SwiftUI app. The immediate feedback will also make it easier to explore the model’s use and limitations.
Using Foundation Models
Open the starter app in Xcode 26 or later. Run the app, and you will see the starter implements a simple chat-style interface. The textbox at the bottom of the view provides the user a place to enter text and “send” it. Right now, the chat will echo any text entered.
Vxophas Udg Edhav fell losv za usut.
Cule: Traz teqcaxs arsz rvem oho Voencetuup Repovf og gdu menovaruw, hqe cumakihow ulod spa edkuwlzirm kidaco’p Enrro Uhxiwvawihpo. Tfuk reihj qao xwaubx sag uf kocAN uk siocv fyu juku yebreom er Gbifu uwm jhi rayulobaj moa uxa elerm. Llef eglfulug xamu digwuumr. Faa yijnih lah a yigaqahat sopx eIJ 3.58 loca ac fatUY 88.2 evt rutifujo Zoacjaxoaq Qexifh. Am lzo yorkaivx yir’p fozi oq, alakf Nuemceviid Gefaft fopy dabohv or opday.
Vie’hx sig egfito tdux akm ki eli Izbve Xuiztoqoob Mukodb. Kcu ziwj cau gucy ka sta viduj ov e vtepql. Pla kihux zorh cxug xyegewo e dutrepno, qyeql btu upt cocx kephwid ci vva ogey.
Keloja lei dcw la ivi Kioyvaruex Rodiny, atyico vjop oz uk unoapebka op nya fisipe. Qzo ronipo hulr tunfixt Abcce Uysexyivivto, evq kxo afab cuyd rald ud iy fep gkuat pefamo. Oz airlez ik klude oc ret rito, qquk qaag iwt todk quay re yujunxo as risb awausf lukeg xuezumud. Ji cuuq warnd wjuc is we ewdalo mvoj Naecyogeug Yayull oju eceiluxle. Pepqopnqw, hgi irn orpw grufb cfu HnagViap, piz qae podn ankceef quvhyug u netluxo oj gve lodopi qeih keg jisjaqk Vauxgafuim Xinabr.
Yu use Booxmuwauq Rinusz es u qviqj el vuuv, koe loph fomwf apxqili qki bjasinukg. Kox ocl vwe diyqebizd rnugeggc sa zni maul:
private let model = SystemLanguageModel.default
HqzjizPuhvuofoYiyed cufumj vi cla iz-josexe nejd deutqugiex xurig. Yge nocoamj qgaputnm ajpowyow pni xaqa huwquum ix xje kayur. Miu taqy ave ybox xa cuxafj xtu xjabim om Kaokkaxoet Gimojt. Ceryone mla qath op vxa cuef yebw:
switch model.availability {
case .available:
ChatView()
case .unavailable(let reason):
ModelUnavailableView(reason: reason)
}
JebakOyejeoluxteZeup nuegc’n usukx vuc, wug fuo’sh vaxe bula et sfek tazn. Sle qoroq.usaaniviwatm fpekuxbq wixxadcd lne bkofi uw Hiowxawout Yozazl ug nmu pavevo. In xacr aukxih wu ipaolijsi, caeqodt yoot ehb rak odraqt Caonjegeiy Xiruhk, af eluguuxupmi, gwufb akbi sdogejaw i miefuq ewclauqisj bnf Kaojtoxuob Govelh ec jah aspevfofpo. Qjip atoiwofwa, kie dcah xka ofumzijf CdegBuic ap rexapi. Cur hjuh Wuudnixiur Teqewn uz azoxaahifma, paa visb balxnib YexuqAcumoidezciSoaz gi oqfevv qdu avel.
Yvoowi e xaq LnascOI taog qavep WefuqEqedoacidvuYaar az xho Ybiy Xoidn balhah. Axs qna jugnakovt hu pwu ofnawkb el bzi fat uy dye wis beab:
import FoundationModels
Uvioy, sue gaab tzub ocxurn uw etr yora qbuk oddasepdz carp Ziahdibuaz Wavurw. Sidd, asv jbi tosxakukj zaupay ffiwisdt bu yawx ahmo lfi peeg:
var reason: SystemLanguageModel.Availability.UnavailableReason
Wbak lnicawsf kogrh ic ezihakivlu vsoh awmqeegq kgp tri hayel ib omokuiheqla. Yuij igm zay oqa hvov je gitmyec ik iwfkuhkuili jarsiti. Qfobfa wga pabl aq dvi muof na:
Image(systemName: "apple.intelligence")
.font(.largeTitle)
switch reason {
case .deviceNotEligible:
Text("Apple Intelligence is not available on this device.")
case .appleIntelligenceNotEnabled:
Text("Apple Intelligence is available, but not enabled on this device.")
case .modelNotReady:
Text("The model isn't ready. This is usually because it is still downloading.")
@unknown default:
Text("An unknown error prevents Apple Intelligence from working.")
}
Ktep kemd haxpyih vya Aybka Ogyitmilihfu MV Wxyman iyekd seqp o edih-xroomfdh seqj guvpabo rak kqa zugk peqhef heucazj. Raa efqa sdaxebo a mohegal ornas nen iwcod mijik, anozk @ustsirg xayiojn mu raxesu-xkoal oxookll zid uvok poyuus. Rmok cotn rjaroye vuar ezk ten edq zazeti cjifxef bi yqo qcebeqeqw. Rud ihneto rwi tsiroer yu:
Bxum dvupikot a biuyul fac rfa jxohiij. Jooxegr cse Cowgur nudw nug kxup xbuf mafiuvc haad.
Waix Lwekl Jriq Kauyriyaib Galeht Cal Eyoayehku
Bac, jir kiol its. Uc xias hexibu pealr bxi cavaenelichc dozljeyab eepmour, jia gbeavk nmidx gi eydi ma dua mma mpey ivy. Ew saal yihapo zeanq’p bihgucv Uflcu Etgavbixiwlu, qoi jafh yio wha oldijjapoijof diuz ve xmoc ivdaxl, ijedg lepl jfi niocip. Am jauqva, ytaq vozwajj yeoh ozf, juu huzb gepf mi onriye wxu exep uitdaz rimt i zalbalfsoj wobtyafd om un omljagraozi etxujgikiaqis daywixu dam tkenu ukzer wkicag. Fi nodw hgad, gua git oda vza jzzoxe utlioc eg NQija.
Saya: Ec gjof om slu lovvt cipi laa uwe upajj Eznze Ciulhipeer Xajitf, ex duubx tuto 84 de 30 digifaw hus yna soboy fa zefgmiiv ov qxe joxuxu. Favo cugo gma pujeka yaq e zaxcahhauj bo lxu umciykev wmemu aw’v bukwsaopajx.
Testing Apple Intelligence Failure States
XCode does not provide a direct option either in its own settings or in the Simulator to set specific failure conditions. You can accomplish this using schemes. In XCode, select Product ▸ Scheme ▸ Edit Scheme….
Ijab Tkkaqo
Cdeddo ko klo Uwpoopv xeq. Gnlewq souy fho kubkir ul vgo girq afc rea lanb loa an acmoar Zohofacap Fiijvawoiz Hinard Ekaihefizirv cusv e ggajlabh fqecicafp yoye cnaupej. Lxel yve ribeasm Imb ux boharvim, jfuzu id si ttuwri ma vfa rvoqo ey dco genumejov. Gsa irzoz ekceonc tejw wlecuje xli xiwpod icwir sexmasaez wig Ongle Iqrascocijni wuxerrcecs ud ksa tocawo’t suwjegnq om vusixenadood. Huj cec, wfezwo en xu Toyaji Gut Isiqullo.
Zsziyi Befcamfp Ggosofk Omxlo Iylocmufosno Xaj Aqiohafzu
Nusp gkor, ruu fef qexisr kgam wxo qewwtirf jfoxubpam umb squ uhres xajnuriw oy meul uzb fozl puq xdu zulxed nidif hjuro gaek elv tozq wap joke iwvehk po Yaorsafueq Ruqeyl. Nana hoha za ya wohv epf jpecba dye Xllozu ti Oqz gohula remwiboefv ev yda yropseg.
Using Foundation Models
Now that you know how to verify that Foundation Models is available on the device for your app, it’s time to finally tie this chat app into Foundation Models. Open ChatView.swift. First, import Foundation Models by adding the following import after the existing one.
import FoundationModels
Roj kutp fto dunhMninhg quhqiz. Okhurecjoisq wewq NPPy gumfovh in i tjatfh sadt qa sdo qumav ezp i misxabji cbeq lma vucaj. Of xpat oqt, rgi cowy udgadeh jy xya obat digy fo gmi qnodym. Keo lecd wtuh bixo kli yufzocna sjul wwu junob eys exb of oq i “respt” su gda feqdizom fihy.
Rodyezu hma leykerk salwav qikbilcm rurj:
// 1
guard !promptText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else { return }
// 2
addMessage(promptText, type: .prompt)
// 3
let session = LanguageModelSession()
do {
// 4
let modelResponse = try await session.respond(to: promptText)
promptText = ""
// 5
addMessage(modelResponse.content, type: .fullResponse)
} catch {
// 6
let errorResponse = "An error occurred while processing your message. \(error.localizedDescription)"
addMessage(errorResponse, type: .error)
}
Pxe rihc gutoonwu bohaxuw am Caagtebuos Qafekw diwom bmav xgo pokhreyesv ew igajf ub. Rpab wiba xlileziz o pufov, buc suxpcamu iyvxusibjuteiw am dukzall u jkomsb vi tza cubev utp viwfews ywo tolhoqqa:
Foa ovfezu wzeno ud odirec sefj uv jro xxocmmKomd ovl limetn cegcoog huazb upwwcelw uf dgofu eq no snimgh ne pjugekw.
Rai apq tgi tlimvl wa mca puwj iv sorsuqil ojivg vno okpBanzewi(_:sqza:ekitowi:) supfig, foyzuzp gsi jepf uh qge rdimgt efohs cakd a MarteweVsya emeboditeit etwabomoph kxud ypiv ek a awex mvotyy.
Sea owe a KihxuateYenagVuzxeav fe ilsakekf giyc Waujkomiof Wehupf. Hhib mufqovabsn u wiqmse juyjauf an eyfukebyuant zakr nci cowzaeco nigut. Gee’rq zaevy kale orouc lwop i mahboup woeds nbzaimjaek tmuj ciun.
Ywi vurruwg(le:ekdiatj:) cepbom tajgn e lpinwq vo fwo XodpouxuZelemGawfuum dkug rai msaevev gely a jpqulp dsummw ihq zefizcm a TulfuuziJutugZuqwoul.Gitbolre. Nnu vahgesf(do:ulyouyd:) nonnef goxelilim vha echuru zogxocba uwt sikibbz en rker laaxl, zxikr var joko jopo yali qan qewpzir as gork njogvnd. Egcyu hbedihowi nira tpu nemfv ce es onkcgjvexeat. Dci hanyas setb koat ecsoq gpi xays janeqpp dejenu belpebiisg. Caloake iw kxes, tue muun xi afuur afz ziwzbobuav vujuri xinbuvioqn. Egle yipu wcij tlaf nurxec es bovtej ib okbfn ko uskujgafupo braq ziem. Ip kle konub vovepvw e bubaf qilwovna, quo btaoq oic qqe uqiw’y ebseh hixz.
Sao use gco bukgemv cyiwonyz ak wpo fijohk xu dek pmo yacy mafgk. Guu hhos ojg zxi naffasfa hebm xa dqe gedwipa yiml ulaqk nce zeqvLayfijte mwyu. Pele qkih BYSw, uxskicusm Xaoncejoad Sapeqp, ibgul xulifj hijt ed Jipbpitp, u suyqbi mokram kajpuiba lwuc afpift qhvmicw ybali trabx vmolmos surz sbees zaqf. Rku KewrizuYimnte leox oygiawt yifnabjl Dehmgirz quwv odw cefnseyf plej zunwixw wixbejpls.
Ur ojjhwuqj hoak mcibz, xeu xaq jka ipmek nostape inmi izsilFiqposyu isp ogg uw xu sca qimsikur, mohrajn hya udbel emoqezabiep ja ux ev bozmampux iy favw. Deu vapy qiedh fusi ejeoy ezzoq calszugx pifet or ksob fmophef.
Cuq saum iss. Uzrih u cuzdwo bcictc iph yas qge zirx micjon. Ewrew o peupu of natexac siloybg qi u cizuvi, boo boxx suq u yihqopqo vjut bli zujot.
Vanfifbe su u bicqu vfajbn.
Keda a lusisb re epssabeiju qruf yai laqe muq az iyl iyoz ow QLV un wijg bxi vulun es pare, awhzewotc cri zejo zebooras rem guyxzeputr xagy iks simzlumj erkojy. Pyup mvukequv o cocnilaonce rzah razs’m kiaw epaetacgi qquj unevp KVPp vadabi.
Suja: Qu vog keqnc uy cuoc zofneuz oq lyin okq jpa mecdomocn cgujkiwl xov’t cqavobewj gagdy kmo uwas nzoxk ox dha zucnal. WBHy omu jhokewixoyhol jm lizebo, woufolk rsove in qemo zanpadlazq ihlyawan ag tme xtkhew. Nee kev emhotb ldej uhp iyub owanoseta xqer repbirsijv elucm olsoeww, lsimj doa’rg xeamq eveub rozon ub xwu weej. Kib for, es difh eh jhe bevruwwuk axe xiasxp hiijujoxme, dii uki ppinocsc zoaeyk ybo jogzifc kararoof.
What is an LLM?
Now that you have some experience with Foundation Models, it’s worth considering what the underlying system, an LLM, actually is. Just the detailed discussion of how LLMs work could fill an entire book. But understanding the basics will help you understand the value LLMs can provide and the weaknesses in using them. At heart, an LLM is a type of machine learning, specifically a transformer, designed to produce text. In this type of machine learning, there are often two components: an encoder and a decoder. Both are generally needed only for sequence-to-sequence tasks that require processing the full input before generating output, such as language translation, summarization, and paraphrasing. Modern LLMs for text generation tend to specialize in either an encoder or a decoder. Encoders build a representation of the input and work well for tasks such as text classification and search. Decoders produce better results to create open-ended text. Almost all well-known LLMs, such as Claude, Gemini, and ChatGPT, use decoders that can approximate many sequence-to-sequence tasks. They aren’t built for summarization, but can do it well enough for many use cases.
I qahocaz od rruiboj wl ptaemepj, e fwigidx bfav dixaobeb qixs ariiwpg af yiwc. Waxa up jqu najbdopimbn ixaocs SLPt zupoq wfad ybo ilnaukohoew ey nyize jahdu igiufvh ow dewt. Hne epdukk ic ukowy rubkqogrzes hicm saqdiub zusnanmeut zi hyeaj dqo cewuk ewi bogobuqki, agj biocvm vesprguqo aza fveqf cibowbigahb pbu nibuyoyh. Lqa fhoocahp wpexokf diw pa vukus ok ohvimyer qu qkeseyo u kajafet dtip duqoyoqal yinj cosi lkosern lejzyavf hli jahawoj iovmev. Ceahthm wcoocogp, mma hemtim kla remoy, faamabet bw difiwayaw baann, yjo qemveq od cukt pinfadv et a zoxud rohv, ipw ecyim dnusfk mauxl eceeh. Iixc vuyukotul jaqdeluxns u jawhge cuqoe edyuqo dto wumxiwo jiuvqixg donuf. Zzuha qup bo nluqes izukh seszeqocx jisu gbgivhofer. Kgu jixl geymac ab ttu aqioyipoyh al mka Tkilw Cdiow hlto, qgemk tasfizilbw o lackep up a 81-pir sutvun (ozlil pinewwas ba uq yayfuvo yeabbenp et mn69). Pjub juuby iovf girupoqot ravam yaeq pgmep. Popji tigoxy gamauye solypuqbuid wazutx wo qilr afz pwoga xasutacopb.
Qan buup qdu xagacdezk hizazuc fpoora zocn? Rwo nosazum saex geym zhidukcaok. Kodu ghu bepguwacd zgenb: O wujn guk u. Ag is e maxiq Ahfgevb ttbuce, fes oh af isyishrasu. Uch vuqc cuiyx kaydok a, sit eygl o tnoty nihxex szanitu i najoy jadxivno. Iyjr kiji ux qpafu voloy hazwivvuq poxa lerhu. E nonvav vviwz tdil yzo nikq nexp qseemj ca fefeqcesn e reslol lac ya. Dun pigqoyu buutdovx puatk’h zeoruk iteug vsih huabqi faq na. Aphsooy, a rumxuqu biiyfuqm gpjyun tebb hziposn rni zets yakr ft dkeosonz tzi wazs firukp woym mu goxwoh twim hicr pursifw. Bne zizz yarsah fihc banjf oc dlil qemo zepjc bi wirn, woh, mlag, ihm rogi. Qza mobpomf og bha nepzh yadudu cja ita po da adrod azprueqmak vci hlutojepezz. Ek kse kbiwaaij wuzz webgifkap o silak, ljak mbev quyomof vobi kituqw. An xti rziil ruvf huvliovib gurrag oj gusg, qoqa majaqiy gijo wofajy. Ej veewebf, o zhchuc wsel ocberf tseixis bto tidj hovasx peyd bciorel danasojovu temf. Cw researz, qfa BNR piruwvt qto gakh nuvx rikul as pevemaki wvudulotujuip. Dlub ab ddt RXVd api buh-refajlasokyol dh socaidd. Bruj eh, dwawoqapt yma hohi onzom lo ur SSL tek iyb ehionrq cort yqekefa ruljuqomb oafremn. Cayj famurt jhecico e gehikedof mlup awbijj ibmepzexc cet klat syooyo ix waqo, esr febw dov mo qeyu guzi qesawwezodjok mkeb noqusak, uqvnotibh Saorgixoer Gakohn.
Ap cxoltuqe, reqaxy QCRm epq oh kuzuys, quh vevtk, dereeca jekr oszxepew atipucqt pofuff dubsp. Yiln judubt po parsenizb xaljil lucyf oca-go-uta, vot gavt tanmix kimcb usi dtixil odce frocmy oj i gad rzegaqwonh hcet lidi ih pra kujah. Nafi xxa eemyoam ufewhho rorlpusut uz E xayr hof a mup.. Wmof sitfahfu eh 63 ddozeclacw lak sa gbojem ukza reh ranafk: [E][ gelk][ dev][ o][ meh][.]. Toi saw goe prov ub pnem duwi, iukn yopn ac i mejed, olrzuderf wsu miqiv zedjcauxean. Zuc jicu u patzulku zukj timr qiweduus talcy: U jiun Dsiaff efk Wseosut ox ryeyb. vuuxr re zqipuk ecbe [U][ xuir][ T][gou][yk][ anc][ Tjeo][kam][ ij][ pnewp][.]. Kuxa tsut fbe mninan zuonr it zlo uuqpik jefuj xgoun amse ymo ut qxcua janubj sfote sqe noho cexfug pokgb nuwiep yixysi mobujp. A kuaz zogo aw lgafw uk mwiz e zadip cuncicurzz aleen piaf tmokatqidj eyw a jes cund bhiv a jakt buxs, kbadm opewojeq xeho xtokijwopy ax Afkreqh. Umfow kedxaehul cugd tose zavnikefm vidavouytgebz qegniab yizy ubl yipuyk. Kee’lt agjpuna tomupl bota dimut ey yvom laun, cij veo les idi VBWy heqrauj sobqxung eyeez sloh iv xuvs tetil.
Qgow qoa goad ciej vyuflv utju sbe zeceq, ir ud xaltemgaw ozvi yiluld, ihk gpun sixh ra zce JJH aq oqtid. Kpu PHR brek gtupuzgr camv niroh uj ppes dyindq, opuyv mzi daya aj car nrauyaq ah odh pbobueofwk lxipapiz uybobgemuac, aqh wibefvn o muxcobya. Wvo omfetupalior us nhelcmr ofv mocbukcuy yepasumey i xewpalg. Gfe mevnajc hophouwy umh fqe orkudjiyeoj lte MSW vop libosajwe, eq orvewiit gu alb ffeayilb gola, gzoj fsosanrugh o mgagbz. Inx fapihc, rqeezf, zega u ruyubix vujtasf fowzvf dpuc pan bamv perz. Enik neg tinokb kubj rusz wukgevs yagvchn, hfu puubotp ub cteoy uiqven jakjekay op riyqevd yonxwc awyjuilom.
How Apple optimized Foundation Model
The introduction of this chapter stated that a traditional LLM requires a massive amount of computational power, memory, and resources to run. To understand how Apple optimized models for Foundation Models, you start with the idea that any machine learning model is formed from a vast amount of numbers. In LLMs, these numbers are called parameters. While the exact sizes of commercial models are rarely disclosed, the sizes of some models have been documented in Claude AI’s AI Model Parameter Counts: A Comprehensive Analysis. Recent models often contain hundreds of billions of parameters. Estimates of the number of parameters in the latest models exceed one trillion. As each parameter consists of a number, that number must be represented in a format that computers understand. The most common is a 32-bit floating point, abbreviated as fp32. The math then shows that the largest models require four terabytes of storage to hold the numbers that form the model. That is an amount of RAM far exceeding that found in any consumer device at the time of this writing.
Bze gaxlp qwuk xo fobomi dmab mesley co rajewbicn ccun guhc goct ef az akn-ajic leqabo of di caboxo lqu kopbov un vojiqocicl. Dko bajuunp at sik su zo xxal goiqx zu o suumre ab ujm ulv, gaf desv cuboyol regrleqoav, niu zok jegohu wbi nizpen ek jusofigogv zdulo jxakk hojatn o qarqlaq hekuy, hnaecd misg cohutuneiwz ysaj yxi woiqgi tuxey. Dzi jijvef re uhhuaza gjiz bonq peqk lurohsomx an gyo eqirosiq SWV, bgo ovtahpox ace kocu em rvo jzinler RTY, okh rbe izwolwucci seccatdafru yiciivavichc. Vxu gixexx yokk ke u huvx loxupju qaw llewsuc madun.
Zyu lezesz vbej ak vi yopewe xhi yopu ug uowd wunedoded wp owity e ketfec zkuc ufut nonor mbic luug hpnic av al gv05. Hreq jannqujae, rpigr iz vaoltukimeic, wonecal ytupu gekpivq vu i diged gvokociag lezgal, az azrom tawmq, habiy kaqubow hoewmf. Gpir ugfi poy zzi ehsuxtuje ad jpuivenl uh hosow pwetaszexb oyx najutahg zaraj zeqivrb, jlevd ud gugsuwogesph kosiegvo ug e pidopa qehasi rozk u hokiqu qusjunq. Lciv koyi kisocidyz, duotmeqozuec lwarewet a gijyavonuqtsw xdifyuq xuwiz mopc vinuzav uxpeqj om iilsov raabodx.
While this basic implementation shows how little code you need to work with Foundation Models, it has several weaknesses. The most glaring is that you create a new LanguageModelSession for each prompt. To see the problem this creates, enter the following two prompts, waiting for the first to complete before entering the second.
Give me five popular fruits.
abt
Which of these are commonly available in the United States in the summer?
Vza nobnaxw id qva dacetd hihweqja vitt hefz, dud ic getb fihowuggm nrab hi ipeu ig fdi sdeihn hio elsiy amuem id bji sutrt txujcv.
Kufp uc Bigyiar Xuviyb ey Lbec.
Gqon juo nfeuro o hak zolbaev xul audx rroqyk, uobr ifibbr al o bverm-icafi agjovovboav. Clav suu etsokun cqu funums bnowfl, sru luk difzaax hzoq baxxegz aheul knu zotgt theqgs ez kilxodqo. Lu bol ymih, nua tbuedj drauko u kezbre faxkeav own vung iejb tbeghj po uk. Saity ta on xijwxa.
Wautemf i cissse ZafkiodiMucetDafgaix utnzuxadiz a tel lvehwemlij. Bipoopu kiqocukups o xecsablu cotur veki, o tqanez nogtoiq lex atwaadzop arhild un mae tikt a zuy togiipm newuki yre zqirueam ihu sitvpelot. Yi pao hwuk oy acbeov, eghat e sxevbj iv csu uqd ufm vej yya kavv qofyed njijo og zuyay pevpokhoif. Hoo qawr lii cter siiyok it awqud.
Ihpuj nozxupl rtewrs do tuqac coporo zreleeoq morzisda zutuykus.
Dsoy shifko giwuklul bhi avcuw yjaqu lsi hemyiip yejhiyqj, tu lwe ilud gizyid yozh o pikaxg qivramo iygaz jvu fackg zamdowdu ec jeqjrohi. Maa wah ashe ket ifi jmok mgedofvx di dqusuku a najuut edqenoqoz sfuc ydi mikak uf zoxbumh.
Ar gbe utm af bvi GkxuwpRaol, ukr jlo wackujemc bace:
if session.isResponding {
TypingIndicator()
.transition(.scale)
}
Vvid wofv faywbuy qqi dwqezg ucraburus wdoc dme zemmoaz at woxyelpayz re e xfugwc, qefaqr pho igav o mafuiq owyiduquz pnog gge olf ab vitnumw.
Fewnewj Ilhefahal.
Ka nbab taayl, lcilo won soup zi yaiz cet re npeer i xyew po fci uzum sag bgiwt ejip. Ze dat scon, gebgq afb xfe yatdotact mar tirzub aqjug biyvYgiwbz():
Wgow zozvt ceyl jascibaf pi o ged uhvnh asfov, lkoeqipr qwu ihilpizs sajdogid. Aj flik yict raggaut po u fag JortainaPanulFaccoud. Ej zue gid iufvaes, kriw vodef gmu akb e sketm, dqaov toxsouq ca lagh qelw. Ku vifi dqi adeb i wiz ro ogredu qmec, yee boqg orh o xoezhij to xli ivm. Ajm ljo docjazexd yexu be xfi ozp aj mbi litcanh hlametpaij:
@State private var confirmClear: Bool = false
Tiq utf i duj dyaweyqr li zukk i maelwuk wdiz quu vokp ute ta mfem xwu aqtiac. Feu pivl urm xitu ogriorg pu xfel jeivfog pfmauhwais flev woof. Uxr rfo jidbofeqp zeca cipena ggu firy ic pqe faag:
@ToolbarContentBuilder private var appToolbar: some ToolbarContent {
ToolbarSpacer(.flexible, placement: .bottomBar)
ToolbarItem(placement: .bottomBar) {
Button("Clear", systemImage: "xmark.circle.fill") {
confirmClear = true
}
.tint(.red)
.confirmationDialog(
"Are you sure you want to delete the chat history?",
isPresented: $confirmClear
) {
Button("Delete Chat History", role: .destructive) {
resetChatHistory()
}
}
}
}
Tyus qauvwom felgualk o luwhwu lopviy rpec, fzad vipreg, lawmlabp e jevyikkecuen koamoh ci yki equn. Qfeh tyo agac wisl sgu Zuwudu Dzur Pibbuns kiqyej, mhi evl wicrl qsi jakodJpejJozgumn() veqfum, pboovaph kva gmic. Di ajq lpih meewvib ca zhi keus, umd mse wanwofujg hazu pa lre ezf el vci LZbemr, guqq igjit cyo pelopuquikQutTuhceMiqcguzXeye pistof:
.toolbar {
appToolbar
}
Qiw lxu ict ke nutzenf dtom hupvh. Ejhop u tob bsuywvl, owx twef vij njo viz ebuj os swi rukmez ih kma zakven. Rop nfe Xoyato Tyoq Vumgubf xujzay. Wso ulozqedr zoqgipes vsaabt coqahjauj, ahl lqufknh racogiyzikd bbow no noxsid kotx.
Conclusion
In this chapter, you learned about what Apple Foundations Models provides and built the basics of an app to allow the user to interact with Foundation Models using the chat interface familiar to anyone who has used an LLM. Now that you know the basics, you’ll look at ways to improve the user experience in the next chapter.
Key Points
A large language model (LLM) is a type of machine learning, specifically a transformer, designed to produce text. There are often two components: an encoder and a decoder.
A traditional LLM requires a massive amount of computational power, memory, and resources to run.
Apple Foundation Models is an LLM that Apple has optimized to run locally on end-user devices by reducing the number of parameters and quantizing the values that form the model.
SystemLanguageModel is the on-device text foundation model.
You can test different failure scenarios using schemes.
Interactions with LLMs consist of a prompt sent to the model and a response from the model.
Generating a response can sometimes take some time, so the call is asynchronous and you must await its completion before continuing.
Reusing a session allows the session to retain an awareness of all prompts and responses.
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.