{"id":281,"date":"2026-11-01T13:04:09","date_gmt":"2026-11-01T13:04:09","guid":{"rendered":"https:\/\/devdojo.co.in\/?p=281"},"modified":"2026-11-01T13:04:09","modified_gmt":"2026-11-01T13:04:09","slug":"genai-series-part-6-run-llms-locally-ollama","status":"publish","type":"post","link":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/01\/genai-series-part-6-run-llms-locally-ollama\/","title":{"rendered":"Generative AI Part 6: How to Run LLMs Locally with Ollama"},"content":{"rendered":"\n<div class=\"dd-post\">\n<style>\n.single article:has(.dd-hero) .entry-media{display:none}\n.dd-post{--navy:#0b1020;--blue:#3178c6;--violet:#7c5cff;--ink:#1f2433;--muted:#5b6275;--line:#e3e6ef;font-size:17px;line-height:1.75;color:var(--ink)}\n.dd-post h2{margin:2.2em 0 .6em;font-size:1.6em;line-height:1.3;scroll-margin-top:90px}\n.dd-post h3{margin:1.6em 0 .5em;font-size:1.22em;scroll-margin-top:90px}\n.dd-post a{color:var(--blue);text-decoration:underline;text-underline-offset:3px}\n.dd-post pre{background:#0f1430;color:#e6e9f5;padding:18px 20px;border-radius:12px;overflow-x:auto;line-height:1.6;border:1px solid #232a52;margin:1.2em 0;font-size:14.5px !important}\n.dd-post pre code{font-size:1em !important;background:none;color:inherit;padding:0;font-family:\"JetBrains Mono\",\"Fira Code\",Consolas,Menlo,monospace;white-space:pre}\n.dd-post :not(pre)>code{background:#eef1fb;color:#2b3a8f;padding:2px 6px;border-radius:5px;font-size:.9em}\n.dd-post .dd-file{display:inline-block;background:#151b3b;color:#c9d1ff;font:600 13px\/1 \"JetBrains Mono\",Consolas,monospace;padding:7px 12px;border-radius:8px 8px 0 0;margin:1em 0 -1.2em;position:relative}\n.dd-post .dd-hero{margin:0 0 1.6em;border-radius:16px;overflow:hidden;box-shadow:0 10px 30px rgba(11,16,32,.25)}\n.dd-post .dd-hero svg{display:block;width:100%;height:auto}\n.dd-post .dd-hero .node{transition:transform .25s,filter .25s;transform-box:fill-box;transform-origin:center;cursor:pointer}\n.dd-post .dd-hero .node:hover{transform:scale(1.08);filter:drop-shadow(0 0 10px #7c5cff)}\n.dd-post .dd-series{display:inline-flex;align-items:center;gap:8px;background:#151b3b;color:#dfe3ff;border-radius:999px;padding:6px 14px;font-size:.88em;font-weight:600;margin:0 0 .8em}\n.dd-post .dd-series span{background:var(--violet);color:#fff;border-radius:999px;padding:2px 10px}\n.dd-post .dd-prereq{font-size:.96em;color:var(--muted);border-left:3px solid var(--line);padding-left:12px;margin:.6em 0 1.2em}\n.dd-post .dd-summary{background:linear-gradient(135deg,#eef3ff,#f4efff);border:1px solid #d6dcf5;border-left:5px solid var(--violet);border-radius:12px;padding:18px 22px;margin:1.4em 0}\n.dd-post .dd-summary strong.lbl{display:block;font-size:1.05em;margin-bottom:6px;color:#3a2fa0}\n.dd-post .dd-summary ul{margin:.3em 0 0 1.1em}\n.dd-post .dd-toc{background:#f8f9fc;border:1px solid var(--line);border-radius:12px;padding:16px 22px;margin:1.4em 0}\n.dd-post .dd-toc ol{margin:.4em 0 0 1.2em;columns:2;column-gap:28px}\n.dd-post .dd-toc li{break-inside:avoid;margin:.15em 0}\n@media(max-width:640px){.dd-post .dd-toc ol{columns:1}}\n.dd-post .dd-tip,.dd-post .dd-note,.dd-post .dd-warn{border-radius:10px;padding:14px 18px;margin:1.3em 0}\n.dd-post .dd-tip{background:#ecfbf3;border-left:4px solid #1f9d61}\n.dd-post .dd-note{background:#eef4ff;border-left:4px solid var(--blue)}\n.dd-post .dd-warn{background:#fff6e8;border-left:4px solid #e08a00}\n.dd-post .dd-cards{display:grid;grid-template-columns:repeat(auto-fit,minmax(210px,1fr));gap:14px;margin:1.3em 0}\n.dd-post .dd-card{border:1px solid var(--line);border-radius:12px;padding:14px 16px;background:#fff;box-shadow:0 2px 8px rgba(20,30,70,.05)}\n.dd-post .dd-card b{display:block;color:#3a2fa0;margin-bottom:4px}\n.dd-post table{width:100%;border-collapse:collapse;margin:1.3em 0;font-size:.95em}\n.dd-post th,.dd-post td{border:1px solid var(--line);padding:10px 12px;text-align:left;vertical-align:top}\n.dd-post th{background:#151b3b;color:#fff}\n.dd-post tr:nth-child(even) td{background:#f8f9fc}\n.dd-post .dd-tablewrap{overflow-x:auto}\n.dd-post figure{margin:1.6em 0;text-align:center}\n.dd-post figure svg{width:100%;height:auto;border-radius:12px}\n.dd-post figcaption{font-size:.9em;color:var(--muted);margin-top:8px}\n.dd-post details{border:1px solid var(--line);border-radius:10px;padding:12px 16px;margin:.7em 0;background:#fff}\n.dd-post details summary{cursor:pointer;font-weight:600}\n.dd-post details[open] summary{margin-bottom:8px;color:#3a2fa0}\n.dd-post .dd-roadmap{border:2px solid #d6dcf5;background:#fbfbff}\n.dd-post .dd-roadmap h4{margin:1em 0 .3em;color:#151b3b;font-size:1em;text-transform:uppercase;letter-spacing:.04em}\n.dd-post .dd-roadmap ol{margin:.2em 0 .6em 1.4em;padding:0}\n.dd-post .dd-roadmap li{margin:.2em 0}\n.dd-post .dd-roadmap .here{background:var(--violet);color:#fff;border-radius:999px;padding:1px 9px;font-size:.8em;font-weight:700;margin-left:6px}\n.dd-post .dd-roadmap .soon{color:#8a90a6;font-size:.82em;margin-left:6px}\n.dd-post .dd-tabs{border:1px solid var(--line);border-radius:12px;padding:6px 16px 16px;margin:1.4em 0;background:#fbfbfe}\n.dd-post .dd-tabs>input{position:absolute;opacity:0;pointer-events:none}\n.dd-post .dd-tabs .labels label{display:inline-block;padding:8px 16px;margin:10px 6px 0 0;border-radius:999px;border:1px solid #cfd5ea;cursor:pointer;font-weight:600;font-size:.95em;background:#fff;transition:background .2s}\n.dd-post .dd-tabs .labels label:hover{border-color:var(--violet)}\n.dd-post .dd-tabs .panel{display:none;margin-top:12px}\n.dd-post .dd-tabs #ti1:checked~.labels label[for=ti1],.dd-post .dd-tabs #ti2:checked~.labels label[for=ti2],.dd-post .dd-tabs #ti3:checked~.labels label[for=ti3],.dd-post .dd-tabs #ti4:checked~.labels label[for=ti4]{background:var(--violet);color:#fff;border-color:var(--violet)}\n.dd-post .dd-tabs #ti1:checked~.p1,.dd-post .dd-tabs #ti2:checked~.p2,.dd-post .dd-tabs #ti3:checked~.p3,.dd-post .dd-tabs #ti4:checked~.p4{display:block}\n.dd-post .dd-tabs #ti1:focus-visible~.labels label[for=ti1],.dd-post .dd-tabs #ti2:focus-visible~.labels label[for=ti2],.dd-post .dd-tabs #ti3:focus-visible~.labels label[for=ti3],.dd-post .dd-tabs #ti4:focus-visible~.labels label[for=ti4]{outline:2px solid var(--blue);outline-offset:2px}\n.dd-post .dd-cta{background:linear-gradient(135deg,#0b1020,#151b3b);color:#e8ebff;border-radius:16px;padding:24px 26px;margin:2em 0;text-align:center}\n.dd-post .dd-cta h3{color:#fff;margin-top:0}\n.dd-post .dd-cta a{color:#a99bff}\n.dd-post .dd-vsc{position:relative;margin:1.5em 0;border-radius:12px;overflow:hidden;background:#1e1e1e;border:1px solid #2b2b2b;box-shadow:0 14px 34px rgba(0,0,0,.28);font-family:\"Segoe UI\",system-ui,sans-serif}\n.dd-post .dd-vsc>input{position:absolute;opacity:0;pointer-events:none}\n.dd-post .dd-vsc-bar{display:flex;align-items:center;gap:12px;background:#323233;color:#cccccc;font-size:12.5px;padding:8px 12px}\n.dd-post .dd-dots{display:inline-flex;gap:7px}.dd-post .dd-dots i{width:12px;height:12px;border-radius:50%;background:#ff5f57;display:block}.dd-post .dd-dots i:nth-child(2){background:#febc2e}.dd-post .dd-dots i:nth-child(3){background:#28c840}\n.dd-post .dd-vsc-title{flex:1;text-align:center;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;padding-right:50px;opacity:.85}\n.dd-post .dd-vsc-tabs{display:flex;align-items:stretch;background:#252526;border-bottom:1px solid #1e1e1e;overflow-x:auto}\n.dd-post .dd-vsc-tabs label{display:flex;align-items:center;gap:7px;padding:9px 16px;color:#969696;font-size:13px;cursor:pointer;background:#2d2d2d;border-right:1px solid #252526;border-top:1px solid transparent;white-space:nowrap;margin:0;transition:color .15s}\n.dd-post .dd-vsc-tabs label:hover{color:#e0e0e0}\n.dd-post .dd-vsc-tabs .ic{font:700 9.5px\/1 Consolas,monospace;padding:3px 4px;border-radius:3px;color:#1e1e1e}\n.dd-post .ic.py{background:#ffd43b}.dd-post .ic.js{background:#f1e05a}.dd-post .ic.sh{background:#89e051}\n.dd-post .dd-vsc-tabs label.run{margin-left:auto;background:transparent;border:0;color:#89d185;font-weight:600;display:none}\n.dd-post .dd-vsc-tabs label.run:hover{color:#b5f0b0;background:#2a2d2e}\n.dd-post .dd-vsc-pane{display:none}\n.dd-post .dd-vsc>.f1:checked~.dd-vsc-tabs .t1,.dd-post .dd-vsc>.f2:checked~.dd-vsc-tabs .t2,.dd-post .dd-vsc>.f3:checked~.dd-vsc-tabs .t3{background:#1e1e1e;color:#ffffff;border-top-color:#3178c6}\n.dd-post .dd-vsc>.f1:checked~.p1,.dd-post .dd-vsc>.f2:checked~.p2,.dd-post .dd-vsc>.f3:checked~.p3{display:block}\n.dd-post .dd-vsc>.f1:checked~.dd-vsc-tabs .run1,.dd-post .dd-vsc>.f2:checked~.dd-vsc-tabs .run2,.dd-post .dd-vsc>.f3:checked~.dd-vsc-tabs .run3{display:flex}\n.dd-post .dd-vsc>.f1:focus-visible~.dd-vsc-tabs .t1,.dd-post .dd-vsc>.f2:focus-visible~.dd-vsc-tabs .t2,.dd-post .dd-vsc>.f3:focus-visible~.dd-vsc-tabs .t3,.dd-post .dd-vsc>input[type=checkbox]:focus-visible~.dd-vsc-tabs .run{outline:2px solid #3178c6;outline-offset:-2px}\n.dd-post .dd-vsc-crumbs{background:#1e1e1e;color:#a9a9a9;font-size:12px;padding:5px 16px 2px}\n.dd-post .dd-vsc pre.dd-vsc-code{background:#1e1e1e;color:#d4d4d4;border:0;border-radius:0;margin:0;padding:8px 0 14px;counter-reset:ln;line-height:1.62;overflow-x:auto}\n.dd-post .dd-vsc pre code{font-family:Consolas,\"JetBrains Mono\",\"Fira Code\",Menlo,monospace;color:inherit;background:none;white-space:pre}\n.dd-post .dd-vsc .l{display:inline-block;min-width:100%;padding-right:18px;box-sizing:border-box}\n.dd-post .dd-vsc .l::before{counter-increment:ln;content:counter(ln);display:inline-block;width:3.2em;padding-right:1.4em;text-align:right;color:#6e7681;user-select:none;-webkit-user-select:none}\n.dd-post .dd-vsc .l:hover{background:#2a2d2e}.dd-post .dd-vsc .l:hover::before{color:#c6c6c6}\n.dd-post .dd-vsc .k,.dd-post .dd-vsc .kn{color:#c586c0}.dd-post .dd-vsc .kc{color:#569cd6}.dd-post .dd-vsc .s{color:#ce9178}.dd-post .dd-vsc .c{color:#6a9955}.dd-post .dd-vsc .m{color:#b5cea8}.dd-post .dd-vsc .nf{color:#dcdcaa}.dd-post .dd-vsc .nc{color:#4ec9b0}.dd-post .dd-vsc .nb{color:#4ec9b0}.dd-post .dd-vsc .nd{color:#dcdcaa}.dd-post .dd-vsc .n{color:#9cdcfe}.dd-post .dd-vsc .o{color:#d4d4d4}.dd-post .dd-vsc .gp{color:#89d185;user-select:none;-webkit-user-select:none}\n.dd-post .dd-vsc-term{display:none;border-top:1px solid #3c3c3c;background:#181818}\n.dd-post .dd-vsc>.r1:checked~.p1 .dd-vsc-term,.dd-post .dd-vsc>.r2:checked~.p2 .dd-vsc-term,.dd-post .dd-vsc>.r3:checked~.p3 .dd-vsc-term{display:block;animation:ddterm .35s ease-out}\n@keyframes ddterm{from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:none}}\n.dd-post .dd-term-head{display:flex;gap:18px;align-items:center;font-size:11px;letter-spacing:.06em;color:#8b8b8b;padding:7px 16px 0}\n.dd-post .dd-term-head span:first-child{color:#e7e7e7;border-bottom:1px solid #e7e7e7;padding-bottom:4px}\n.dd-post .dd-term-head .dd-term-note{margin-left:auto;letter-spacing:0;text-transform:none;color:#d7ba7d;border:0;font-size:11.5px}\n.dd-post .dd-vsc-term pre{background:#181818;color:#cccccc;border:0;margin:0;padding:10px 16px 14px;border-radius:0}\n.dd-post .dd-vsc-status{display:flex;flex-wrap:wrap;gap:4px 14px;background:#007acc;color:#fff;font-size:11.5px;padding:4px 12px}\n.dd-post .dd-vsc-status .sp{flex:1}\n.dd-post .dd-vsc-termonly pre.dd-vsc-code{background:#181818;padding:12px 16px}\n@media(max-width:640px){.dd-post .dd-vsc-title{padding-right:0;text-align:left}.dd-post .dd-vsc-status span:nth-child(n+4){display:none}.dd-post .dd-vsc .l::before{width:2.2em;padding-right:1em}}\n.dd-post .dd-vsc-hint{font-size:.93em;color:var(--muted);margin-top:-.6em}\n.dd-post .dd-next{border:1px dashed var(--violet);border-radius:12px;padding:16px 20px;margin:1.6em 0;background:#f7f4ff}\n<\/style>\n<style>\n.dd-post .ic.mf{background:#c5a3ff}\n.dd-post .dd-ram{display:grid;grid-template-columns:repeat(auto-fit,minmax(170px,1fr));gap:10px;margin:.6em 0}\n.dd-post .dd-ram div{background:#151b3b;color:#e8ebff;border-radius:10px;padding:10px 12px;font-size:.92em}\n.dd-post .dd-ram b{display:block;color:#a99bff;font-size:.82em;text-transform:uppercase;letter-spacing:.05em}\n.dd-post .dd-ram code{background:#262f63 !important;color:#fff !important}\n<\/style>\n\n<div class=\"dd-hero\">\n<svg viewBox=\"0 0 1200 520\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" role=\"img\" aria-label=\"Generative AI series Part 6 banner: the terminal, Python and Node.js send prompts to Ollama on localhost port 11434, which runs open models like Llama, Gemma and Qwen on your own computer\">\n<defs>\n<linearGradient id=\"ddbg\" x1=\"0\" y1=\"0\" x2=\"1\" y2=\"1\"><stop offset=\"0\" stop-color=\"#0b1020\"\/><stop offset=\"1\" stop-color=\"#151b3b\"\/><\/linearGradient>\n<linearGradient id=\"ddac\" x1=\"0\" y1=\"0\" x2=\"1\" y2=\"0\"><stop offset=\"0\" stop-color=\"#3178c6\"\/><stop offset=\"1\" stop-color=\"#7c5cff\"\/><\/linearGradient>\n<radialGradient id=\"ddglow\" cx=\".5\" cy=\".5\" r=\".5\"><stop offset=\"0\" stop-color=\"#7c5cff\" stop-opacity=\".45\"\/><stop offset=\"1\" stop-color=\"#7c5cff\" stop-opacity=\"0\"\/><\/radialGradient>\n<\/defs>\n<rect x=\"0\" y=\"-60\" width=\"1200\" height=\"640\" fill=\"url(#ddbg)\"\/>\n<circle cx=\"1000\" cy=\"110\" r=\"250\" fill=\"url(#ddglow)\"\/>\n<g opacity=\".12\" stroke=\"#9fb2ff\"><path d=\"M0 100H1200M0 200H1200M0 300H1200M0 400H1200M200 0V520M400 0V520M600 0V520M800 0V520M1000 0V520\"\/><\/g>\n<rect x=\"60\" y=\"46\" width=\"128\" height=\"38\" rx=\"19\" fill=\"url(#ddac)\"\/>\n<text x=\"124\" y=\"71\" text-anchor=\"middle\" font-family=\"Segoe UI,Arial,sans-serif\" font-size=\"18\" font-weight=\"700\" fill=\"#fff\">PART 6<\/text>\n<text x=\"204\" y=\"71\" font-family=\"Segoe UI,Arial,sans-serif\" font-size=\"18\" fill=\"#aab4e8\">Generative AI Series \u00b7 DevDojo<\/text>\n<text x=\"60\" y=\"148\" font-family=\"Segoe UI,Arial,sans-serif\" font-size=\"54\" font-weight=\"800\" fill=\"#ffffff\">Run LLMs Locally<\/text>\n<text x=\"60\" y=\"206\" font-family=\"Segoe UI,Arial,sans-serif\" font-size=\"44\" font-weight=\"800\" fill=\"url(#ddac)\">with Ollama<\/text>\n<text x=\"60\" y=\"248\" font-family=\"Segoe UI,Arial,sans-serif\" font-size=\"23\" fill=\"#c9d1ff\">Free, private, offline AI on your own laptop<\/text>\n<g font-family=\"Segoe UI,Arial,sans-serif\">\n<g class=\"node\"><rect x=\"70\" y=\"295\" width=\"190\" height=\"52\" rx=\"12\" fill=\"#1b2250\" stroke=\"#89e051\" stroke-width=\"2\"\/><text x=\"165\" y=\"328\" text-anchor=\"middle\" font-size=\"18\" font-weight=\"700\" fill=\"#fff\">$ ollama run<\/text><\/g>\n<g class=\"node\"><rect x=\"70\" y=\"362\" width=\"190\" height=\"52\" rx=\"12\" fill=\"#1b2250\" stroke=\"#ffd43b\" stroke-width=\"2\"\/><text x=\"165\" y=\"395\" text-anchor=\"middle\" font-size=\"18\" font-weight=\"700\" fill=\"#fff\">Python app<\/text><\/g>\n<g class=\"node\"><rect x=\"70\" y=\"429\" width=\"190\" height=\"52\" rx=\"12\" fill=\"#1b2250\" stroke=\"#f1e05a\" stroke-width=\"2\"\/><text x=\"165\" y=\"462\" text-anchor=\"middle\" font-size=\"18\" font-weight=\"700\" fill=\"#fff\">Node.js app<\/text><\/g>\n<g class=\"node\"><rect x=\"400\" y=\"335\" width=\"230\" height=\"110\" rx=\"20\" fill=\"url(#ddac)\"\/><text x=\"515\" y=\"383\" text-anchor=\"middle\" font-size=\"32\" font-weight=\"800\" fill=\"#fff\">Ollama<\/text><text x=\"515\" y=\"414\" text-anchor=\"middle\" font-size=\"16\" fill=\"#eef\">localhost:11434<\/text><\/g>\n<g class=\"node\"><rect x=\"770\" y=\"295\" width=\"170\" height=\"52\" rx=\"12\" fill=\"#0b1020\" stroke=\"#7c5cff\" stroke-width=\"2\"\/><text x=\"855\" y=\"328\" text-anchor=\"middle\" font-size=\"18\" font-weight=\"700\" fill=\"#fff\">Llama<\/text><\/g>\n<g class=\"node\"><rect x=\"770\" y=\"362\" width=\"170\" height=\"52\" rx=\"12\" fill=\"#0b1020\" stroke=\"#3178c6\" stroke-width=\"2\"\/><text x=\"855\" y=\"395\" text-anchor=\"middle\" font-size=\"18\" font-weight=\"700\" fill=\"#fff\">Gemma<\/text><\/g>\n<g class=\"node\"><rect x=\"770\" y=\"429\" width=\"170\" height=\"52\" rx=\"12\" fill=\"#0b1020\" stroke=\"#61dafb\" stroke-width=\"2\"\/><text x=\"855\" y=\"462\" text-anchor=\"middle\" font-size=\"18\" font-weight=\"700\" fill=\"#fff\">Qwen<\/text><\/g>\n<g class=\"node\"><rect x=\"1000\" y=\"340\" width=\"150\" height=\"100\" rx=\"18\" fill=\"#0b1020\" stroke=\"#7c5cff\" stroke-width=\"2\"\/><text x=\"1075\" y=\"380\" text-anchor=\"middle\" font-size=\"19\" font-weight=\"800\" fill=\"#fff\">Your PC<\/text><text x=\"1075\" y=\"406\" text-anchor=\"middle\" font-size=\"14\" fill=\"#c9d1ff\">CPU \/ GPU<\/text><text x=\"1075\" y=\"426\" text-anchor=\"middle\" font-size=\"14\" fill=\"#c9d1ff\">no cloud<\/text><\/g>\n<\/g>\n<path id=\"ddf1\" d=\"M260 321 C 330 321, 330 370, 400 370\" fill=\"none\" stroke=\"url(#ddac)\" stroke-width=\"3\" stroke-dasharray=\"8 8\" opacity=\".8\"\/>\n<path id=\"ddf2\" d=\"M260 388 C 320 388, 340 390, 400 390\" fill=\"none\" stroke=\"url(#ddac)\" stroke-width=\"3\" stroke-dasharray=\"8 8\" opacity=\".8\"\/>\n<path id=\"ddf3\" d=\"M260 455 C 330 455, 330 410, 400 410\" fill=\"none\" stroke=\"url(#ddac)\" stroke-width=\"3\" stroke-dasharray=\"8 8\" opacity=\".8\"\/>\n<path id=\"ddf4\" d=\"M630 390 C 700 390, 700 321, 770 321\" fill=\"none\" stroke=\"url(#ddac)\" stroke-width=\"3\" stroke-dasharray=\"8 8\" opacity=\".8\"\/>\n<path id=\"ddf5\" d=\"M630 390 C 700 390, 700 455, 770 455\" fill=\"none\" stroke=\"url(#ddac)\" stroke-width=\"3\" stroke-dasharray=\"8 8\" opacity=\".8\"\/>\n<path id=\"ddf6\" d=\"M940 388 C 965 388, 975 390, 1000 390\" fill=\"none\" stroke=\"url(#ddac)\" stroke-width=\"3\" stroke-dasharray=\"8 8\" opacity=\".8\"\/>\n<circle r=\"6\" fill=\"#89e051\"><animateMotion dur=\"2.4s\" repeatCount=\"indefinite\"><mpath href=\"#ddf1\"\/><\/animateMotion><\/circle>\n<circle r=\"6\" fill=\"#ffd43b\"><animateMotion dur=\"2.4s\" begin=\".6s\" repeatCount=\"indefinite\"><mpath href=\"#ddf2\"\/><\/animateMotion><\/circle>\n<circle r=\"6\" fill=\"#f1e05a\"><animateMotion dur=\"2.4s\" begin=\"1.2s\" repeatCount=\"indefinite\"><mpath href=\"#ddf3\"\/><\/animateMotion><\/circle>\n<circle r=\"7\" fill=\"#7c5cff\"><animateMotion dur=\"2s\" repeatCount=\"indefinite\"><mpath href=\"#ddf4\"\/><\/animateMotion><\/circle>\n<circle r=\"7\" fill=\"#61dafb\"><animateMotion dur=\"2s\" begin=\"1s\" repeatCount=\"indefinite\"><mpath href=\"#ddf5\"\/><\/animateMotion><\/circle>\n<circle r=\"6\" fill=\"#ffffff\"><animateMotion dur=\"1.6s\" repeatCount=\"indefinite\"><mpath href=\"#ddf6\"\/><\/animateMotion><\/circle>\n<text x=\"60\" y=\"510\" font-family=\"Segoe UI,Arial,sans-serif\" font-size=\"16\" fill=\"#7f89b5\">devdojo.co.in \u00b7 Beginner friendly \u00b7 Terminal + Python + Node.js examples<\/text>\n<\/svg>\n<\/div>\n\n<div class=\"dd-series\">Series: Generative AI <span>Part 6 of 30<\/span><\/div>\n<p class=\"dd-prereq\"><strong>What you should know first:<\/strong> read <a href=\"https:\/\/devdojo.co.in\/?p=244\">Part 5: Temperature, Top-p and Controlling Model Output<\/a> and <a href=\"https:\/\/devdojo.co.in\/?p=223\">Part 3: Your First LLM API Calls<\/a>. You only need a terminal and a laptop with at least 8 GB of RAM.<\/p>\n\n<p>So far in this series every model we used lived in someone else&#8217;s data centre: you sent a prompt over the internet, paid per token and trusted the provider with your data. In this part you will learn how to <strong>run LLMs locally with Ollama<\/strong>, a free open-source tool that downloads open models such as Llama, Gemma and Qwen and runs them on your own computer. You will install Ollama, pull your first model, chat with it in the terminal, call it from Python and Node.js, stream answers, reuse your OpenAI code from Part 3 and even build your own custom model with a <code>Modelfile<\/code>. No API key, no bill, and it works offline.<\/p>\n\n<div class=\"dd-summary\">\n<strong class=\"lbl\">Quick Summary<\/strong>\n<ul>\n<li><strong>Ollama<\/strong> is a free tool that downloads and runs <strong>open models<\/strong> (Llama, Gemma, Qwen, Mistral, gpt-oss and more) on your own computer.<\/li>\n<li>Install it, then use <code>ollama pull llama3.2<\/code> to download a model and <code>ollama run llama3.2<\/code> to chat with it in the terminal.<\/li>\n<li>Ollama runs a local server at <code>http:\/\/localhost:11434<\/code>. Your apps talk to it with the <code>ollama<\/code> package (Python and JavaScript) or plain HTTP.<\/li>\n<li>It also offers an <strong>OpenAI-compatible API<\/strong> at <code>\/v1<\/code>, so your Part 3 code works locally by changing only the base URL.<\/li>\n<li>Pick a model that fits your <strong>RAM<\/strong>: about 1\u20134B parameters for 8 GB, 7\u20138B for 16 GB, and bigger models need 32 GB or a good GPU.<\/li>\n<li>Local models give you <strong>privacy, zero per-token cost and full control<\/strong> (temperature, top-k, seed, context size), but they are smaller and slower than top cloud models.<\/li>\n<\/ul>\n<\/div>\n\n<details class=\"dd-roadmap\">\n<summary>Full Generative AI roadmap (30 parts)<\/summary>\n<h4>Beginner<\/h4>\n<ol start=\"1\">\n<li><a href=\"https:\/\/devdojo.co.in\/?p=215\">What Is Generative AI and How Do LLMs Work?<\/a><\/li>\n<li><a href=\"https:\/\/devdojo.co.in\/?p=219\">Tokens, Context Windows and Model Parameters<\/a><\/li>\n<li><a href=\"https:\/\/devdojo.co.in\/?p=223\">Your First LLM API Calls in Python and Node.js (OpenAI, Anthropic, Gemini)<\/a><\/li>\n<li><a href=\"https:\/\/devdojo.co.in\/?p=240\">Prompt Engineering Basics: Roles, Instructions and Examples<\/a><\/li>\n<li><a href=\"https:\/\/devdojo.co.in\/?p=244\">Temperature, Top-p and Controlling Model Output<\/a><\/li>\n<li>Run LLMs Locally with Ollama <span class=\"here\">You are here<\/span><\/li>\n<li>Streaming Responses and Building a Simple Chat UI <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Structured Outputs: Getting Reliable JSON from LLMs <span class=\"soon\">Coming soon<\/span><\/li>\n<\/ol>\n<h4>Intermediate<\/h4>\n<ol start=\"9\">\n<li>Embeddings Explained: Turning Text into Vectors <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Vector Databases: pgvector, Chroma and Pinecone <span class=\"soon\">Coming soon<\/span><\/li>\n<li>RAG Fundamentals: Retrieval-Augmented Generation <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Document Loading and Chunking Strategies <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Better RAG: Hybrid Search, Re-ranking and Query Rewriting <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Function Calling and Tool Use <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Conversation Memory and Long Context Management <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Multimodal AI: Vision, Images and Audio Inputs <span class=\"soon\">Coming soon<\/span><\/li>\n<li>How Image Generation Works: Diffusion Models Basics <span class=\"soon\">Coming soon<\/span><\/li>\n<li>LangChain vs LlamaIndex: When to Use a Framework <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Testing LLM Apps: Evals, Metrics and Test Sets <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Cutting Cost and Latency: Caching, Batching and Model Choice <span class=\"soon\">Coming soon<\/span><\/li>\n<\/ol>\n<h4>Advanced<\/h4>\n<ol start=\"21\">\n<li>Fine-Tuning vs Prompting vs RAG: Choosing the Right Tool <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Fine-Tuning an Open Model with LoRA <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Transformers Deep Dive: Attention Explained Simply <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Reasoning Models and Thinking Time <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Guardrails, Safety and Prompt Injection Defence <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Monitoring and Tracing LLM Apps in Production <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Serving Open Models: vLLM, Quantization and GPUs <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Building a Production GenAI App End to End <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Responsible AI: Privacy, Licensing and Bias <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Final Project: Build Your Own AI Knowledge Assistant <span class=\"soon\">Coming soon<\/span><\/li>\n<\/ol>\n<\/details>\n\n<nav class=\"dd-toc\" aria-label=\"Table of contents\">\n<strong>In this part<\/strong>\n<ol>\n<li><a href=\"#why-local\">Why run LLMs locally?<\/a><\/li>\n<li><a href=\"#what-is-ollama\">What is Ollama and how it works<\/a><\/li>\n<li><a href=\"#install\">Install Ollama and run your first model<\/a><\/li>\n<li><a href=\"#choose-model\">Choosing a model for your computer<\/a><\/li>\n<li><a href=\"#rest-api\">The local REST API<\/a><\/li>\n<li><a href=\"#python-node\">Run LLMs locally with Ollama from Python and Node.js<\/a><\/li>\n<li><a href=\"#streaming\">Streaming answers<\/a><\/li>\n<li><a href=\"#openai-compatible\">Reuse OpenAI code with a local model<\/a><\/li>\n<li><a href=\"#modelfile\">Build a custom model with a Modelfile<\/a><\/li>\n<li><a href=\"#common-errors\">Common errors and fixes<\/a><\/li>\n<li><a href=\"#best-practices\">Best practices<\/a><\/li>\n<li><a href=\"#practice\">Practice task<\/a><\/li>\n<li><a href=\"#faq\">FAQ<\/a><\/li>\n<\/ol>\n<\/nav>\n<\/div>\n\n\n\n<div class=\"dd-post\">\n<h2 id=\"why-local\">Why run LLMs locally?<\/h2>\n<p>In <a href=\"https:\/\/devdojo.co.in\/?p=223\">Part 3<\/a> you called OpenAI, Claude and Gemini over the internet. Those models are the smartest available, but every request costs money, needs an API key and sends your text to another company. A <strong>local LLM<\/strong> flips all of that. The model file sits on your disk and runs on your own CPU or GPU.<\/p>\n<div class=\"dd-cards\">\n<div class=\"dd-card\"><b>Privacy<\/b>Company code, customer data or personal notes never leave your computer. Great for regulated work.<\/div>\n<div class=\"dd-card\"><b>Zero per-token cost<\/b>Experiment as much as you like. Perfect for learning, testing prompts and batch jobs.<\/div>\n<div class=\"dd-card\"><b>Works offline<\/b>Code on a train or flight. No network, no rate limits, no outages.<\/div>\n<div class=\"dd-card\"><b>Full control<\/b>All the sampling dials from Part 5 (temperature, top-k, seed) still work, plus context size.<\/div>\n<\/div>\n<figure>\n<svg viewBox=\"0 0 900 340\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" role=\"img\" aria-label=\"Comparison: a cloud LLM API sends your prompt over the internet to a provider and bills per token, while a local model with Ollama keeps the prompt on your laptop for free\">\n<rect width=\"900\" height=\"340\" rx=\"16\" fill=\"#0f1430\"\/>\n<g font-family=\"Segoe UI,Arial,sans-serif\">\n<text x=\"225\" y=\"40\" text-anchor=\"middle\" font-size=\"20\" font-weight=\"800\" fill=\"#fff\">Cloud API (Parts 3\u20135)<\/text>\n<text x=\"675\" y=\"40\" text-anchor=\"middle\" font-size=\"20\" font-weight=\"800\" fill=\"#fff\">Local model (this part)<\/text>\n<line x1=\"450\" y1=\"20\" x2=\"450\" y2=\"320\" stroke=\"#2b3466\" stroke-width=\"2\" stroke-dasharray=\"6 6\"\/>\n<rect x=\"40\" y=\"80\" width=\"130\" height=\"60\" rx=\"12\" fill=\"#1b2250\" stroke=\"#3178c6\" stroke-width=\"2\"\/><text x=\"105\" y=\"116\" text-anchor=\"middle\" font-size=\"16\" fill=\"#fff\">Your app<\/text>\n<rect x=\"280\" y=\"80\" width=\"140\" height=\"60\" rx=\"12\" fill=\"#1b2250\" stroke=\"#7c5cff\" stroke-width=\"2\"\/><text x=\"350\" y=\"108\" text-anchor=\"middle\" font-size=\"16\" fill=\"#fff\">Provider<\/text><text x=\"350\" y=\"128\" text-anchor=\"middle\" font-size=\"12\" fill=\"#c9d1ff\">data centre<\/text>\n<path d=\"M170 110 H280\" stroke=\"#7c5cff\" stroke-width=\"3\" stroke-dasharray=\"7 6\"\/><text x=\"225\" y=\"100\" text-anchor=\"middle\" font-size=\"12\" fill=\"#c9d1ff\">internet<\/text>\n<text x=\"60\" y=\"190\" font-size=\"15\" fill=\"#ffb3b3\">\u2717 pay per token<\/text>\n<text x=\"60\" y=\"218\" font-size=\"15\" fill=\"#ffb3b3\">\u2717 data leaves your machine<\/text>\n<text x=\"60\" y=\"246\" font-size=\"15\" fill=\"#ffb3b3\">\u2717 needs internet + API key<\/text>\n<text x=\"60\" y=\"274\" font-size=\"15\" fill=\"#9be7b4\">\u2713 biggest, smartest models<\/text>\n<text x=\"60\" y=\"302\" font-size=\"15\" fill=\"#9be7b4\">\u2713 no hardware needed<\/text>\n<rect x=\"490\" y=\"70\" width=\"370\" height=\"90\" rx=\"16\" fill=\"none\" stroke=\"#61dafb\" stroke-width=\"2\"\/><text x=\"505\" y=\"92\" font-size=\"12\" fill=\"#61dafb\">your laptop<\/text>\n<rect x=\"510\" y=\"98\" width=\"120\" height=\"50\" rx=\"10\" fill=\"#1b2250\" stroke=\"#3178c6\" stroke-width=\"2\"\/><text x=\"570\" y=\"129\" text-anchor=\"middle\" font-size=\"16\" fill=\"#fff\">Your app<\/text>\n<rect x=\"720\" y=\"98\" width=\"120\" height=\"50\" rx=\"10\" fill=\"url(#f1ac)\"\/><text x=\"780\" y=\"129\" text-anchor=\"middle\" font-size=\"16\" font-weight=\"700\" fill=\"#fff\">Ollama<\/text>\n<defs><linearGradient id=\"f1ac\" x1=\"0\" x2=\"1\"><stop offset=\"0\" stop-color=\"#3178c6\"\/><stop offset=\"1\" stop-color=\"#7c5cff\"\/><\/linearGradient><\/defs>\n<path d=\"M630 123 H720\" stroke=\"#61dafb\" stroke-width=\"3\" stroke-dasharray=\"7 6\"\/>\n<text x=\"510\" y=\"190\" font-size=\"15\" fill=\"#9be7b4\">\u2713 free after download<\/text>\n<text x=\"510\" y=\"218\" font-size=\"15\" fill=\"#9be7b4\">\u2713 data never leaves your PC<\/text>\n<text x=\"510\" y=\"246\" font-size=\"15\" fill=\"#9be7b4\">\u2713 works offline, no API key<\/text>\n<text x=\"510\" y=\"274\" font-size=\"15\" fill=\"#ffb3b3\">\u2717 smaller models, less smart<\/text>\n<text x=\"510\" y=\"302\" font-size=\"15\" fill=\"#ffb3b3\">\u2717 speed depends on your RAM\/GPU<\/text>\n<\/g>\n<\/svg>\n<figcaption>Cloud APIs vs local models: local wins on privacy and cost, cloud wins on raw quality.<\/figcaption>\n<\/figure>\n<p>The trade-off is quality and speed. A 3-billion-parameter model on a laptop will not match the biggest cloud models at hard reasoning, but it is surprisingly good at summaries, simple Q&amp;A, rewriting text and code help. Many real apps use both: a local model for cheap, private tasks and a cloud model for the hardest ones.<\/p>\n\n<h2 id=\"what-is-ollama\">What is Ollama and how it works<\/h2>\n<p><strong>Ollama<\/strong> is a free, open-source app for macOS, Windows and Linux that makes local models as easy as Docker made containers. It does three jobs for you:<\/p>\n<ol>\n<li><strong>Downloads models<\/strong> from its library (<a href=\"https:\/\/ollama.com\/library\" target=\"_blank\" rel=\"noopener\">ollama.com\/library<\/a>) in a compressed (quantized) format called <em>GGUF<\/em>, so an 8B model needs about 5 GB instead of 16 GB.<\/li>\n<li><strong>Runs a local server<\/strong> on <code>http:\/\/localhost:11434<\/code> that loads the model into RAM or GPU memory and answers requests.<\/li>\n<li><strong>Gives you simple tools<\/strong>: a command-line chat, a REST API, official Python and JavaScript packages and an OpenAI-compatible endpoint.<\/li>\n<\/ol>\n<figure>\n<svg viewBox=\"0 0 900 300\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" role=\"img\" aria-label=\"How Ollama works: apps send HTTP requests to the Ollama server on port 11434, which loads model files from disk into memory and runs them on the CPU or GPU\">\n<defs><linearGradient id=\"f2ac\" x1=\"0\" x2=\"1\"><stop offset=\"0\" stop-color=\"#3178c6\"\/><stop offset=\"1\" stop-color=\"#7c5cff\"\/><\/linearGradient><\/defs>\n<rect width=\"900\" height=\"300\" rx=\"16\" fill=\"#0f1430\"\/>\n<g font-family=\"Segoe UI,Arial,sans-serif\">\n<rect x=\"30\" y=\"50\" width=\"160\" height=\"44\" rx=\"10\" fill=\"#1b2250\" stroke=\"#89e051\" stroke-width=\"2\"\/><text x=\"110\" y=\"78\" text-anchor=\"middle\" font-size=\"15\" fill=\"#fff\">ollama run (CLI)<\/text>\n<rect x=\"30\" y=\"110\" width=\"160\" height=\"44\" rx=\"10\" fill=\"#1b2250\" stroke=\"#ffd43b\" stroke-width=\"2\"\/><text x=\"110\" y=\"138\" text-anchor=\"middle\" font-size=\"15\" fill=\"#fff\">Python \/ Node.js<\/text>\n<rect x=\"30\" y=\"170\" width=\"160\" height=\"44\" rx=\"10\" fill=\"#1b2250\" stroke=\"#61dafb\" stroke-width=\"2\"\/><text x=\"110\" y=\"198\" text-anchor=\"middle\" font-size=\"15\" fill=\"#fff\">Chat apps, IDEs<\/text>\n<path d=\"M190 72 C 230 72, 230 130, 270 130 M190 132 H270 M190 192 C 230 192, 230 134, 270 134\" stroke=\"#7c5cff\" stroke-width=\"2.5\" fill=\"none\"\/>\n<text x=\"230\" y=\"240\" text-anchor=\"middle\" font-size=\"13\" fill=\"#c9d1ff\">HTTP requests<\/text>\n<rect x=\"270\" y=\"80\" width=\"200\" height=\"110\" rx=\"16\" fill=\"url(#f2ac)\"\/><text x=\"370\" y=\"122\" text-anchor=\"middle\" font-size=\"22\" font-weight=\"800\" fill=\"#fff\">Ollama server<\/text><text x=\"370\" y=\"148\" text-anchor=\"middle\" font-size=\"14\" fill=\"#eef\">localhost:11434<\/text><text x=\"370\" y=\"170\" text-anchor=\"middle\" font-size=\"13\" fill=\"#eef\">loads &amp; unloads models<\/text>\n<rect x=\"530\" y=\"40\" width=\"170\" height=\"70\" rx=\"12\" fill=\"#1b2250\" stroke=\"#7c5cff\" stroke-width=\"2\"\/><text x=\"615\" y=\"70\" text-anchor=\"middle\" font-size=\"15\" fill=\"#fff\">Model files<\/text><text x=\"615\" y=\"92\" text-anchor=\"middle\" font-size=\"12\" fill=\"#c9d1ff\">~\/.ollama\/models (GGUF)<\/text>\n<rect x=\"530\" y=\"160\" width=\"170\" height=\"70\" rx=\"12\" fill=\"#1b2250\" stroke=\"#3178c6\" stroke-width=\"2\"\/><text x=\"615\" y=\"190\" text-anchor=\"middle\" font-size=\"15\" fill=\"#fff\">Model in memory<\/text><text x=\"615\" y=\"212\" text-anchor=\"middle\" font-size=\"12\" fill=\"#c9d1ff\">kept warm ~5 min<\/text>\n<path d=\"M470 120 C 500 120, 500 75, 530 75 M615 110 V160 M470 150 C 500 150, 500 195, 530 195\" stroke=\"#61dafb\" stroke-width=\"2.5\" fill=\"none\"\/>\n<rect x=\"760\" y=\"140\" width=\"110\" height=\"110\" rx=\"14\" fill=\"#0b1020\" stroke=\"#89e051\" stroke-width=\"2\"\/><text x=\"815\" y=\"185\" text-anchor=\"middle\" font-size=\"16\" font-weight=\"700\" fill=\"#fff\">GPU<\/text><text x=\"815\" y=\"210\" text-anchor=\"middle\" font-size=\"13\" fill=\"#c9d1ff\">or CPU +<\/text><text x=\"815\" y=\"228\" text-anchor=\"middle\" font-size=\"13\" fill=\"#c9d1ff\">RAM<\/text>\n<path d=\"M700 195 H760\" stroke=\"#89e051\" stroke-width=\"2.5\"\/>\n<text x=\"450\" y=\"280\" text-anchor=\"middle\" font-size=\"13\" fill=\"#7f89b5\">Answers stream back the same way, token by token<\/text>\n<\/g>\n<\/svg>\n<figcaption>How Ollama works: one local server, many apps, models loaded from disk into RAM or GPU memory.<\/figcaption>\n<\/figure>\n<div class=\"dd-note\"><strong>Open model vs open source:<\/strong> &#8220;open model&#8221; (or &#8220;open weights&#8221;) means you can download and run the model file. Each model still has its own licence, so check it on the model page before using it in a commercial product.<\/div>\n\n<h2 id=\"install\">Install Ollama and run your first model<\/h2>\n<p>On macOS and Windows, download the installer from the official site and open it; Ollama then runs in the background (you will see its icon in the menu bar or system tray). On Linux, use the install script. Then pull a model and start chatting:<\/p>\n<div class=\"dd-vsc dd-vsc-termonly\" role=\"group\" aria-label=\"Terminal: Terminal \u2014 install Ollama\">\n<div class=\"dd-vsc-bar\"><span class=\"dd-dots\"><i><\/i><i><\/i><i><\/i><\/span><span class=\"dd-vsc-title\">Terminal \u2014 install Ollama<\/span><\/div>\n<pre class=\"dd-vsc-code\"><code><span class=\"l\"><span class=\"c\"># macOS \/ Windows: download the installer from https:\/\/ollama.com\/download<\/span><\/span>\n<span class=\"l\"><span class=\"c\"># Linux: one-line install script<\/span><\/span>\n<span class=\"l\"><span class=\"gp\">$<\/span> curl -fsSL https:\/\/ollama.com\/install.sh | sh<\/span>\n<span class=\"l\"><span class=\"gp\">$<\/span> ollama --version<\/span>\n<span class=\"l\"><span class=\"c\"># download a small model (about 2 GB) and chat with it<\/span><\/span>\n<span class=\"l\"><span class=\"gp\">$<\/span> ollama pull llama3.2<\/span>\n<span class=\"l\"><span class=\"gp\">$<\/span> ollama run llama3.2<\/span>\n<span class=\"l\"><span class=\"c\"># type a message, press Enter; type \/bye to quit<\/span><\/span><\/code><\/pre>\n<\/div>\n<p>The first <code>ollama run<\/code> takes a few seconds while the model loads into memory; after that, answers start almost instantly. If you skip <code>ollama pull<\/code>, <code>ollama run<\/code> downloads the model for you automatically. Here are the everyday commands you will use:<\/p>\n<div class=\"dd-vsc dd-vsc-termonly\" role=\"group\" aria-label=\"Terminal: Terminal \u2014 manage models\">\n<div class=\"dd-vsc-bar\"><span class=\"dd-dots\"><i><\/i><i><\/i><i><\/i><\/span><span class=\"dd-vsc-title\">Terminal \u2014 manage models<\/span><\/div>\n<pre class=\"dd-vsc-code\"><code><span class=\"l\"><span class=\"gp\">$<\/span> ollama list            # models on your disk<\/span>\n<span class=\"l\"><span class=\"gp\">$<\/span> ollama ps              # models loaded in memory right now<\/span>\n<span class=\"l\"><span class=\"gp\">$<\/span> ollama run llama3.2 \"Explain an API in one sentence\"   # one-shot prompt<\/span>\n<span class=\"l\"><span class=\"gp\">$<\/span> ollama show llama3.2   # size, context length, parameters<\/span>\n<span class=\"l\"><span class=\"gp\">$<\/span> ollama stop llama3.2   # unload it from memory<\/span>\n<span class=\"l\"><span class=\"gp\">$<\/span> ollama rm llama3.2     # delete it from disk<\/span><\/code><\/pre>\n<\/div>\n<div class=\"dd-tip\"><strong>Tip:<\/strong> model names have tags after a colon. <code>llama3.2<\/code> means the default tag (3B parameters); <code>llama3.2:1b<\/code> is the smaller 1B version. The tag tells you the size, and size tells you how much memory you need.<\/div>\n<\/div>\n\n\n\n<div class=\"dd-post\">\n<h2 id=\"choose-model\">Choosing a model for your computer<\/h2>\n<p>The most common beginner mistake is downloading a model that is too big. A simple rule: a model compressed to 4 bits needs roughly <strong>0.6\u20130.7 GB of memory per billion parameters<\/strong>, plus extra for the context window. So a 3B model needs about 2\u20133 GB, an 8B model about 5\u20136 GB and a 32B model about 20 GB. Click your setup below for safe picks:<\/p>\n<div class=\"dd-tabs\" role=\"group\" aria-label=\"Model picker by computer memory\">\n<input type=\"radio\" name=\"ram\" id=\"ti1\" checked>\n<input type=\"radio\" name=\"ram\" id=\"ti2\">\n<input type=\"radio\" name=\"ram\" id=\"ti3\">\n<input type=\"radio\" name=\"ram\" id=\"ti4\">\n<div class=\"labels\"><label for=\"ti1\">8 GB RAM<\/label><label for=\"ti2\">16 GB RAM<\/label><label for=\"ti3\">32 GB+ RAM<\/label><label for=\"ti4\">With a GPU<\/label><\/div>\n<div class=\"panel p1\"><p><strong>Most student laptops.<\/strong> Stay with 1\u20134B parameter models and close heavy apps (Chrome tabs eat RAM too).<\/p>\n<div class=\"dd-ram\"><div><b>Start here<\/b><code>llama3.2<\/code> (3B)<\/div><div><b>Tiny + fast<\/b><code>llama3.2:1b<\/code>, <code>gemma3:1b<\/code><\/div><div><b>Good all-rounder<\/b><code>gemma3:4b<\/code>, <code>qwen3:4b<\/code><\/div><\/div>\n<p>Expect a few words per second on CPU. Fine for learning and small tasks.<\/p><\/div>\n<div class=\"panel p2\"><p><strong>Typical developer laptop, including Apple Silicon Macs.<\/strong> 7\u20138B models are the sweet spot for quality and speed.<\/p>\n<div class=\"dd-ram\"><div><b>Chat + writing<\/b><code>llama3.1:8b<\/code><\/div><div><b>Code + reasoning<\/b><code>qwen3:8b<\/code><\/div><div><b>Vision too<\/b><code>gemma3:4b<\/code> (reads images)<\/div><\/div>\n<p>Apple Silicon shares memory with its GPU, so Macs run these models smoothly.<\/p><\/div>\n<div class=\"panel p3\"><p><strong>Workstations and high-end Macs.<\/strong> You can try 12\u201332B models that feel much closer to cloud quality.<\/p>\n<div class=\"dd-ram\"><div><b>Strong all-rounder<\/b><code>gemma3:12b<\/code>, <code>qwen3:14b<\/code><\/div><div><b>Open reasoning model<\/b><code>gpt-oss:20b<\/code><\/div><div><b>Heavier<\/b><code>gemma3:27b<\/code>, <code>qwen3:32b<\/code><\/div><\/div>\n<p>Bigger models load slower; keep only one large model running at a time.<\/p><\/div>\n<div class=\"panel p4\"><p><strong>NVIDIA or AMD GPU.<\/strong> Ollama uses the GPU automatically when the model fits in its video memory (VRAM).<\/p>\n<div class=\"dd-ram\"><div><b>8 GB VRAM<\/b>7\u20138B models<\/div><div><b>12\u201316 GB VRAM<\/b>12\u201314B models, <code>gpt-oss:20b<\/code><\/div><div><b>24 GB VRAM<\/b>up to ~32B models<\/div><\/div>\n<p>Run <code>ollama ps<\/code>: the PROCESSOR column shows how much of the model sits on the GPU vs the CPU.<\/p><\/div>\n<\/div>\n<p>Model names change quickly as new versions arrive, so treat these as starting points and browse the <a href=\"https:\/\/ollama.com\/library\" target=\"_blank\" rel=\"noopener\">Ollama model library<\/a> for the newest options. Look at the size tag and the &#8220;tools&#8221;, &#8220;vision&#8221; or &#8220;thinking&#8221; labels on each model page.<\/p>\n\n<h2 id=\"rest-api\">The local REST API<\/h2>\n<p>Everything Ollama does goes through its HTTP server, so any language that can send a request can use a local model. The two main endpoints are <code>\/api\/generate<\/code> (single prompt) and <code>\/api\/chat<\/code> (a list of messages with roles, exactly like Part 4). Set <code>\"stream\": false<\/code> to get one JSON reply instead of many small chunks:<\/p>\n<div class=\"dd-vsc\" role=\"group\" aria-label=\"Code editor: api_chat.sh\">\n<input type=\"radio\" name=\"v1\" id=\"v1f1\" class=\"f1\" checked>\n<input type=\"checkbox\" id=\"v1r1\" class=\"r1\">\n<div class=\"dd-vsc-bar\"><span class=\"dd-dots\"><i><\/i><i><\/i><i><\/i><\/span><span class=\"dd-vsc-title\">api_chat.sh \u2014 devdojo-ollama \u2014 Visual Studio Code<\/span><\/div>\n<div class=\"dd-vsc-tabs\">\n<label for=\"v1f1\" class=\"t1\"><b class=\"ic sh\">$_<\/b>api_chat.sh<\/label>\n<label for=\"v1r1\" class=\"run run1\" title=\"Show the output in the terminal\">\u25b6 Run<\/label>\n<\/div>\n<div class=\"dd-vsc-pane p1\">\n<div class=\"dd-vsc-crumbs\">devdojo-ollama \u203a api_chat.sh<\/div>\n<pre class=\"dd-vsc-code\"><code><span class=\"l\"><span class=\"c\"># Ollama runs a local REST API on port 11434<\/span><\/span>\n<span class=\"l\">curl http:\/\/localhost:11434\/api\/chat -d <span class=\"s\">'{<\/span><\/span>\n<span class=\"l\"><span class=\"s\">  \"model\": \"llama3.2\",<\/span><\/span>\n<span class=\"l\"><span class=\"s\">  \"messages\": [{ \"role\": \"user\", \"content\": \"Say hello to DevDojo readers\" }],<\/span><\/span>\n<span class=\"l\"><span class=\"s\">  \"stream\": false,<\/span><\/span>\n<span class=\"l\"><span class=\"s\">  \"options\": { \"temperature\": 0.2 }<\/span><\/span>\n<span class=\"l\"><span class=\"s\">}'<\/span><\/span><\/code><\/pre>\n<div class=\"dd-vsc-term\"><div class=\"dd-term-head\"><span>TERMINAL<\/span><span>OUTPUT<\/span><span>PROBLEMS<\/span><span class=\"dd-term-note\">Example output \u2013 wording and numbers will differ on your machine<\/span><\/div><pre><code><span class=\"gp\">$<\/span> bash api_chat.sh\n{\"model\":\"llama3.2\",\"created_at\":\"\u2026\",\"message\":{\"role\":\"assistant\",\"content\":\"Hello, DevDojo readers! Happy coding and keep learning!\"},\"done\":true,\"done_reason\":\"stop\",\"total_duration\":\u2026,\"prompt_eval_count\":\u2026,\"eval_count\":\u2026}<\/code><\/pre><\/div>\n<div class=\"dd-vsc-status\"><span>\u2387 main<\/span><span>Ln 7, Col 1<\/span><span class=\"sp\"><\/span><span>Spaces: 4<\/span><span>UTF-8<\/span><span>LF<\/span><span>Shell Script<\/span><\/div>\n<\/div>\n<\/div>\n<p class=\"dd-vsc-hint\">Click <strong>\u25b6 Run<\/strong> to see the shape of the JSON reply. The <code>\u2026<\/code> parts are timing and token numbers that differ on every machine.<\/p>\n<p>Notice that the reply has the same <code>role<\/code> and <code>content<\/code> shape you saw with cloud APIs, plus useful stats: <code>prompt_eval_count<\/code> (input tokens), <code>eval_count<\/code> (output tokens) and <code>total_duration<\/code> in nanoseconds.<\/p>\n<\/div>\n\n\n\n<div class=\"dd-post\">\n<h2 id=\"python-node\">Run LLMs locally with Ollama from Python and Node.js<\/h2>\n<p>For real apps, use the official <code>ollama<\/code> packages. They wrap the REST API with nice types, and the code looks almost the same in both languages. Install them first (and keep Ollama running in the background):<\/p>\n<div class=\"dd-vsc dd-vsc-termonly\" role=\"group\" aria-label=\"Terminal: Terminal \u2014 devdojo-ollama\">\n<div class=\"dd-vsc-bar\"><span class=\"dd-dots\"><i><\/i><i><\/i><i><\/i><\/span><span class=\"dd-vsc-title\">Terminal \u2014 devdojo-ollama<\/span><\/div>\n<pre class=\"dd-vsc-code\"><code><span class=\"l\"><span class=\"c\"># Python<\/span><\/span>\n<span class=\"l\"><span class=\"gp\">$<\/span> pip install -U ollama openai<\/span>\n<span class=\"l\"><span class=\"c\"># Node.js (ES modules, Node 18+)<\/span><\/span>\n<span class=\"l\"><span class=\"gp\">$<\/span> npm install ollama openai<\/span><\/code><\/pre>\n<\/div>\n<p>Now send a chat request with a system message, a user message and the sampling options you learned in Part 5. <code>num_ctx<\/code> sets the context window size in tokens and <code>num_predict<\/code> is the local version of &#8220;max tokens&#8221;:<\/p>\n<div class=\"dd-vsc\" role=\"group\" aria-label=\"Code editor: chat_local.py, chat-local.mjs\">\n<input type=\"radio\" name=\"v2\" id=\"v2f1\" class=\"f1\" checked>\n<input type=\"radio\" name=\"v2\" id=\"v2f2\" class=\"f2\">\n<input type=\"checkbox\" id=\"v2r1\" class=\"r1\">\n<input type=\"checkbox\" id=\"v2r2\" class=\"r2\">\n<div class=\"dd-vsc-bar\"><span class=\"dd-dots\"><i><\/i><i><\/i><i><\/i><\/span><span class=\"dd-vsc-title\">2 files \u2014 devdojo-ollama \u2014 Visual Studio Code<\/span><\/div>\n<div class=\"dd-vsc-tabs\">\n<label for=\"v2f1\" class=\"t1\"><b class=\"ic py\">PY<\/b>chat_local.py<\/label>\n<label for=\"v2f2\" class=\"t2\"><b class=\"ic js\">JS<\/b>chat-local.mjs<\/label>\n<label for=\"v2r1\" class=\"run run1\" title=\"Show the output in the terminal\">\u25b6 Run<\/label>\n<label for=\"v2r2\" class=\"run run2\" title=\"Show the output in the terminal\">\u25b6 Run<\/label>\n<\/div>\n<div class=\"dd-vsc-pane p1\">\n<div class=\"dd-vsc-crumbs\">devdojo-ollama \u203a chat_local.py<\/div>\n<pre class=\"dd-vsc-code\"><code><span class=\"l\"><span class=\"c\"># chat_local.py - talk to a local model with the official ollama package<\/span><\/span>\n<span class=\"l\"><span class=\"kn\">from<\/span> <span class=\"n\">ollama<\/span> <span class=\"kn\">import<\/span> <span class=\"n\">chat<\/span><\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"n\">response<\/span> = <span class=\"n\">chat<\/span>(<\/span>\n<span class=\"l\">    <span class=\"n\">model<\/span>=<span class=\"s\">\"llama3.2\"<\/span>,<\/span>\n<span class=\"l\">    <span class=\"n\">messages<\/span>=[<\/span>\n<span class=\"l\">        {<span class=\"s\">\"role\"<\/span>: <span class=\"s\">\"system\"<\/span>, <span class=\"s\">\"content\"<\/span>: <span class=\"s\">\"You are a friendly coding tutor. Answer in 2 short sentences.\"<\/span>},<\/span>\n<span class=\"l\">        {<span class=\"s\">\"role\"<\/span>: <span class=\"s\">\"user\"<\/span>, <span class=\"s\">\"content\"<\/span>: <span class=\"s\">\"What is a REST API?\"<\/span>},<\/span>\n<span class=\"l\">    ],<\/span>\n<span class=\"l\">    <span class=\"n\">options<\/span>={<span class=\"s\">\"temperature\"<\/span>: <span class=\"m\">0.2<\/span>, <span class=\"s\">\"top_p\"<\/span>: <span class=\"m\">0.9<\/span>, <span class=\"s\">\"seed\"<\/span>: <span class=\"m\">42<\/span>, <span class=\"s\">\"num_ctx\"<\/span>: <span class=\"m\">4096<\/span>, <span class=\"s\">\"num_predict\"<\/span>: <span class=\"m\">120<\/span>},<\/span>\n<span class=\"l\">)<\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"nb\">print<\/span>(<span class=\"n\">response<\/span>.<span class=\"n\">message<\/span>.<span class=\"n\">content<\/span>)<\/span>\n<span class=\"l\"><span class=\"nb\">print<\/span>(<span class=\"s\">\"tokens in:\"<\/span>, <span class=\"n\">response<\/span>.<span class=\"n\">prompt_eval_count<\/span>, <span class=\"s\">\"| tokens out:\"<\/span>, <span class=\"n\">response<\/span>.<span class=\"n\">eval_count<\/span>)<\/span>\n<span class=\"l\"><span class=\"nb\">print<\/span>(<span class=\"s\">f\"time: {<\/span><span class=\"n\">response<\/span>.<span class=\"n\">total_duration<\/span> \/ <span class=\"m\">1e9<\/span><span class=\"s\">:.1f}s\"<\/span>)<\/span><\/code><\/pre>\n<div class=\"dd-vsc-term\"><div class=\"dd-term-head\"><span>TERMINAL<\/span><span>OUTPUT<\/span><span>PROBLEMS<\/span><span class=\"dd-term-note\">Example output \u2013 wording and numbers will differ on your machine<\/span><\/div><pre><code><span class=\"gp\">$<\/span> python chat_local.py\nA REST API is a way for programs to talk to each other over HTTP using URLs and methods like GET and POST. For example, an app can send GET \/users to a server and receive the list of users as JSON.\ntokens in: &lt;n&gt; | tokens out: &lt;n&gt;\ntime: &lt;seconds&gt;s<\/code><\/pre><\/div>\n<div class=\"dd-vsc-status\"><span>\u2387 main<\/span><span>Ln 15, Col 1<\/span><span class=\"sp\"><\/span><span>Spaces: 4<\/span><span>UTF-8<\/span><span>LF<\/span><span>Python<\/span><\/div>\n<\/div>\n<div class=\"dd-vsc-pane p2\">\n<div class=\"dd-vsc-crumbs\">devdojo-ollama \u203a chat-local.mjs<\/div>\n<pre class=\"dd-vsc-code\"><code><span class=\"l\"><span class=\"c\">\/\/ chat-local.mjs - talk to a local model with the official ollama package<\/span><\/span>\n<span class=\"l\"><span class=\"k\">import<\/span> <span class=\"n\">ollama<\/span> <span class=\"k\">from<\/span> <span class=\"s\">\"ollama\"<\/span>;<\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"k\">const<\/span> <span class=\"n\">response<\/span> = <span class=\"k\">await<\/span> <span class=\"n\">ollama<\/span>.<span class=\"n\">chat<\/span>({<\/span>\n<span class=\"l\">  <span class=\"n\">model<\/span>: <span class=\"s\">\"llama3.2\"<\/span>,<\/span>\n<span class=\"l\">  <span class=\"n\">messages<\/span>: [<\/span>\n<span class=\"l\">    { <span class=\"n\">role<\/span>: <span class=\"s\">\"system\"<\/span>, <span class=\"n\">content<\/span>: <span class=\"s\">\"You are a friendly coding tutor. Answer in 2 short sentences.\"<\/span> },<\/span>\n<span class=\"l\">    { <span class=\"n\">role<\/span>: <span class=\"s\">\"user\"<\/span>, <span class=\"n\">content<\/span>: <span class=\"s\">\"What is a REST API?\"<\/span> },<\/span>\n<span class=\"l\">  ],<\/span>\n<span class=\"l\">  <span class=\"n\">options<\/span>: { <span class=\"n\">temperature<\/span>: <span class=\"m\">0.2<\/span>, <span class=\"n\">top_p<\/span>: <span class=\"m\">0.9<\/span>, <span class=\"n\">seed<\/span>: <span class=\"m\">42<\/span>, <span class=\"n\">num_ctx<\/span>: <span class=\"m\">4096<\/span>, <span class=\"n\">num_predict<\/span>: <span class=\"m\">120<\/span> },<\/span>\n<span class=\"l\">});<\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"n\">console<\/span>.<span class=\"n\">log<\/span>(<span class=\"n\">response<\/span>.<span class=\"n\">message<\/span>.<span class=\"n\">content<\/span>);<\/span>\n<span class=\"l\"><span class=\"n\">console<\/span>.<span class=\"n\">log<\/span>(<span class=\"s\">\"tokens in:\"<\/span>, <span class=\"n\">response<\/span>.<span class=\"n\">prompt_eval_count<\/span>, <span class=\"s\">\"| tokens out:\"<\/span>, <span class=\"n\">response<\/span>.<span class=\"n\">eval_count<\/span>);<\/span>\n<span class=\"l\"><span class=\"n\">console<\/span>.<span class=\"n\">log<\/span>(<span class=\"s\">`time: ${<\/span>(<span class=\"n\">response<\/span>.<span class=\"n\">total_duration<\/span> \/ <span class=\"m\">1e9<\/span>).<span class=\"n\">toFixed<\/span>(<span class=\"m\">1<\/span>)<span class=\"s\">}s`<\/span>);<\/span><\/code><\/pre>\n<div class=\"dd-vsc-term\"><div class=\"dd-term-head\"><span>TERMINAL<\/span><span>OUTPUT<\/span><span>PROBLEMS<\/span><span class=\"dd-term-note\">Example output \u2013 wording and numbers will differ on your machine<\/span><\/div><pre><code><span class=\"gp\">$<\/span> node chat-local.mjs\nA REST API is a way for programs to talk to each other over HTTP using URLs and methods like GET and POST. For example, an app can send GET \/users to a server and receive the list of users as JSON.\ntokens in: &lt;n&gt; | tokens out: &lt;n&gt;\ntime: &lt;seconds&gt;s<\/code><\/pre><\/div>\n<div class=\"dd-vsc-status\"><span>\u2387 main<\/span><span>Ln 15, Col 1<\/span><span class=\"sp\"><\/span><span>Spaces: 2<\/span><span>UTF-8<\/span><span>LF<\/span><span>JavaScript<\/span><\/div>\n<\/div>\n<\/div>\n<p class=\"dd-vsc-hint\">Switch between the <strong>Python<\/strong> and <strong>Node.js<\/strong> tabs, then click <strong>\u25b6 Run<\/strong> to see the output.<\/p>\n<div class=\"dd-tablewrap\"><table>\n<thead><tr><th>Option<\/th><th>What it controls<\/th><th>Typical value<\/th><\/tr><\/thead>\n<tbody>\n<tr><td><code>temperature<\/code><\/td><td>Randomness (Part 5)<\/td><td>0.2 for facts, 0.8 for ideas<\/td><\/tr>\n<tr><td><code>top_p<\/code> \/ <code>top_k<\/code><\/td><td>Cut unlikely tokens<\/td><td>0.9 \/ 40<\/td><\/tr>\n<tr><td><code>seed<\/code><\/td><td>Same input + same seed = same output<\/td><td>any number, e.g. 42<\/td><\/tr>\n<tr><td><code>num_ctx<\/code><\/td><td>Context window in tokens (more = more memory)<\/td><td>4096\u20138192<\/td><\/tr>\n<tr><td><code>num_predict<\/code><\/td><td>Maximum tokens to generate<\/td><td>128\u20131024<\/td><\/tr>\n<tr><td><code>stop<\/code><\/td><td>Stop sequences<\/td><td><code>[\"\\n\\n\"]<\/code><\/td><\/tr>\n<\/tbody><\/table><\/div>\n<div class=\"dd-warn\"><strong>Watch the context size:<\/strong> Ollama uses a fairly small default context window to save memory. If the model seems to &#8220;forget&#8221; the start of a long document, raise <code>num_ctx<\/code>, but remember that a bigger context uses more RAM.<\/div>\n\n<h2 id=\"streaming\">Streaming answers<\/h2>\n<p>Local models write a few words at a time. Instead of waiting for the full answer, stream it so users see text appear instantly (we will build a full chat UI with streaming in Part 7). Pass <code>stream=True<\/code> and loop over the chunks:<\/p>\n<div class=\"dd-vsc\" role=\"group\" aria-label=\"Code editor: stream_local.py, stream-local.mjs\">\n<input type=\"radio\" name=\"v3\" id=\"v3f1\" class=\"f1\" checked>\n<input type=\"radio\" name=\"v3\" id=\"v3f2\" class=\"f2\">\n<input type=\"checkbox\" id=\"v3r1\" class=\"r1\">\n<input type=\"checkbox\" id=\"v3r2\" class=\"r2\">\n<div class=\"dd-vsc-bar\"><span class=\"dd-dots\"><i><\/i><i><\/i><i><\/i><\/span><span class=\"dd-vsc-title\">2 files \u2014 devdojo-ollama \u2014 Visual Studio Code<\/span><\/div>\n<div class=\"dd-vsc-tabs\">\n<label for=\"v3f1\" class=\"t1\"><b class=\"ic py\">PY<\/b>stream_local.py<\/label>\n<label for=\"v3f2\" class=\"t2\"><b class=\"ic js\">JS<\/b>stream-local.mjs<\/label>\n<label for=\"v3r1\" class=\"run run1\" title=\"Show the output in the terminal\">\u25b6 Run<\/label>\n<label for=\"v3r2\" class=\"run run2\" title=\"Show the output in the terminal\">\u25b6 Run<\/label>\n<\/div>\n<div class=\"dd-vsc-pane p1\">\n<div class=\"dd-vsc-crumbs\">devdojo-ollama \u203a stream_local.py<\/div>\n<pre class=\"dd-vsc-code\"><code><span class=\"l\"><span class=\"c\"># stream_local.py - print the answer word by word as the model writes it<\/span><\/span>\n<span class=\"l\"><span class=\"kn\">from<\/span> <span class=\"n\">ollama<\/span> <span class=\"kn\">import<\/span> <span class=\"n\">chat<\/span><\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"n\">stream<\/span> = <span class=\"n\">chat<\/span>(<\/span>\n<span class=\"l\">    <span class=\"n\">model<\/span>=<span class=\"s\">\"llama3.2\"<\/span>,<\/span>\n<span class=\"l\">    <span class=\"n\">messages<\/span>=[{<span class=\"s\">\"role\"<\/span>: <span class=\"s\">\"user\"<\/span>, <span class=\"s\">\"content\"<\/span>: <span class=\"s\">\"Give me 3 short tips to learn Python.\"<\/span>}],<\/span>\n<span class=\"l\">    <span class=\"n\">stream<\/span>=<span class=\"kc\">True<\/span>,<\/span>\n<span class=\"l\">)<\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"k\">for<\/span> <span class=\"n\">chunk<\/span> in <span class=\"n\">stream<\/span>:<\/span>\n<span class=\"l\">    <span class=\"nb\">print<\/span>(<span class=\"n\">chunk<\/span>.<span class=\"n\">message<\/span>.<span class=\"n\">content<\/span>, <span class=\"n\">end<\/span>=<span class=\"s\">\"\"<\/span>, <span class=\"n\">flush<\/span>=<span class=\"kc\">True<\/span>)<\/span>\n<span class=\"l\"><span class=\"nb\">print<\/span>()<\/span><\/code><\/pre>\n<div class=\"dd-vsc-term\"><div class=\"dd-term-head\"><span>TERMINAL<\/span><span>OUTPUT<\/span><span>PROBLEMS<\/span><span class=\"dd-term-note\">Example output \u2013 wording and numbers will differ on your machine<\/span><\/div><pre><code><span class=\"gp\">$<\/span> python stream_local.py\n1. Practise a little every day, even 20 minutes.\n2. Build small projects like a to-do app or a quiz.\n3. Read other people's code and run it yourself.<\/code><\/pre><\/div>\n<div class=\"dd-vsc-status\"><span>\u2387 main<\/span><span>Ln 12, Col 1<\/span><span class=\"sp\"><\/span><span>Spaces: 4<\/span><span>UTF-8<\/span><span>LF<\/span><span>Python<\/span><\/div>\n<\/div>\n<div class=\"dd-vsc-pane p2\">\n<div class=\"dd-vsc-crumbs\">devdojo-ollama \u203a stream-local.mjs<\/div>\n<pre class=\"dd-vsc-code\"><code><span class=\"l\"><span class=\"c\">\/\/ stream-local.mjs - print the answer word by word as the model writes it<\/span><\/span>\n<span class=\"l\"><span class=\"k\">import<\/span> <span class=\"n\">ollama<\/span> <span class=\"k\">from<\/span> <span class=\"s\">\"ollama\"<\/span>;<\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"k\">const<\/span> <span class=\"n\">stream<\/span> = <span class=\"k\">await<\/span> <span class=\"n\">ollama<\/span>.<span class=\"n\">chat<\/span>({<\/span>\n<span class=\"l\">  <span class=\"n\">model<\/span>: <span class=\"s\">\"llama3.2\"<\/span>,<\/span>\n<span class=\"l\">  <span class=\"n\">messages<\/span>: [{ <span class=\"n\">role<\/span>: <span class=\"s\">\"user\"<\/span>, <span class=\"n\">content<\/span>: <span class=\"s\">\"Give me 3 short tips to learn Python.\"<\/span> }],<\/span>\n<span class=\"l\">  <span class=\"n\">stream<\/span>: <span class=\"kc\">true<\/span>,<\/span>\n<span class=\"l\">});<\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"k\">for<\/span> <span class=\"k\">await<\/span> (<span class=\"k\">const<\/span> <span class=\"n\">part<\/span> <span class=\"k\">of<\/span> <span class=\"n\">stream<\/span>) {<\/span>\n<span class=\"l\">  <span class=\"n\">process<\/span>.<span class=\"n\">stdout<\/span>.<span class=\"n\">write<\/span>(<span class=\"n\">part<\/span>.<span class=\"n\">message<\/span>.<span class=\"n\">content<\/span>);<\/span>\n<span class=\"l\">}<\/span>\n<span class=\"l\"><span class=\"n\">process<\/span>.<span class=\"n\">stdout<\/span>.<span class=\"n\">write<\/span>(<span class=\"s\">\"\\n\"<\/span>);<\/span><\/code><\/pre>\n<div class=\"dd-vsc-term\"><div class=\"dd-term-head\"><span>TERMINAL<\/span><span>OUTPUT<\/span><span>PROBLEMS<\/span><span class=\"dd-term-note\">Example output \u2013 wording and numbers will differ on your machine<\/span><\/div><pre><code><span class=\"gp\">$<\/span> node stream-local.mjs\n1. Practise a little every day, even 20 minutes.\n2. Build small projects like a to-do app or a quiz.\n3. Read other people's code and run it yourself.<\/code><\/pre><\/div>\n<div class=\"dd-vsc-status\"><span>\u2387 main<\/span><span>Ln 13, Col 1<\/span><span class=\"sp\"><\/span><span>Spaces: 2<\/span><span>UTF-8<\/span><span>LF<\/span><span>JavaScript<\/span><\/div>\n<\/div>\n<\/div>\n<p class=\"dd-vsc-hint\">Click <strong>\u25b6 Run<\/strong>; in a real terminal the text appears word by word.<\/p>\n\n<h2 id=\"openai-compatible\">Reuse OpenAI code with a local model<\/h2>\n<p>Already have code written with the OpenAI SDK from Part 3? Ollama speaks the same language at <code>\/v1<\/code>. Change the <code>base_url<\/code>, pass any API key and use a local model name. This is a great way to develop and test for free, then switch to a cloud model in production by changing two lines:<\/p>\n<div class=\"dd-vsc\" role=\"group\" aria-label=\"Code editor: openai_local.py, openai-local.mjs\">\n<input type=\"radio\" name=\"v4\" id=\"v4f1\" class=\"f1\" checked>\n<input type=\"radio\" name=\"v4\" id=\"v4f2\" class=\"f2\">\n<input type=\"checkbox\" id=\"v4r1\" class=\"r1\">\n<input type=\"checkbox\" id=\"v4r2\" class=\"r2\">\n<div class=\"dd-vsc-bar\"><span class=\"dd-dots\"><i><\/i><i><\/i><i><\/i><\/span><span class=\"dd-vsc-title\">2 files \u2014 devdojo-ollama \u2014 Visual Studio Code<\/span><\/div>\n<div class=\"dd-vsc-tabs\">\n<label for=\"v4f1\" class=\"t1\"><b class=\"ic py\">PY<\/b>openai_local.py<\/label>\n<label for=\"v4f2\" class=\"t2\"><b class=\"ic js\">JS<\/b>openai-local.mjs<\/label>\n<label for=\"v4r1\" class=\"run run1\" title=\"Show the output in the terminal\">\u25b6 Run<\/label>\n<label for=\"v4r2\" class=\"run run2\" title=\"Show the output in the terminal\">\u25b6 Run<\/label>\n<\/div>\n<div class=\"dd-vsc-pane p1\">\n<div class=\"dd-vsc-crumbs\">devdojo-ollama \u203a openai_local.py<\/div>\n<pre class=\"dd-vsc-code\"><code><span class=\"l\"><span class=\"c\"># openai_local.py - reuse your OpenAI code from Part 3 with a local model<\/span><\/span>\n<span class=\"l\"><span class=\"kn\">from<\/span> <span class=\"n\">openai<\/span> <span class=\"kn\">import<\/span> <span class=\"n\">OpenAI<\/span><\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"n\">client<\/span> = <span class=\"n\">OpenAI<\/span>(<\/span>\n<span class=\"l\">    <span class=\"n\">base_url<\/span>=<span class=\"s\">\"http:\/\/localhost:11434\/v1\"<\/span>,  <span class=\"c\"># Ollama's OpenAI-compatible API<\/span><\/span>\n<span class=\"l\">    <span class=\"n\">api_key<\/span>=<span class=\"s\">\"ollama\"<\/span>,                      <span class=\"c\"># required by the SDK, ignored by Ollama<\/span><\/span>\n<span class=\"l\">)<\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"n\">response<\/span> = <span class=\"n\">client<\/span>.<span class=\"n\">chat<\/span>.<span class=\"n\">completions<\/span>.<span class=\"n\">create<\/span>(<\/span>\n<span class=\"l\">    <span class=\"n\">model<\/span>=<span class=\"s\">\"llama3.2\"<\/span>,<\/span>\n<span class=\"l\">    <span class=\"n\">messages<\/span>=[{<span class=\"s\">\"role\"<\/span>: <span class=\"s\">\"user\"<\/span>, <span class=\"s\">\"content\"<\/span>: <span class=\"s\">\"Explain JSON to a beginner in one sentence.\"<\/span>}],<\/span>\n<span class=\"l\">    <span class=\"n\">temperature<\/span>=<span class=\"m\">0.2<\/span>,<\/span>\n<span class=\"l\">)<\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"nb\">print<\/span>(<span class=\"n\">response<\/span>.<span class=\"n\">choices<\/span>[<span class=\"m\">0<\/span>].<span class=\"n\">message<\/span>.<span class=\"n\">content<\/span>)<\/span><\/code><\/pre>\n<div class=\"dd-vsc-term\"><div class=\"dd-term-head\"><span>TERMINAL<\/span><span>OUTPUT<\/span><span>PROBLEMS<\/span><span class=\"dd-term-note\">Example output \u2013 wording and numbers will differ on your machine<\/span><\/div><pre><code><span class=\"gp\">$<\/span> python openai_local.py\nJSON is a simple text format for storing data as key-value pairs, like {\"name\": \"Asha\", \"age\": 21}, that almost every programming language can read.<\/code><\/pre><\/div>\n<div class=\"dd-vsc-status\"><span>\u2387 main<\/span><span>Ln 15, Col 1<\/span><span class=\"sp\"><\/span><span>Spaces: 4<\/span><span>UTF-8<\/span><span>LF<\/span><span>Python<\/span><\/div>\n<\/div>\n<div class=\"dd-vsc-pane p2\">\n<div class=\"dd-vsc-crumbs\">devdojo-ollama \u203a openai-local.mjs<\/div>\n<pre class=\"dd-vsc-code\"><code><span class=\"l\"><span class=\"c\">\/\/ openai-local.mjs - reuse your OpenAI code from Part 3 with a local model<\/span><\/span>\n<span class=\"l\"><span class=\"k\">import<\/span> <span class=\"n\">OpenAI<\/span> <span class=\"k\">from<\/span> <span class=\"s\">\"openai\"<\/span>;<\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"k\">const<\/span> <span class=\"n\">client<\/span> = new <span class=\"n\">OpenAI<\/span>({<\/span>\n<span class=\"l\">  <span class=\"n\">baseURL<\/span>: <span class=\"s\">\"http:\/\/localhost:11434\/v1\"<\/span>, <span class=\"c\">\/\/ Ollama's OpenAI-compatible API<\/span><\/span>\n<span class=\"l\">  <span class=\"n\">apiKey<\/span>: <span class=\"s\">\"ollama\"<\/span>,                     <span class=\"c\">\/\/ required by the SDK, ignored by Ollama<\/span><\/span>\n<span class=\"l\">});<\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"k\">const<\/span> <span class=\"n\">response<\/span> = <span class=\"k\">await<\/span> <span class=\"n\">client<\/span>.<span class=\"n\">chat<\/span>.<span class=\"n\">completions<\/span>.<span class=\"n\">create<\/span>({<\/span>\n<span class=\"l\">  <span class=\"n\">model<\/span>: <span class=\"s\">\"llama3.2\"<\/span>,<\/span>\n<span class=\"l\">  <span class=\"n\">messages<\/span>: [{ <span class=\"n\">role<\/span>: <span class=\"s\">\"user\"<\/span>, <span class=\"n\">content<\/span>: <span class=\"s\">\"Explain JSON to a beginner in one sentence.\"<\/span> }],<\/span>\n<span class=\"l\">  <span class=\"n\">temperature<\/span>: <span class=\"m\">0.2<\/span>,<\/span>\n<span class=\"l\">});<\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"n\">console<\/span>.<span class=\"n\">log<\/span>(<span class=\"n\">response<\/span>.<span class=\"n\">choices<\/span>[<span class=\"m\">0<\/span>].<span class=\"n\">message<\/span>.<span class=\"n\">content<\/span>);<\/span><\/code><\/pre>\n<div class=\"dd-vsc-term\"><div class=\"dd-term-head\"><span>TERMINAL<\/span><span>OUTPUT<\/span><span>PROBLEMS<\/span><span class=\"dd-term-note\">Example output \u2013 wording and numbers will differ on your machine<\/span><\/div><pre><code><span class=\"gp\">$<\/span> node openai-local.mjs\nJSON is a simple text format for storing data as key-value pairs, like {\"name\": \"Asha\", \"age\": 21}, that almost every programming language can read.<\/code><\/pre><\/div>\n<div class=\"dd-vsc-status\"><span>\u2387 main<\/span><span>Ln 15, Col 1<\/span><span class=\"sp\"><\/span><span>Spaces: 2<\/span><span>UTF-8<\/span><span>LF<\/span><span>JavaScript<\/span><\/div>\n<\/div>\n<\/div>\n<p class=\"dd-vsc-hint\">Same OpenAI SDK, local model. Compare the two tabs with your Part 3 code.<\/p>\n<div class=\"dd-tip\"><strong>Good pattern:<\/strong> read <code>base_url<\/code>, <code>api_key<\/code> and the model name from environment variables. Then your app runs on Ollama in development and on a cloud model in production without code changes.<\/div>\n<\/div>\n\n\n\n<div class=\"dd-post\">\n<h2 id=\"modelfile\">Build a custom model with a Modelfile<\/h2>\n<p>Typing the same system prompt and settings every time gets boring. A <strong>Modelfile<\/strong> is like a Dockerfile for models: it starts <code>FROM<\/code> a base model and saves your own defaults and personality under a new name. This does not train the model; it packages a prompt and settings so every app gets the same behaviour.<\/p>\n<div class=\"dd-vsc\" role=\"group\" aria-label=\"Code editor: Modelfile\">\n<input type=\"radio\" name=\"v5\" id=\"v5f1\" class=\"f1\" checked>\n<input type=\"checkbox\" id=\"v5r1\" class=\"r1\">\n<div class=\"dd-vsc-bar\"><span class=\"dd-dots\"><i><\/i><i><\/i><i><\/i><\/span><span class=\"dd-vsc-title\">Modelfile \u2014 devdojo-ollama \u2014 Visual Studio Code<\/span><\/div>\n<div class=\"dd-vsc-tabs\">\n<label for=\"v5f1\" class=\"t1\"><b class=\"ic mf\">MF<\/b>Modelfile<\/label>\n<label for=\"v5r1\" class=\"run run1\" title=\"Show the output in the terminal\">\u25b6 Run<\/label>\n<\/div>\n<div class=\"dd-vsc-pane p1\">\n<div class=\"dd-vsc-crumbs\">devdojo-ollama \u203a Modelfile<\/div>\n<pre class=\"dd-vsc-code\"><code><span class=\"l\"><span class=\"c\"># Modelfile - build your own \"DevDojo Tutor\" on top of llama3.2<\/span><\/span>\n<span class=\"l\"><span class=\"k\">FROM<\/span> llama3.2<\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"k\">PARAMETER<\/span> temperature <span class=\"m\">0<\/span>.3<\/span>\n<span class=\"l\"><span class=\"k\">PARAMETER<\/span> num_ctx <span class=\"m\">8192<\/span><\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"k\">SYSTEM<\/span> <span class=\"s\">\"\"\"<\/span><\/span>\n<span class=\"l\"><span class=\"s\">You are DevDojo Tutor. Explain coding ideas to beginners<\/span><\/span>\n<span class=\"l\"><span class=\"s\">in simple English, with one short code example.<\/span><\/span>\n<span class=\"l\"><span class=\"s\">\"\"\"<\/span><\/span><\/code><\/pre>\n<div class=\"dd-vsc-term\"><div class=\"dd-term-head\"><span>TERMINAL<\/span><span>OUTPUT<\/span><span>PROBLEMS<\/span><span class=\"dd-term-note\">Example output \u2013 layer hashes differ<\/span><\/div><pre><code><span class=\"gp\">$<\/span> ollama create devdojo-tutor -f Modelfile\ngathering model components\nusing existing layer sha256:\u2026\ncreating new layer sha256:\u2026\nwriting manifest\nsuccess<\/code><\/pre><\/div>\n<div class=\"dd-vsc-status\"><span>\u2387 main<\/span><span>Ln 10, Col 1<\/span><span class=\"sp\"><\/span><span>Spaces: 4<\/span><span>UTF-8<\/span><span>LF<\/span><span>Modelfile<\/span><\/div>\n<\/div>\n<\/div>\n<p class=\"dd-vsc-hint\">Click <strong>\u25b6 Run<\/strong> to see what <code>ollama create<\/code> prints.<\/p>\n<div class=\"dd-vsc dd-vsc-termonly\" role=\"group\" aria-label=\"Terminal: Terminal \u2014 use your custom model\">\n<div class=\"dd-vsc-bar\"><span class=\"dd-dots\"><i><\/i><i><\/i><i><\/i><\/span><span class=\"dd-vsc-title\">Terminal \u2014 use your custom model<\/span><\/div>\n<pre class=\"dd-vsc-code\"><code><span class=\"l\"><span class=\"gp\">$<\/span> ollama run devdojo-tutor \"What is a variable?\"<\/span>\n<span class=\"l\"><span class=\"c\"># it also works from code: model=\"devdojo-tutor\"<\/span><\/span>\n<span class=\"l\"><span class=\"gp\">$<\/span> ollama list<\/span><\/code><\/pre>\n<\/div>\n\n<h2 id=\"common-errors\">Common errors and fixes<\/h2>\n<div class=\"dd-tablewrap\"><table>\n<thead><tr><th>Problem or error<\/th><th>Likely cause<\/th><th>Fix<\/th><\/tr><\/thead>\n<tbody>\n<tr><td><code>ConnectionError<\/code> \/ <code>ECONNREFUSED 127.0.0.1:11434<\/code><\/td><td>The Ollama server is not running<\/td><td>Open the Ollama app, or run <code>ollama serve<\/code> in a separate terminal.<\/td><\/tr>\n<tr><td><code>model \"llama3.2\" not found, try pulling it first<\/code><\/td><td>The model is not downloaded or the name\/tag is wrong<\/td><td>Run <code>ollama pull llama3.2<\/code> and check names with <code>ollama list<\/code>.<\/td><\/tr>\n<tr><td><code>model requires more system memory than is available<\/code><\/td><td>Model too big for your RAM<\/td><td>Use a smaller tag (e.g. <code>llama3.2:1b<\/code>), close other apps or lower <code>num_ctx<\/code>.<\/td><\/tr>\n<tr><td>Answers are very slow (one word per second)<\/td><td>Model running on CPU or partly swapped<\/td><td>Check <code>ollama ps<\/code>; pick a smaller model so it fits in GPU\/unified memory.<\/td><\/tr>\n<tr><td>Model forgets the start of a long text<\/td><td>Context window too small<\/td><td>Raise <code>num_ctx<\/code> in options or in a Modelfile.<\/td><\/tr>\n<tr><td>Another device on your network cannot connect<\/td><td>Ollama listens only on localhost by default<\/td><td>Set <code>OLLAMA_HOST=0.0.0.0<\/code> only on a trusted network and protect the port.<\/td><\/tr>\n<tr><td>OpenAI SDK error: missing API key<\/td><td>The SDK requires a key even for local use<\/td><td>Pass any string, e.g. <code>api_key=\"ollama\"<\/code>.<\/td><\/tr>\n<\/tbody><\/table><\/div>\n\n<h2 id=\"best-practices\">Best practices<\/h2>\n<ul>\n<li><strong>Start small, scale up.<\/strong> Begin with a 1\u20134B model, check that answers are good enough, and only then try a bigger one.<\/li>\n<li><strong>Pin model tags<\/strong> in your code (for example <code>llama3.2:3b<\/code>), so an update to the default tag does not silently change your app.<\/li>\n<li><strong>Set a seed and low temperature<\/strong> for tests, so the same prompt gives the same answer on your machine.<\/li>\n<li><strong>Keep the server private.<\/strong> Port 11434 has no login, so never expose it to the internet without a proxy and authentication.<\/li>\n<li><strong>Use the OpenAI-compatible API<\/strong> plus environment variables, so you can switch between local and cloud models easily.<\/li>\n<li><strong>Check the licence<\/strong> of each open model before using it in a paid product.<\/li>\n<li><strong>Watch disk space.<\/strong> Models are big; remove old ones with <code>ollama rm<\/code>.<\/li>\n<\/ul>\n\n<h2 id=\"practice\">Practice task<\/h2>\n<p>Build a tiny &#8220;local model showdown&#8221;:<\/p>\n<ol>\n<li>Pull two models that fit your RAM (for example <code>llama3.2:1b<\/code> and <code>llama3.2<\/code>).<\/li>\n<li>Extend <code>chat_local.py<\/code> to loop over both models and ask the same three questions with <code>seed=42<\/code> and <code>temperature=0.2<\/code>.<\/li>\n<li>Print each answer with <code>eval_count<\/code> and speed in tokens per second (<code>eval_count \/ (eval_duration \/ 1e9)<\/code>).<\/li>\n<li>Create a Modelfile for a &#8220;Git helper&#8221; that only answers Git questions, then test it with <code>ollama run<\/code>.<\/li>\n<li>Point your OpenAI code from Part 3 at Ollama using environment variables and run it without an API key.<\/li>\n<\/ol>\n<div class=\"dd-tip\"><strong>Bonus:<\/strong> share your tokens-per-second results and laptop model in the comments, so other readers know what to expect.<\/div>\n\n<h2 id=\"faq\">FAQ: running LLMs locally with Ollama<\/h2>\n<details><summary>Is Ollama free?<\/summary><p>Yes. Ollama itself is free and open source, and the models in its library are free to download. Each model has its own licence, so check it for commercial use.<\/p><\/details>\n<details><summary>Can I run Ollama without a GPU?<\/summary><p>Yes. Ollama runs on the CPU too. Small models (1\u20134B) work fine on most laptops with 8 GB of RAM; a GPU or Apple Silicon simply makes everything faster.<\/p><\/details>\n<details><summary>Does Ollama send my data to the internet?<\/summary><p>No. When you run a local model, prompts and answers stay on your computer. Internet is needed only to download Ollama and the models.<\/p><\/details>\n<details><summary>Which is the best model for a beginner?<\/summary><p>Start with <code>llama3.2<\/code> (3B) on an 8 GB machine or an 8B model such as <code>qwen3:8b<\/code> or <code>llama3.1:8b<\/code> on 16 GB. Then try others from the library and compare.<\/p><\/details>\n<details><summary>Can I use Ollama with LangChain or other tools?<\/summary><p>Yes. Most AI frameworks, editors and chat apps support Ollama directly or through its OpenAI-compatible API, which we will use in later parts of this series.<\/p><\/details>\n<details><summary>Where are the model files stored?<\/summary><p>By default in <code>~\/.ollama\/models<\/code> on macOS and Linux and in your user folder on Windows. You can change the location with the <code>OLLAMA_MODELS<\/code> environment variable.<\/p><\/details>\n\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>You can now run LLMs locally with Ollama: install it, pull an open model that fits your computer, chat in the terminal, call it from Python and Node.js, stream answers, reuse your OpenAI code by changing the base URL and package your own assistant with a Modelfile. Local models will not replace the biggest cloud models for every task, but they are perfect for learning, privacy-sensitive work and free experiments. For every command and option, keep the <a href=\"https:\/\/docs.ollama.com\/\" target=\"_blank\" rel=\"noopener\">official Ollama documentation<\/a> handy.<\/p>\n<p>Missed the previous part? Read <a href=\"https:\/\/devdojo.co.in\/?p=244\">Part 5: Temperature, Top-p and Controlling Model Output<\/a>. Want to build something bigger with LLMs? Try our <a href=\"https:\/\/devdojo.co.in\/?p=198\">RAG tutorial with Python and pgvector<\/a>.<\/p>\n\n<div class=\"dd-next\"><strong>Next part \u2013 Generative AI Part 7: Streaming Responses and Building a Simple Chat UI.<\/strong> Turn the streaming code from today into a real chat app with a web interface that shows answers word by word, works with both local and cloud models and remembers the conversation.<\/div>\n\n<div class=\"dd-cta\">\n<h3>New posts every day on DevDojo<\/h3>\n<p>Follow the full <strong>Generative AI series<\/strong> \u2013 30 parts from &#8220;what is an LLM&#8221; to building a production AI assistant. Bookmark <a href=\"https:\/\/devdojo.co.in\/\">devdojo.co.in<\/a> and tell us in the comments which local model you liked most.<\/p>\n<\/div>\n<\/div>\n\n","protected":false},"excerpt":{"rendered":"<p>Learn to run LLMs locally with Ollama: install it, pull open models, chat in the terminal and call them from Python and Node.js. Free, private and offline.<\/p>\n","protected":false},"author":1,"featured_media":280,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38],"tags":[113,44,147,43,115,52,112],"class_list":["post-281","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ai","tag-generative-ai","tag-llm","tag-local-llm","tag-node-js","tag-ollama","tag-python","tag-series-generative-ai"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.4 - aioseo.com -->\n\t<meta name=\"description\" content=\"Learn to run LLMs locally with Ollama: install it, pull open models, chat in the terminal and call them from Python and Node.js. Free, private and offline.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Lokendra\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/devdojo.co.in\/index.php\/2026\/11\/01\/genai-series-part-6-run-llms-locally-ollama\/\" \/>\n\t\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.4\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"DevDojo - Empowering Developers\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Run LLMs Locally with Ollama: Generative AI Part 6\" \/>\n\t\t<meta property=\"og:description\" content=\"Learn to run LLMs locally with Ollama: install it, pull open models, chat in the terminal and call them from Python and Node.js. Free, private and offline.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/devdojo.co.in\/index.php\/2026\/11\/01\/genai-series-part-6-run-llms-locally-ollama\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2026-11-01T13:04:09+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2026-11-01T13:04:09+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Run LLMs Locally with Ollama: Generative AI Part 6\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Learn to run LLMs locally with Ollama: install it, pull open models, chat in the terminal and call them from Python and Node.js. Free, private and offline.\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"BlogPosting\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/2026\\\/11\\\/01\\\/genai-series-part-6-run-llms-locally-ollama\\\/#blogposting\",\"name\":\"Run LLMs Locally with Ollama: GenAI Part 6\",\"headline\":\"Generative AI Part 6: How to Run LLMs Locally with Ollama\",\"author\":{\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/author\\\/lokendra\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/devdojo.co.in\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/genai-series-part-6-run-llms-locally-ollama.jpg\",\"width\":1200,\"height\":630,\"caption\":\"Generative AI Part 6 banner: run LLMs locally with Ollama on localhost:11434 from the terminal, Python and Node.js\"},\"datePublished\":\"2026-11-01T13:04:09+00:00\",\"dateModified\":\"2026-11-01T13:04:09+00:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/2026\\\/11\\\/01\\\/genai-series-part-6-run-llms-locally-ollama\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/2026\\\/11\\\/01\\\/genai-series-part-6-run-llms-locally-ollama\\\/#webpage\"},\"articleSection\":\"AI, Generative AI, LLM, Local LLM, Node.js, Ollama, Python, Series: Generative AI\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/2026\\\/11\\\/01\\\/genai-series-part-6-run-llms-locally-ollama\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/devdojo.co.in\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/category\\\/ai\\\/#listItem\",\"name\":\"AI\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/category\\\/ai\\\/#listItem\",\"position\":2,\"name\":\"AI\",\"item\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/category\\\/ai\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/2026\\\/11\\\/01\\\/genai-series-part-6-run-llms-locally-ollama\\\/#listItem\",\"name\":\"Generative AI Part 6: How to Run LLMs Locally with Ollama\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/2026\\\/11\\\/01\\\/genai-series-part-6-run-llms-locally-ollama\\\/#listItem\",\"position\":3,\"name\":\"Generative AI Part 6: How to Run LLMs Locally with Ollama\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/category\\\/ai\\\/#listItem\",\"name\":\"AI\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/#organization\",\"name\":\"DevDojo\",\"description\":\"Empowering Developers\",\"url\":\"https:\\\/\\\/devdojo.co.in\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/author\\\/lokendra\\\/#author\",\"url\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/author\\\/lokendra\\\/\",\"name\":\"Lokendra\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/2026\\\/11\\\/01\\\/genai-series-part-6-run-llms-locally-ollama\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/99f102f0cc9080237ce54b91304fd1b3b6fa29925cbaeba93cd796872e58b45c?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Lokendra\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/2026\\\/11\\\/01\\\/genai-series-part-6-run-llms-locally-ollama\\\/#webpage\",\"url\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/2026\\\/11\\\/01\\\/genai-series-part-6-run-llms-locally-ollama\\\/\",\"name\":\"Run LLMs Locally with Ollama: GenAI Part 6\",\"description\":\"Learn to run LLMs locally with Ollama: install it, pull open models, chat in the terminal and call them from Python and Node.js. Free, private and offline.\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/2026\\\/11\\\/01\\\/genai-series-part-6-run-llms-locally-ollama\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/author\\\/lokendra\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/author\\\/lokendra\\\/#author\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/devdojo.co.in\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/genai-series-part-6-run-llms-locally-ollama.jpg\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/2026\\\/11\\\/01\\\/genai-series-part-6-run-llms-locally-ollama\\\/#mainImage\",\"width\":1200,\"height\":630,\"caption\":\"Generative AI Part 6 banner: run LLMs locally with Ollama on localhost:11434 from the terminal, Python and Node.js\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/2026\\\/11\\\/01\\\/genai-series-part-6-run-llms-locally-ollama\\\/#mainImage\"},\"datePublished\":\"2026-11-01T13:04:09+00:00\",\"dateModified\":\"2026-11-01T13:04:09+00:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/#website\",\"url\":\"https:\\\/\\\/devdojo.co.in\\\/\",\"name\":\"DevDojo\",\"description\":\"Empowering Developers\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Run LLMs Locally with Ollama: GenAI Part 6","description":"Learn to run LLMs locally with Ollama: install it, pull open models, chat in the terminal and call them from Python and Node.js. Free, private and offline.","canonical_url":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/01\/genai-series-part-6-run-llms-locally-ollama\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"BlogPosting","@id":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/01\/genai-series-part-6-run-llms-locally-ollama\/#blogposting","name":"Run LLMs Locally with Ollama: GenAI Part 6","headline":"Generative AI Part 6: How to Run LLMs Locally with Ollama","author":{"@id":"https:\/\/devdojo.co.in\/index.php\/author\/lokendra\/#author"},"publisher":{"@id":"https:\/\/devdojo.co.in\/#organization"},"image":{"@type":"ImageObject","url":"https:\/\/devdojo.co.in\/wp-content\/uploads\/2026\/11\/genai-series-part-6-run-llms-locally-ollama.jpg","width":1200,"height":630,"caption":"Generative AI Part 6 banner: run LLMs locally with Ollama on localhost:11434 from the terminal, Python and Node.js"},"datePublished":"2026-11-01T13:04:09+00:00","dateModified":"2026-11-01T13:04:09+00:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/01\/genai-series-part-6-run-llms-locally-ollama\/#webpage"},"isPartOf":{"@id":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/01\/genai-series-part-6-run-llms-locally-ollama\/#webpage"},"articleSection":"AI, Generative AI, LLM, Local LLM, Node.js, Ollama, Python, Series: Generative AI"},{"@type":"BreadcrumbList","@id":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/01\/genai-series-part-6-run-llms-locally-ollama\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/devdojo.co.in\/#listItem","position":1,"name":"Home","item":"https:\/\/devdojo.co.in\/","nextItem":{"@type":"ListItem","@id":"https:\/\/devdojo.co.in\/index.php\/category\/ai\/#listItem","name":"AI"}},{"@type":"ListItem","@id":"https:\/\/devdojo.co.in\/index.php\/category\/ai\/#listItem","position":2,"name":"AI","item":"https:\/\/devdojo.co.in\/index.php\/category\/ai\/","nextItem":{"@type":"ListItem","@id":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/01\/genai-series-part-6-run-llms-locally-ollama\/#listItem","name":"Generative AI Part 6: How to Run LLMs Locally with Ollama"},"previousItem":{"@type":"ListItem","@id":"https:\/\/devdojo.co.in\/#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/01\/genai-series-part-6-run-llms-locally-ollama\/#listItem","position":3,"name":"Generative AI Part 6: How to Run LLMs Locally with Ollama","previousItem":{"@type":"ListItem","@id":"https:\/\/devdojo.co.in\/index.php\/category\/ai\/#listItem","name":"AI"}}]},{"@type":"Organization","@id":"https:\/\/devdojo.co.in\/#organization","name":"DevDojo","description":"Empowering Developers","url":"https:\/\/devdojo.co.in\/"},{"@type":"Person","@id":"https:\/\/devdojo.co.in\/index.php\/author\/lokendra\/#author","url":"https:\/\/devdojo.co.in\/index.php\/author\/lokendra\/","name":"Lokendra","image":{"@type":"ImageObject","@id":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/01\/genai-series-part-6-run-llms-locally-ollama\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/99f102f0cc9080237ce54b91304fd1b3b6fa29925cbaeba93cd796872e58b45c?s=96&d=mm&r=g","width":96,"height":96,"caption":"Lokendra"}},{"@type":"WebPage","@id":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/01\/genai-series-part-6-run-llms-locally-ollama\/#webpage","url":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/01\/genai-series-part-6-run-llms-locally-ollama\/","name":"Run LLMs Locally with Ollama: GenAI Part 6","description":"Learn to run LLMs locally with Ollama: install it, pull open models, chat in the terminal and call them from Python and Node.js. Free, private and offline.","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/devdojo.co.in\/#website"},"breadcrumb":{"@id":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/01\/genai-series-part-6-run-llms-locally-ollama\/#breadcrumblist"},"author":{"@id":"https:\/\/devdojo.co.in\/index.php\/author\/lokendra\/#author"},"creator":{"@id":"https:\/\/devdojo.co.in\/index.php\/author\/lokendra\/#author"},"image":{"@type":"ImageObject","url":"https:\/\/devdojo.co.in\/wp-content\/uploads\/2026\/11\/genai-series-part-6-run-llms-locally-ollama.jpg","@id":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/01\/genai-series-part-6-run-llms-locally-ollama\/#mainImage","width":1200,"height":630,"caption":"Generative AI Part 6 banner: run LLMs locally with Ollama on localhost:11434 from the terminal, Python and Node.js"},"primaryImageOfPage":{"@id":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/01\/genai-series-part-6-run-llms-locally-ollama\/#mainImage"},"datePublished":"2026-11-01T13:04:09+00:00","dateModified":"2026-11-01T13:04:09+00:00"},{"@type":"WebSite","@id":"https:\/\/devdojo.co.in\/#website","url":"https:\/\/devdojo.co.in\/","name":"DevDojo","description":"Empowering Developers","inLanguage":"en-US","publisher":{"@id":"https:\/\/devdojo.co.in\/#organization"}}]},"og:locale":"en_US","og:site_name":"DevDojo - Empowering Developers","og:type":"article","og:title":"Run LLMs Locally with Ollama: Generative AI Part 6","og:description":"Learn to run LLMs locally with Ollama: install it, pull open models, chat in the terminal and call them from Python and Node.js. Free, private and offline.","og:url":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/01\/genai-series-part-6-run-llms-locally-ollama\/","article:published_time":"2026-11-01T13:04:09+00:00","article:modified_time":"2026-11-01T13:04:09+00:00","twitter:card":"summary_large_image","twitter:title":"Run LLMs Locally with Ollama: Generative AI Part 6","twitter:description":"Learn to run LLMs locally with Ollama: install it, pull open models, chat in the terminal and call them from Python and Node.js. Free, private and offline."},"aioseo_meta_data":{"post_id":"281","title":"Run LLMs Locally with Ollama: GenAI Part 6","description":"Learn to run LLMs locally with Ollama: install it, pull open models, chat in the terminal and call them from Python and Node.js. Free, private and offline.","keywords":null,"keyphrases":{"focus":{"keyphrase":"run LLMs locally with Ollama","score":74},"additional":[]},"primary_term":null,"canonical_url":null,"og_title":"Run LLMs Locally with Ollama: Generative AI Part 6","og_description":"Learn to run LLMs locally with Ollama: install it, pull open models, chat in the terminal and call them from Python and Node.js. Free, private and offline.","og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"BlogPosting","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":0,"frequency":"default","local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":{"faqs":[],"keyPoints":[],"schemas":[],"titles":[],"descriptions":[],"socialPosts":{"email":{"subject":"","preview":"","content":""},"linkedin":[],"twitter":[],"facebook":[],"instagram":[]}},"created":"2026-11-01 13:00:25","updated":"2026-11-01 13:04:09","focus_keyword":"run LLMs locally with Ollama","additional_keywords":null,"truseo_locale":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/devdojo.co.in\/\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/devdojo.co.in\/index.php\/category\/ai\/\" title=\"AI\">AI<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tGenerative AI Part 6: How to Run LLMs Locally with Ollama\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/devdojo.co.in\/"},{"label":"AI","link":"https:\/\/devdojo.co.in\/index.php\/category\/ai\/"},{"label":"Generative AI Part 6: How to Run LLMs Locally with Ollama","link":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/01\/genai-series-part-6-run-llms-locally-ollama\/"}],"_links":{"self":[{"href":"https:\/\/devdojo.co.in\/index.php\/wp-json\/wp\/v2\/posts\/281","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devdojo.co.in\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devdojo.co.in\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devdojo.co.in\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/devdojo.co.in\/index.php\/wp-json\/wp\/v2\/comments?post=281"}],"version-history":[{"count":1,"href":"https:\/\/devdojo.co.in\/index.php\/wp-json\/wp\/v2\/posts\/281\/revisions"}],"predecessor-version":[{"id":282,"href":"https:\/\/devdojo.co.in\/index.php\/wp-json\/wp\/v2\/posts\/281\/revisions\/282"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devdojo.co.in\/index.php\/wp-json\/wp\/v2\/media\/280"}],"wp:attachment":[{"href":"https:\/\/devdojo.co.in\/index.php\/wp-json\/wp\/v2\/media?parent=281"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devdojo.co.in\/index.php\/wp-json\/wp\/v2\/categories?post=281"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devdojo.co.in\/index.php\/wp-json\/wp\/v2\/tags?post=281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}