<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/add-a-local-llm-without-making-your-app-depend-on-it-jkij2yytc" -->

---
title: Add a local LLM without making your app depend on it
description: A pattern for integrating a local Ollama LLM into a Swift app so the app never depends on it: define a small NarrativeEngine protocol so the app is decoupled...
canonical: https://daily.dev/posts/add-a-local-llm-without-making-your-app-depend-on-it-jkij2yytc
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Add a local LLM without making your app depend on it | daily.dev
og:description: A pattern for integrating a local Ollama LLM into a Swift app so the app never depends on it: define a small NarrativeEngine protocol so the app is decoupled...
og:url: https://daily.dev/posts/add-a-local-llm-without-making-your-app-depend-on-it-jkij2yytc
og:image: https://api.daily.dev/og/posts/jkij2Yytc.png
og:image:alt: Add a local LLM without making your app depend on it
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Add a local LLM without making your app depend on it

**[Flavio Copes](https://daily.dev/sources/flaviocopes)** · 8 min read · 0 upvotes · 0 comments

## Summary

A pattern for integrating a local Ollama LLM into a Swift app so the app never depends on it: define a small NarrativeEngine protocol so the app is decoupled from the specific model backend, use a short 2-second health check against Ollama's /api/tags endpoint separate from a longer 90-second generation timeout, return nil instead of throwing when generation fails so the UI falls back to a plain factual summary, back off retries for 60 seconds after a failure to avoid hammering a down service, generate summaries lazily per visible row and cache them by a content signature hash for free invalidation, and keep all factual computation in code so the model only rephrases pre-computed facts rather than inferring them.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://flaviocopes.com/optional-local-llm-swift-app>

## Questions this post answers

### How do I add an optional Ollama-powered feature to a Swift app without breaking it when Ollama isn't installed?

Define a small protocol like NarrativeEngine with isAvailable() and write() methods so the app depends on an abstraction rather than Ollama directly. Check availability with a short 2-second timeout against Ollama's api/tags endpoint, and have the orchestration layer return an optional String (nil on failure) so the view falls back to factual data instead of showing an error.

_Developers wiring optional local AI into apps track patterns like circuit breakers and caching on daily.dev._

### What timeout should I use for an Ollama health check versus actual text generation?

Use a short timeout, around 2 seconds, for the health check against Ollama's api/tags endpoint, since a service on 127.0.0.1 either responds instantly or refuses the connection in milliseconds. Use a much longer timeout, around 90 seconds, for the actual generation request via api/generate, since a local model like gemma3:4b can take significantly longer to produce a response, especially on slower machines.

_Anyone tuning local LLM UX in production apps can find similar implementation details on daily.dev._

### How can I avoid Ollama getting hammered with repeated failed requests when it's down?

Implement a simple circuit breaker: record a timestamp when a health check fails, and skip re-checking Ollama for a fixed retry delay (60 seconds) afterward, returning unavailable immediately instead. Once the delay passes, the next check tries again, so the service quietly resumes working if the user starts Ollama in the meantime without users seeing errors or repeated timeouts.

_daily.dev surfaces practical resilience patterns like this for developers building against flaky local services._

## Similar posts on daily.dev

- [How to Protect Sensitive Data by Running LLMs Locally with Ollama](https://daily.dev/posts/how-to-protect-sensitive-data-by-running-llms-locally-with-ollama-krjyxqjkt) · freeCodeCamp · 2 upvotes · 0 comments
- [I connected my local LLM to my browser and it changed how I automated tasks](https://daily.dev/posts/i-connected-my-local-llm-to-my-browser-and-it-changed-how-i-automated-tasks-2bzoh9ji6) · XDA Developers · 0 upvotes · 0 comments
- [Integrating LLMs with Ollama and Spring AI](https://daily.dev/posts/integrating-llms-with-ollama-and-spring-ai-ftjw4akn6) · codecentric · 0 upvotes · 0 comments
- [AI For The Skeptics: Attempting To Do Something Useful With It](https://daily.dev/posts/ai-for-the-skeptics-attempting-to-do-something-useful-with-it-atvi3r9su) · Hackaday · 0 upvotes · 0 comments
- [Don’t Use Ollama for Local LLMs](https://daily.dev/posts/don-t-use-ollama-for-local-llms-szl4snpls) · Medium · 0 upvotes · 0 comments

---

Tags: [#testing](https://daily.dev/tags/testing), [#architecture](https://daily.dev/tags/architecture), [#swift](https://daily.dev/tags/swift), [#local-ai](https://daily.dev/tags/local-ai), [#ollama](https://daily.dev/tags/ollama)

[View this post on daily.dev](https://daily.dev/posts/add-a-local-llm-without-making-your-app-depend-on-it-jkij2yytc)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Add a local LLM without making your app depend on it","url":"https://daily.dev/posts/add-a-local-llm-without-making-your-app-depend-on-it-jkij2yytc","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/add-a-local-llm-without-making-your-app-depend-on-it-jkij2yytc"},"datePublished":"2026-08-16T13:37:18.111Z","dateModified":"2026-09-14T07:17:31.338Z","description":"A pattern for integrating a local Ollama LLM into a Swift app so the app never depends on it: define a small NarrativeEngine protocol so the app is decoupled...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/7219243bb6b6113ecc90bd933965a4ef?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/7219243bb6b6113ecc90bd933965a4ef?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Flavio Copes","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Flavio Copes","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/1f2dbd275797411bbd37bfdaaf0951a9","url":"https://daily.dev/sources/flaviocopes"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/add-a-local-llm-without-making-your-app-depend-on-it-jkij2yytc","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"testing,architecture,swift,local-ai,ollama","timeRequired":"PT8M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Flavio Copes","item":"https://daily.dev/sources/flaviocopes"},{"@type":"ListItem","position":3,"name":"Add a local LLM without making your app depend on it"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/add-a-local-llm-without-making-your-app-depend-on-it-jkij2yytc#faq","mainEntity":[{"@type":"Question","name":"How do I add an optional Ollama-powered feature to a Swift app without breaking it when Ollama isn't installed?","acceptedAnswer":{"@type":"Answer","text":"Define a small protocol like NarrativeEngine with isAvailable() and write() methods so the app depends on an abstraction rather than Ollama directly. Check availability with a short 2-second timeout against Ollama's api/tags endpoint, and have the orchestration layer return an optional String (nil on failure) so the view falls back to factual data instead of showing an error. Developers wiring optional local AI into apps track patterns like circuit breakers and caching on daily.dev."}},{"@type":"Question","name":"What timeout should I use for an Ollama health check versus actual text generation?","acceptedAnswer":{"@type":"Answer","text":"Use a short timeout, around 2 seconds, for the health check against Ollama's api/tags endpoint, since a service on 127.0.0.1 either responds instantly or refuses the connection in milliseconds. Use a much longer timeout, around 90 seconds, for the actual generation request via api/generate, since a local model like gemma3:4b can take significantly longer to produce a response, especially on slower machines. Anyone tuning local LLM UX in production apps can find similar implementation details on daily.dev."}},{"@type":"Question","name":"How can I avoid Ollama getting hammered with repeated failed requests when it's down?","acceptedAnswer":{"@type":"Answer","text":"Implement a simple circuit breaker: record a timestamp when a health check fails, and skip re-checking Ollama for a fixed retry delay (60 seconds) afterward, returning unavailable immediately instead. Once the delay passes, the next check tries again, so the service quietly resumes working if the user starts Ollama in the meantime without users seeing errors or repeated timeouts. daily.dev surfaces practical resilience patterns like this for developers building against flaky local services."}}]}
```

