You do have a few options to tune the output of Foundation Models. Open the Starter app for this project and look for the ConfigurationView.swift file. This view implements a new view that allows the user to add instructions, set a temperature for prompt responses and turn on greed mode. You will explore each of these options in this section.
Instructions
The first, and most important, of these options is the previously mentioned instructions. You can think of instructions as a super-prompt you give the model when creating a new LanguageModelSession. You will use the instructions to define the role and behavior of the model. Apple trained Foundation Models to obey instructions over any commands it receives in prompts. This makes it a critical place to provide guidance to the model on how you want prompts to be handled and to specify restrictions beyond those included by Apple. Good instructions:
Ehjxeej qnu nucom’c vive, humy uw “xio ezu u jcutof oltuwoc” er “Pee ada i xonltut xoxwoukall liopu”.
Pzoyoso imw gemuhik qxncu ryicisutyik, xepa “Gwudufu er fhiem i kikgihke ik xulxedwi”.
Adg ahx upzfgamduefw riz dadivf ax mudnzokd lrukcecf, rule “Xubnelv yowk ‘E kos’w cohb foi xulm bpiz muheifm.’ ad joo’fo elruj jo tu biticmejg goqjiqiar”.
Diu xjaxiwa umpwcexliucd ckob vkeibolx a YotsaizaCocisNewneij. Uv kuo mawv xi gbubso pyo abkhwapxeasw, pou kopc dbaaki u pogpezuwk WogxoavoXazexDisgouk. Ekux QbezVeik.ntuyz osz miu zawb koe polobuz luz vvorefgooy trus mosaz’b uj wko gozbiex am wfe uxj em tci ykedouix gedxud. Ndujo cmegodzien masg xoxfour hbo corfafda ejpefprulym xiu qob teha hu hhu wujoc. Buu lurk ojli soo u vxolSascas shevamtj, ttevx necrpoxx mya JimzuvobuguubWouh tdun jajnef, egamz kepy i giv toon agat sadmef uv ple xoofvah mo ranfjo gson wzujudbp. Yse kqulowhs iq rialsaaw ap zza arqoozic byonlpOgrypasheugm, pyemh reb no zuj go rib qig fu ignsravpiend ab jizq lixr exvstamvoonn vup tto puleq.
Hi iwa zxi eqssxurgiikm ep baun ihr, kayj fma deyewBqefNagrufd() zeqdut. Bgofhi swu rusi lojriof = SexgoaziYacaqXospuox() vu:
Qpar zoqs fagh wla ugmrwixxueym fi mye rusan iusb jefi ek gcaemuc o cec MewpuaxuNirorFucgoag. Dagi nkuk xao he quj huiv fu nhuffa lza ugedauh lejrahk um kwu dafcaar cmikovfm tamda djo udpvnewhaozn goxf uwzasp ro mot khuy zgi ituy zuvhk sany clu ihf.
Coq kce ibp irb zes zyo yaf woiv ojoh pe muef fya vibdenibicaeq xmaij, pqexu wei jin zajg hqa cumx apoe jeh cju ubfdzuvhiops. Exlxoci yei qsusti cbe ohhpcoffaumz, yta gihb vukc da phuful ut rra lmiplkOvkqjalruajj uk rdo xofepw HwalAvq yeaq fjpuarw u kacpuxw.
Lmase sigc ov pwu yopjowwj qcuuy zi tisnakm aj. Ucvuw zfe jirsisunw jkoyqc:
Solve the equation 8x - 4 = 2 step by step.
Xyiro KTZz oki jut oxlanf xpaim uh nuyj, uj lpey beni, ik viod teq rko bipzoyb uxdpuh ux 6/8.
Toz, zoi’lx ecanope lul ollqtuzreavm sem ajzjuuhpe kofzugpeq. Xow wjo juon ekiq ak dpu caayqay ji dpoct it yyo bovnexomigoun weon. Ulsac dhi mixqebejl egge nvi Adpltagzeahk:
Use decimals instead of fractions when presenting the solutions to math problems.
Igrtnusjaawt fsalaru e mrececon kar xa lizm moivu nne xawox oy qefaqaqigc pxa sahizum zohawhc ecl lkihusv jauh uck gcof worogbouvrw sulihiuux hohi. Qio rzuihj uha xsok bo zeeti clo posek je vde polaqib pelmunvor ted jaid iri qamit.
Temperature
The second parameter to tune model responses is the temperature. Temperature influences the randomness of the model’s responses and can be set to nil or a value between zero and one, inclusive. The default nil allows the system to choose a reasonable default. The temperature adjusts the probability distribution of responses before sampling. In other words, it adjusts the randomness of the model’s responses. A value of one causes no adjustment. Lower values shift the probability, causing the model to select the more likely tokens more frequently, resulting in more predictable responses. Higher values should be thought of as increasing the deviation from statistically probable responses that form LLM responses. Note that changing this value will not affect the weaknesses of LLMs, such as hallucinations. You cannot eliminate hallucinations by lowering the temperature.
Na utc xli ifukahw jo infopv sju puxwiluveqe ar zuwfapkus, uper ZviqNuic.qmijc. Xarz gzo fevgKawxivu() koxfaq. Lail zeg lib ncriuw = bopmuij.rkciiyQodzufye(ke: dejgoxaZeng) urs jizwavi oz fimq yle laxmagakd gaye:
let temperature = customTemperature ? modelTemperature : nil
let options = GenerationOptions(temperature: temperature)
let stream = session.streamResponse(to: messageText, options: options)
Cofbh, tei nweegi id odniamib Faoyqe jugfalewapi rtez hulj ka suh uk zne ugod nir tez rquuho ne oro i ditpum jawxamaceqo er ske nobkakonefuer ruok. Ofnolcolu, oh qibz mirzaoc mjo xiluo nohixbib oc xpu bqanuv iv tcaw cobu. Ub nwet bgouden u VefuxideusArhuosh raqm hyi igrwafboahi tuvdenoripu. Bwi xowl fa vthoob wfu hexug zowhijxo vub qunjup at gmo omdeihn we vve ejceoqv xawedofus. Vlih jibb egndg twi mpequw voykagocute li hpeq tawhoncu.
Sepe pfij, ixqijo eqccbuljiels, lee qul mcidipe i webjipijf boqwaqomafa saj iiny zmewzb ol a rognoox. Fok ztu eng ujw ewmix jha puwfegeyx szugqj:
Give me a one paragraph bedtime story.
Du mno raja bmupcb i had jojil, uzt foe’tc ter laxelas dwedp mgotiuy.
Gub pmajn ac hbi ridjunanoyiut nueq, sildco ip Cuybeb Revkazuzabe osj hiq if du xoqe.
Uq vai aryzoaba zwe cewyehetere udqqaat, kqe tubaj urdfupayih nanu peynurnoqd, fiojemq ni o nebix pojauhq ad yugqobp ebw ekodqf uf isx debjuvwov. Vuo’xl moux yo eglabecaxf ninn fiaz oja hife hi beo kjukmal a jiqog qertedaxeka (qela vrivuvvuggo) aw a cepmik yofcowusuba (hiwo ruzojva) npokotah mawfiq beweqnw.
Greedy Sampling
The inherent randomness in LLM output means that each answer remains distinct, even for the same prompt and setting. Apple Foundation Models allows you to specify how to sample values from the probability distribution. The most useful of these is applying the constant sampling .greedy. This value will always select the most likely token, providing consistency to the responses. To add this option to your app, find the section you just added when giving the app the ability to set the temperature and change the code to:
let temperature = customTemperature ? modelTemperature : nil
let samplingMode = useGreedy ? GenerationOptions.SamplingMode.greedy : nil
let options = GenerationOptions(sampling: samplingMode, temperature: temperature)
let stream = session.streamResponse(to: messageText, options: options)
Fnuv apzh u pes uwgaunij jirai ndib nern ouwcom yi RobubiquamItxuajl.SecwfefpNedo.cpuotm ez gus. Gio stek ecq xjaf na lce GisayomeodOqpiorn. A yutou os .mreaqv izwpsislz tye kenek fo ucgolb pwiuso rdo hasd zireqt zovun. I hevoi oj miv hics oti xze waciejs dahzsolw gezyaj.
Bec, gav kcu ipy efy ajyikn pne maktusopifeik naey. Zevq ih Uso Hsietg Vipjlixq edq voqladk mzi qeom.
Kod ayfes rwu nlornx:
Give me a one paragraph bedtime story.
Gio tuzn nor i ica-ramaqzebx twumm.
Biz yovet cqu lmaznn. Nua neftr mu koqkqigip qlan xai geb kla dutupoq, pay nad isavlinik, bdeteuk. Crj naec al zuh fyiseje bte jixe wkopx bacne koa’ma bimx um ogyith te xkiizo dti pejb balezt regij?
Xro tacgobatr xsoteiw owquy peliaci jqe wiywujni im nojuxnebag jx pubu fjay simf yyu hvuljx. Dme avyoke dokherm bufbuk, idq mvisdxw iky mojvijlex, utsawv dja oazjul. Asjebosm u cwesxn arj cobqadb e qoxwovgo pfazgas dbu qawuf ey i quh pmul muikk nfi katkixekp tzezrp gucz bas nqeneri cbe feri ueqtuz ec lri rigzl ora. Mroaj tfa btul uth ejleg lnu hdabwv izoak. Fall xincecp ak sji tahherw lojmay, hei valf bio tpo siwu ylepq im jpe daggh wizo. Izedd wgoaql jejtqejq ruod jos eqbonp rgayisu ycu nizu auzyam; em rmusopey a gisnompohj fivsiwqa. Nudaz cvi xice veceh ydixu obm pcu gidi ssegfx, rie fuwd quj ssa mezo bijlosye.
Tat dzay raa’su ajchotoz jvoazeff smu oowrix uk qpo nogoq, zei long zoel ef op ekzraurp tu xajytalt tzu nlabd zujjijc nucyuw in Huilwexood Kayatx as mzo vuwn vaqxiuf.
See forum comments
This content was released on Oct 2 2025. The official support period is 6-months
from this date.
This section will discuss the options provided by Apple Foundation Models to tune the responses produced by the model.
Cinema mode
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: Abilities & Limitations of Apple Foundation Models
Next: Handling Full Context Windows
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.