Running on your laptop
local graph
Chapter 12 — Running on your laptop
Section titled “Chapter 12 — Running on your laptop”12 Running on your laptop
This chapter covers:
- Reasons for using a personal, local SLM-based assistant
- Using Ollama’s server to run SLMs locally and offline
- Using the LM Studio desktop app to run SLMs locally and offline
- Using the Jan assistant app to run SLMs locally and offline
In chapter 11, we looked at frameworks for serving private, domain-specific SLMs behind endpoints at scale for client applications, as well as options for running SLMs on edge devices, such as resource-constrained Android phones. This chapter explores ways to run personal SLM-based assistants or productivity tools directly on a laptop, including completely offline.
12.1 Why use a personal local assistant
Section titled “12.1 Why use a personal local assistant”Platforms that expose commercial LLMs through a chat interface or API—such as those from OpenAI, xAI, Anthropic, and Google—can learn about their users in ways we can’t fully realize. They collect data from user interactions and turn that information into assets. Even when platforms let users opt out of data collection or the use of prompts, generated responses, and other sensitive data for model tuning, their closed nature makes it hard to know how consistently those choices are honored. This matters because information can be unintentionally exposed, not only through third-party chat systems and APIs, but also via client laptops and smartphones connected to the internet. This is critical not only at the enterprise level, but also for personal use. LLMs can boost productivity, but privacy and safety concerns can’t be ignored.
Fortunately, as you’ve seen in earlier chapters, there are alternatives to third-party online models and services, both for individuals who want private AI assistants and for companies that need secure tools for employees. These alternatives extend beyond open source small language models; there are also ways to serve models on a user’s laptop and higher-level tools to interact with them.
This chapter explores options for running SLMs locally, safely, and offline on a laptop using only open source components. This doesn’t just apply to running chatbots but also to running SLMs for broader tasks, including complex systems such as RAG applications.
12.2 Running an LLM locally with Ollama
Section titled “12.2 Running an LLM locally with Ollama”We’ll start with Ollama (https://ollama.com/), an application based on llama.cpp (a C/C++ library introduced in chapter 6) that lets you interact with LLMs on your local computer. You can use any community-created GGUF-format quantized model available on the Hugging Face Hub (at the time of writing, more than 45,000 are hosted there). You can also convert your own models to the format Ollama expects, as explained later in this section. Ollama bundles model weights, configuration, and data into a single package defined by a Modelfile, and it optimizes setup details, including GPU usage.
Installing Ollama is straightforward: download the version for your operating system (Windows, macOS, or Linux) from the official website. A Docker image, ollama/ollama, is also available on Docker Hub. Once installed, Ollama exposes an API that serves the model, so users can interact with it locally, either directly or through a client application.
To run a model, use the run command in a terminal. If the model isn’t installed yet, Ollama downloads it first. You can browse the long list of available models on the Ollama website (see figure 12.1).
The list includes not only text models but also vision, multimodal, and embedding models. For example, to run the DeepSeek-R1 8B model, use the following command:
ollama run deepseek-r1:8BDiscord GitHub Models Search models
All Embedding Vision Tools Popular
deepseek-r1 DeepSeek’s first-generation of reasoning models with comparable performance to OpenAI-o1, including six dense models distilled from DeepSeek-R1 based on Llama and Qwen.
1.5b 7b 8b 14b 32b 70b 671b ↓ 21.6M Pulls ⚙️ 29 Tags ⏳ Updated 3 weeks ago
llama3.3 New state of the art 70B model. Llama 3.3 70B offers similar performance compared to the Llama 3.1 405B model.
tools 70b ↓ 1.4M Pulls ⚙️ 14 Tags ⏳ Updated 2 months ago
phi4 Phi-4 is a 14B parameter, state-of-the-art open model from Microsoft.
14b ↓ 809.6K Pulls ⚙️ 5 Tags ⏳ Updated 7 weeks ago
llama3.2 Meta’s Llama 3.2 goes small with 1B and 3B models.
Figure 12.1 Ollama’s online model catalog
The first time you run a model with run, Ollama downloads it from the Ollama repo. Subsequent runs start the CLI chat immediately. Figure 12.2 shows an active chat session with the DeepSeek-R1 8B model on macOS.
All the models in the Ollama repository are quantized, which reduces memory and compute requirements compared to the originals. Many can run on a laptop without hardware acceleration because they’re optimized for CPUs (assuming you have enough RAM). As a rule of thumb, you’ll typically need at least 8 GB of RAM for 7B or 8B models , 14 to 16 GB for 13B models, and 32 GB for 33B models.
If a model isn’t in the Ollama catalog but is hosted on the Hugging Face Hub, you can still use the run command to download and run it locally. Just provide the model’s Hub URL:
ollama run hf.co/mlabonne/Meta-Llama-3.1-8B-Instruct-abliterated-GGUF[redacted] — ollama run deepseek-r1:8b — 80×24[redacted] ~ % ollama run deepseek-r1:8b>>> Generate a Python function that takes a list of integers as input and return... s the sum of all even numbers in the list.<think>I need to write a Python function called sum_even_numbers that takes alist of integers as its parameter.
The goal is to return the sum of all the even numbers within this list.
First, I'll initialize a variable to keep track of the total sum. It's agood idea to start with a value of 0 since adding even numbers willincrement the sum correctly.
Next, I'll iterate through each number in the input list using a for loop.
For each number, I'll check if it's even by seeing if it's divisible by 2without any remainder. This can be done using the modulo operator: if num% 2 == 0.
If a number is even, I'll add its value to the total sum.
After processing all numbers in the list, the function will return theaccumulated sum.[!visual-conversion] Figure 12.2 — A live local chat session with the DeepSeek-R1 8B model through Ollama on macOS (p. 250)
To list the models installed in your local Ollama instance, run the following command in a terminal:
ollama listIt will print out a list, as follows:
| NAME | ID | SIZE | MODIFIED |
|---|---|---|---|
| deepseek-r1:8b | 28f8fd6cdc67 | 4.9 GB | 4 weeks ago |
| mistral:latest | f974a74358d6 | 4.1 GB | 6 weeks ago |
Ollama can serve multiple models at the same time, though the chat and inference speed will depend on your laptop’s hardware. To remove models you no longer need, delete them with rm, using the model name shown in the online catalog and in your local list:
ollama rm mistral:latestOllama also includes a REST API for running inference on locally installed models from a client application. Its default listening port is 11434. The /api/tags endpoint accepts HTTP GET requests and returns the list of installed models, such as the CLI list command:
{"models": [{"name": "deepseek-r1:8b", "model": "deepseek-r1:8b", "modified_at": "2025-01-28T18:38:42.09260284Z", "size": 4920738407, "digest": "28f8fd6cdc677661426adab9338ce3c013d7e69a5bea9e704b364171a5d61a10", "details": {"parent_model": "", "format": "gguf", "family": "llama", "families": ["llama"], "parameter_size": "8.0B", "quantization_level": "Q4_K_M"}, {"name": "mistral:latest", "model": "mistral:latest", "modified_at": "2025-01-18T15:41:59.669938897Z", "size": 4113301824, "digest": "f974a74358d62a017b37c6f424fcdf2744ca02926c4f952513ddf474b2fa5091", "details": {"parent_model": "", "format": "gguf", "family": "llama", "families": ["llama"], "parameter_size": "7.2B", "quantization_level": "Q4_0"}}]}POST requests to other endpoints let client applications perform any CLI operation, including chat completions. Here’s an example request to a local Mistral 7B model served through Ollama:
curl http://localhost:11434/api/chat -d '{ "model": "mistral:latest", "messages": [ { "role": "user", "content": "why is the sky blue?" } ]}'So far, we’ve seen SLMs served through Ollama from the CLI, which is a suitable option for users with a strong technical background. To make running SLMs locally accessible to more people, the Ollama open source community has developed an ecosystem of visual client applications. The official Ollama GitHub repository (https://github.com/ollama/ollama) maintains an up-to-date list. Which frontend you choose mostly comes down to preference and requirements.
We’ll look at LocalLLM (https://github.com/qusaismael/locallm), a Python-based option, which means there’s no need to install and maintain other language compilers, interpreters, or related configuration. LocalLLM is a minimal, user-friendly web frontend for chatting with local models served through Ollama. It’s built with Flask (https://github.com/pallets/flask), a lightweight Python web framework. Although it’s a young project, LocalLLM includes useful features such as switching between local models in the UI, support for streaming responses, Markdown and code-block rendering, and a raw-text debug view (particularly helpful when interacting with models such as DeepSeek-R1 that use test-time compute). A prerequisite is a local instance of Ollama serving the SLMs you want to use.
To install LocalLLM, create and activate a Python virtual environment, and then clone the GitHub repo:
git clone https://github.com/qusaismael/locallm.gitcd locallmThen install its requirements:
pip install -r requirements.txtThe application can then be started as follows:
python app.pyThe UI can be accessed at http://localhost:50001. Figure 12.3 shows the LocalLLM UI.

[!visual-conversion] Figure 12.3 — The LocalLLM UI (p. 252)
The left panel shows the chat list for the current session (at the time of writing, this web app doesn’t yet persist chat history). The central panel is the chat area: the input box and Submit button are at the bottom, and the model output (and, if enabled, the raw output) appears above. At the top right is the model selector; its dropdown lists the SLMs currently available on the local Ollama server.
Remember, this application is for local use, not production deployment, because it has no authentication.
12.2.1 Importing a custom model into Ollama
Section titled “12.2.1 Importing a custom model into Ollama”As mentioned earlier, there are plenty of GGUF models on the Hugging Face Hub and in the Ollama catalog. You may well find a model that fits your needs there, but you
may also want to fine-tune a baseline model on your own private data and make it available for chat on your laptop or to a broader group in your organization. Through the llama.cpp library, Ollama can convert custom SLMs to the GGUF format and add them to a local server for use via the CLI or REST API.
To convert and import a model, first build llama.cpp locally. Clone the official GitHub repo, and install its requirements:
git clone https://github.com/ggerganov/llama.cpp.gitcd ./llama.cpppip install -r requirements.txtIn this example, we assume our custom model is uploaded to the Hugging Face Hub and under version control. If the model is only local, you can skip the next step. Install Git LFS, and clone the Hugging Face Hub repo that hosts the model and its associated files:
cd ..git lfs installgit clone https://huggingface.co/TechXGenus/starcoder2-3b-instructThe model in this example is a version of BigCode’s StarCoder2 3B (an SLM specialized for code generation), fine-tuned on an additional 0.7 billion high-quality code-related tokens.
After cloning it locally, convert the model to GGUF format using convert_hf_to_gguf.py, a Python script in the llama.cpp source code repository:
mkdir gguf_modelcd ./llama.cpppython convert_hf_to_gguf.py ../starcoder2-3b-instruct/--outfile ../gguf_model/starcoder2-3b_instruct.ggufThis script takes two arguments: the path to the directory where you cloned the original model, and the path and filename for the converted model. After conversion, we need to create a Modelfile. A Modelfile describes how to deploy the converted custom model to a local Ollama server and serve it for inference. In this case, our Modelfile would look like this:
FROM starcoder2-3b_instruct.gguf
PARAMETER num_ctx 4096TEMPLATE ""<|endoftext|>You are an exceptionally intelligent coding assistant that consistently delivers accurate and reliable responses to user instructions.### Instruction{ .Prompt }### Response"""PARAMETER stop "###"PARAMETER stop "<|endoftext|>"PARAMETER stop "<file_sep>"The FROM command specifies the GGUF model name. The TEMPLATE command specifies an optional system template. The PARAMETER command lets you set text-generation parameters such as context length and stop words. Create the Modelfile in the same directory as the converted GGUF model.
Assuming we have a local instance of Ollama already running, deploy the model using the ollama CLI’s create option:
cd ./gguf_modelollama create starcoder2-3b-instruct-new -f ModelfileOnce it’s created, you can chat with the model from the terminal:
ollama run starcoder2-3b-instruct-new:latestHere is an example of code-generation prompt for this custom model:
Write two different modular functions with documentation to add and multiply two numbers in Python.
And here is the resulting sample code:
# Modular Function 1def add_numbers(a, b): """ This function adds two numbers and returns the result.
Args: a: The first number. b: The second number.
Returns: The sum of `a` and `b`. """ return a + b
# Modular Function 2def multiply_numbers(a, b): """ This function multiplies two numbers and returns the result.
Args: a: The first number. b: The second number.
Returns:The product of 'a' and 'b'."""return a * b
# Sample Usageprint("Addition Result:", add_numbers(5, 3))print("Multiplication Result:", multiply_numbers(2, 4))This script contains two modular functions named ‘add_numbers()’ and ‘multiply_numbers()’. The comments on these functions explain what they do.
The sample usage at the end demonstrates how to use these functions. It will print “Addition Result: 8”, “Multiplication Result: 8”.
12.2.2 User privacy in Ollama
Section titled “12.2.2 User privacy in Ollama”Once a model has been downloaded locally, Ollama can run completely offline, so the user’s laptop doesn’t need to be connected to the internet or a LAN. That’s strong evidence for privacy preservation. But what happens if you chat locally with an SLM in Ollama while the hosting laptop is online? Does the Ollama server send any information out, and is there anything you should watch for to keep your privacy intact? The considerations in this section reflect the latest release available when this chapter was written (0.5.13). Please verify it yourself, since future versions of Ollama may behave differently.
A review of Ollama’s current source code, along with packet sniffing of a running local instance, shows nothing suspicious. Everything happens on a locally hosted server. Still, a few things are worth watching in case they change in the future. The first is the updater.go file. The body of the IsNewReleaseAvailable function calls the external endpoint https://ollama.com/api/update every 60 minutes, sending anonymized information about the laptop’s operating system, version, and architecture, along with the current timestamp. This function runs as part of the regular update check to see whether a new release is available for the local configuration. There seems to be no way to disable this through the local server configuration. The only option is to clone the Ollama source code repository locally and comment out the following line in lifecycle.go:
StartBackgroundUpdaterChecker(ctx, t.UpdateAvailable)Then you can build the application locally.
Another thing to pay attention to is the history file. It’s created in your local Ollama installation directory and is updated with every prompt sent to the local models during chats. It stores only prompt text, but because prompts may contain sensitive information , you should protect this plaintext (not encrypted) file from unauthorized access by intruders or malware.
You should similarly pay special attention to the Ollama server log file. It’s created and updated in the logs subdirectory of your local Ollama installation. It records REST
API calls and model use, but it doesn’t include sensitive information. Even so, it’s good practice to apply security measures to prevent unauthorized access, because the file isn’t encrypted.
In short, Ollama seems to preserve user privacy during local-model inference and chat, even when the laptop is connected to the web.
That concludes our look at the Ollama tool. We’ll return to it in the next chapter where we’ll explore end-to-end solutions that use small language models.
12.3 Running an LLM locally with LM Studio
Section titled “12.3 Running an LLM locally with LM Studio”The second tool we’ll explore is LM Studio (https://lmstudio.ai/). It’s free but not open source like Ollama. Still, it’s worth considering: it offers open source utilities (including Python and JavaScript SDKs and the Apple MLX engine) and a polished out-of-the-box experience for users with a range of technical skills. LM Studio is available for macOS (M-series), Windows, and Linux. Like Ollama, it can run GGUF models (and Apple MLX models) locally and entirely offline after you download them from the LM Studio catalog (see figure 12.4) or the Hugging Face Hub.
Model Catalog
Don’t have LM Studio yet? Get it for macOS, Windows, or Linux.

[!visual-conversion] Figure 12.4 — LM Studio’s online model catalog (p. 256)
LM Studio’s UI has several views. If you just want to interact with a local model, you can use the chat view (see figure 12.5).

[!visual-conversion] Figure 12.5 — LM Studio’s chat view (p. 257)
The center area of the chat view is where you interact with the model; the left panel shows the chat history, and the right panel contains advanced settings (system prompt, temperature, and sampling parameters). The selected model is identified at the top; in this example, it’s Llama 3.2 3B Instruct (the GGUF version from the LM Studio catalog). As shown in figure 12.5, you can also attach documents to a chat session (.docx, .pdf, and .txt) to provide extra context. If the document fits in the model’s context window, LM Studio adds its content to the conversation in full. Otherwise, LM Studio uses retrieval-augmented generation (RAG; introduced in chapter 2 and discussed in more detail in chapter 13). Long documents are split into chunks and provided to the model for reference.
For advanced users, such as developers who can build client applications that interact with local models through the LM Studio server’s REST API, the developer view is available (see figure 12.6).
To understand the developer view, you’ll first need to know about the LM Studio API server. Installing the LM Studio desktop app also installs its companion CLI tool. In addition to loading and unloading models, the lms CLI can start and stop LM Studio’s local, OpenAI-like API server and inspect raw LLM input and output. This is one of the open source components of LM Studio. You can also build lms from source (https://github.com/lmstudio-ai/lms) and, in theory (though it is challenging), install it separately.

[!visual-conversion] Figure 12.6 — LM Studio’s developer view (p. 258)
To start a local lms server, use this command:
lms server startOnce the server starts, you can use the developer view to track and debug any API call, including completions, chat completions, and embeddings. The top-center area of the UI (see figure 12.6) shows the loaded models, the bottom-center area shows the server log stream, and the right panel shows the selected model’s details and inference settings (system prompt, temperature, sampling parameters, schema for structured output, speculative decoding settings, context length, seed, and KV cache quantization).
To stop the server, run the following command in a terminal:
lms server stopAs when chatting with a model in the UI, starting a local server and calling the REST API doesn’t require the laptop to be connected to the internet or a LAN. You only need connectivity to download the model.
LM Studio 0.3.10 introduced speculative decoding (for models in GGUF or MLX formats). This inference optimization was proposed in the “Fast Inference from Transformers via Speculative Decoding” paper (https://arxiv.org/abs/2211.17192). In LLMs, it speeds up generation by drafting multiple future tokens in parallel and then having a larger model verify them.
Speculative decoding runs two models side by side: a large target LLM and a smaller, faster draft model. Both models must use the same tokenizer. The draft model generates candidate text, and the target model accepts or rejects those tokens to produce the final output. Because Transformer models can evaluate many tokens at once while predicting the next one, speculative decoding uses that capability to reduce generation time while preserving quality.
In LM Studio, speculative decoding works like this:
- The draft model runs, quickly predicting the next few tokens as a draft.
- The target model confirms or rejects each draft token, accepting only those it would have generated itself.
This can speed up generation (when enough tokens are accepted) without degrading quality. But if tokens are often rejected, total generation will likely slow down. Model choice matters: besides sharing a tokenizer, the draft model should be much smaller than the target model and from the same family.
Let’s walk through an example of speculative decoding in LM Studio. We’ll use Llama 3.2 3B Instruct (4-bit quantized) as the target model and Llama 3.2 1B Instruct (4-bit quantized) as the draft model. If you’ve downloaded them locally (via the lms CLI or the Mission Control panel in the LM Studio desktop app), you can select them in the Speculative Decoding panel at the bottom right of the chat view (see figure 12.7).
┌──────────────────────────────────────────────────────┐│ ⧉ Speculative Decoding [ ON ] [ Basic ] All ⌄ │├──────────────────────────────────────────────────────┤│ Draft Model 🗑 Read how it works ││ ┌──────────────────────────────────────────────────┐ ││ │ Llama 3.2 1B Inst... 4bit 712.58 MB ⌄ × │ ││ ├──────────────────────────────────────────────────┤ ││ │ ✓ Llama 3.2 1B Instruct 4bit 712.58 MB │ ││ └──────────────────────────────────────────────────┘ │└──────────────────────────────────────────────────────┘[!visual-conversion] Figure 12.7 — The LM Studio’s Speculative Decoding panel (p. 259)
Once both models have been selected, turn on the Visualize Accepted Draft Tokens switch in the Speculative Decoding panel to see colored tokens showing whether they were generated by the draft model or the target model. You can then start a chat as usual in the user view. The only changes you’ll notice are draft-model tokens highlighted in green (see figure 12.8) and faster content generation.

[!visual-conversion] Figure 12.8 — Speculative Decoding in action with the Llama 3.2 3B Instruct (target) and Llama 3.2 1B Instruct (draft) models in LM Studio (p. 260)
Benchmarks with these models on a MacBook Air M1 show a slower ramp-up: first-token generation with the larger model takes almost twice as long. Still, the average time only increases from about 1.5 seconds to 3 seconds, and generating 500 tokens is faster overall. With speculative decoding, you can cut total time by about 30% (roughly 9 to 10 seconds). Speculative decoding can be used through the REST API or programmatically via LM Studio’s Python SDK.
12.4 The LM Studio Python SDK
Section titled “12.4 The LM Studio Python SDK”LM Studio’s Python SDK is an open source library (https://github.com/lmstudio-ai/lmstudio-python), and it’s available on PyPI:
pip install lmstudioThis library lets you interact with models served by the LM Studio server from Python clients, Jupyter notebooks, or the Python REPL. Anything you can do in the UI, you can do programmatically with this SDK. It provides a synchronous conven and a scoped resource API that uses with statements for deterministic cleanup or ne work resources. The convenience API works well for a CLI or notebook cells. For larger applications, use the scoped API so context managers reliably close connections and other allocated resources.
Let’s see how this API works by walking through examples for chat, text completion, embedding generation, and agentic flow. For the code examples in this section, we’ll assume an LM Studio API server is running locally and a model is loaded and ready to accept requests (here, the Llama 3.2 3B Instruct 4-bit quantized version from the LM Studio online catalog). You can chat with the loaded model using the API with the following very high-level code:
import lmstudio as lms
model = lms.llm('llama-3.2-3b-instruct')print(model.respond("What is the meaning of life?"))As you can see, we specified the model ID and then called its respond method. The returned value is a PredictionResult instance whose content attribute contains the generated text.
You can do the same through the scoped resource API as follows:
import lmstudio as lms
with lms.Client() as client: model = client.llm.model("llama-3.2-3b-instruct") result = model.respond("What is the meaning of life?")
print(result)Inferencing parameters can be passed to the respond method. Example:
result = model.respond("What is the meaning of life?", config={ "temperature": 0.2, "maxTokens": 200,})With either approach, you can stream the chat response by calling respond_stream instead of respond.
Next, we’ll manage a chat context. The model receives a multturn conversation as input and predicts the assistant’s response. First, create a chat with an initial system prompt using the Chat helper class:
chat = lms.Chat("You are a helpful assistant.")Then, within an infinite while loop, we’ll implement the code that handles chat turns between the model and a human user.
Listing 12.1 Managing a chat context with the LM Studio Python API
while True: try: user_input = input("You (leave blank to exit): ") except EOFError: print() break if not user_input: break chat.add_user_message(user_input) prediction_stream = model.respond_stream( chat, on_message=chat.append, ) print("Bot: ", end="", flush=True) for fragment in prediction_stream: print(fragment.content, end="", flush=True) print()When it’s your turn, the script pauses for input. The model’s responses are streamed via the respond_stream method. To end the chat and stop the script, press Enter on an empty prompt.
This SDK also supports text completion. To do this, call complete on your chosen model, as shown here:
result = model.complete("Today is Friday and", config={"maxTokens": 200})You can generate embeddings for input text programmatically with this SDK. First, you need an embedding model downloaded locally and served. By default, LM Studio Server includes Nomic AI’s Nomic Embed Text v1.5, but you can choose a different embedding model.
To convert a prompt into a vector, pass it to the embed method on the appropriate embedding model handle:
import lmstudio as lms
model = lms.embedding_model("nomic-embed-text-v1.5")embedding = model.embed("A fancy prompt!")One interesting feature of this Python SDK is the ability to set up an agentic flow. Instead of using an SLM in a simple text-in/text-out fashion, you can ask the model to call a tool (or a set of tools) and handle the returned output. The LM Studio SDK introduced the concept of execution rounds, which describe the cycle of running a tool, passing its output to an LLM, and letting the LLM choose the next step. The model can repeat this cycle multiple times before returning a final result.
The act function in the LM Studio SDK implements automatic, multi-round tool calling. Let’s look at a basic example. Assume we’ve implemented a regular Python
function that performs some actions, given inputs, and returns a result. For example, the function could take two floats as input, multiply them, and return the result:
def multiply(a: float, b: float) -> float: return a * bWe pick up a model available in the local server as usual:
import lmstudio as lms
model = lms.llm("llama-3.2-3b-instruct")We can then call the act function for it, passing a prompt and the tool function (multiply):
model.act( "What is the result of 123 multiplied by 456?", [multiply], on_message=print,)In the preceding code, we pass a list of tools, so you can provide multiple tool functions for a single act call. Based on the prompt, the model decides which tool(s) to use. Our example tool is intentionally simple, but a tool function can run any Python code, including access to the web, local files and applications, and databases. Design tools defensively: validate inputs, handle failures, and plan for misuse.
An agentic workflow’s performance depends on the model you choose, so evaluate candidate SLMs (or create evaluation tasks for custom-tuned SLMs) before you make your final choice. We’ll discuss agentic workflows further in chapters 13 and 14.
12.5 Running an LLM locally with Jan
Section titled “12.5 Running an LLM locally with Jan”The third tool we’ll explore is Jan (https://github.com/janhq/jan). Like Ollama, it’s 100% open source and shares most of the same features as Ollama and LM Studio. Like LM Studio, Jan provides a desktop app (macOS, Linux, and Windows) that lets you chat with local models and models hosted behind major commercial APIs (OpenAI, Anthropic, Groq, Google, OpenRouter, and others). We’ll focus on local models here. As with the other tools we’ve looked at, you don’t need to be online to chat with local LLMs. You only need an internet connection to download a model the first time or to connect the Jan desktop app to a cloud API.
The Jan UI is simpler than the LM Studio’s UI. After downloading and installing the version for your operating system, start the app to see the chat view (see figure 12.9). The center pane is the chat area: the prompt box (and an area for optional RAG file uploads) is at the bottom, and the message history is above. As shown in the figure, responses are well formatted, and generated code includes syntax highlighting and allows easy copy-and-paste.
NOTE Retrieval and chat features with documents are currently available only for multimodal models. PDF documents and images are the only supported file types to date.

[!visual-conversion] Figure 12.9 — The chat view of the Jan desktop application (p. 264)
You can download local models from the Jan Hub, the default online catalog, or the Hugging Face Hub. Models must be in GGUF format, which is the only format Jan supports at the time of writing, though future releases may add ONNX Runtime support. You can browse and select models hosted in Jan Hub directly from the desktop app (see figure 12.10).
To help you choose a model, Jan uses your laptop’s hardware specs to warn you about models that will run slowly or need more memory than you have. At the top of the model selection view, you can import GGUF models from the Hugging Face Hub: enter the model’s URL or ID, and click Import Model. To import a custom local model that isn’t shared online, open Settings (the gear icon at the bottom left), go to My Models, click Import Model, select the local GGUF file, choose whether to create a symbolic link or copy the file into Jan’s directory, and click Import.
Like Ollama and LM Studio, Jan includes a built-in API server that’s compatible with the OpenAI API specification, so you can interact with local models over HTTP. The server isn’t started by default: in the Jan desktop app, open the Local API Server view, and click Start Server to expose the REST API to other local client applications. The server listens on port 1337 by default, but you can change it (and other settings) in the UI.

[!visual-conversion] Figure 12.10 — The model selection panel in the Jan desktop app (p. 265)
Unlike LM Studio (or Ollama when using a third-party frontend), Jan can’t run the API server while you chat with a model in the UI; the two modes are mutually exclusive.
12.6 The Cortex local LLM engine
Section titled “12.6 The Cortex local LLM engine”The Jan application and its built-in API server are powered by Cortex (https://github.com/janhq/cortex.cpp), an open source local AI engine written in C++. Cortex lets you switch inference backends (llama.cpp by default, or ONNX Runtime). It supports GPUs and tries to use one by default when running a model (NVIDIA, AMD, and Intel are supported). Quantized models are available from the Hugging Face Hub or bundled with Cortex; the supported model list is the same as Jan’s (see https://cortex.so/models/). Cortex supports multiple quantization modes per model, so several versions of the same SLM may be available. TypeScript and Python client libraries are in progress; the Python client isn’t released yet.
You can install the Cortex engine as a standalone local LLM engine or as part of Jan. After Cortex is installed, use the cortex CLI to start the server:
cortex startThe default port is 39281. The API documentation is available from a web browser at http://127.0.0.1:39281. An HTTP GET request to the engines endpoint displays the list of installed engines:
curl --request GET \--url http://127.0.0.1:39281/v1/enginesThe output of the request would look like this:
{"llama-cpp": [{"engine": "llama-cpp","name": "linux-amd64-avx2","type": "local","version": "v0.1.49"},"python-engine": [],"tensorrt-llm": []}You can do the same with the cortex CLI’s engines list command:
cortex engines listWhen you start the server for the first time, no LLM is installed by default. You’ll need to pull one from the Jan catalog. You have two options, including using the cortex CLI’s pull command:
cortex pull tinyllama:1bOr you can send an HTTP POST request to the models/pull endpoint:
curl --request POST \--url http://127.0.0.1:39281/v1/models/pull \-H "Content-Type: application/json" \--data '{"model": "tinyllama:1b"}'Once the model finishes downloading, it’s ready to chat. Start a chat session with the following command:
cortex run tinyllamaThe following is an example chat with the TinyLlama model:
In order to exit, type exit()
GI What is the tallest building in the world?
II The current record-holder for the tallest building in the world is the Burj Khalifa in Dubai, United Arab Emirates. It was officially opened on 4 July 2010 and stands at 828 meters (2,716 feet) tall. The building is home to a variety of amenities and is the tallest freestanding structure in the world.
GI Thanks. Tell me more about it.
Certainly! The Burj Khalifa is a 828-meter-tall (2,716-foot) skyscraper located Dubai, United Arab Emirates. The building was officially opened on July 4, 2010 and was designed by Adrian Smith and Gordon Gill Architecture. It features a unique architectural design, including a staggered triangular shape and a central core.
The building’s most notable feature is its observation deck, known as the Dubai Fountain, which is located at the 124th floor. The fountain is powered by 2,000 water jets that shoot 1.5 million gallons of water per minute, creating a spectacular light show in the evening. The observation deck has over 500 seats and offers panoramic views of the city, including Dubai Creek, the Dubai Marina, and the Persian Gulf.
In addition to the observation deck, the Burj Khalifa features over 160 restaurants, cafes, and bars, as well as a variety of shopping and entertainment venues. The building also has a residential tower, known as the Burj Khalifa Towers, with 2,722 units, making it the world’s tallest residential tower.
Overall, the Burj Khalifa is a remarkable achievement in architectural design and is a testament to the power of innovation and vision in creating some of the world’s most iconic and awe-inspiring structures.
The following command will stop the server:
cortex stopThat wraps up our overview of the most mature and popular options for building a personal AI assistant on a laptop. The three solutions share many features, but each has its own strengths and a few areas to improve. Your choice will depend mostly on the task and your personal preference. Table 12.1 summarizes pros and cons of the Ollama, LM Studio, and Jan tools.
Table 12.1 Pros and cons of Ollama, LM Studio, and Jan
| Local LLM assistant tool | Pros | Cons |
|---|---|---|
| Ollama | ■ 100% open source ■ Models optimized for CPU to get the most from commodity hardware ■ REST API server ■ A large open source community providing multiple options for client applications, plugins, and extensions ■ Mature open source Python and Typescript SDKs ■ Provides Python Scripts for model conversion to GGUF format ■ Easy integration with other tools for building local end-to-end AI solutions | ■ No native frontend |
Table 12.1 Pros and cons of Ollama, LM Studio, and Jan (continued)
| Local LLM assistant tool | Pros | Cons |
|---|---|---|
| LM Studio | ■ User Friendly UI ■ Native support also for models in Apple MLX format ■ Mature open source Python and Typescript SDKs ■ OpenAI API-compatible REST API server ■ Integrated Speculative Decoding ■ Integrated chat with local documents | ■ The desktop application is free but not open source. ■ The LLM inference server is open source but challenging to build separately. |
| Jan | ■ 100% open source ■ Clean UI ■ The LLM inference server can be installed and used without the desktop app. ■ OpenAI API-compatible REST API server ■ Works also with third-party cloud models/API | ■ Chat through the UI and REST API server cannot happen at the same time. ■ Models optimized for GPU; a little bit more computationally hungry than Ollama and LM Studio ■ Python and Typescript SDKs not yet suitable for production |
Whatever solution you choose, these tools provide a safe way to give language models access to your personal files without sending them off your laptop and to let organizations connect productivity tools to private data sources on the corporate network.
Summary
Section titled “Summary”- Local language models protect privacy by processing data on personal devices, without internet connectivity.
- Ollama serves GGUF-quantized models via a local API, automatically downloading a model the first time you request it.
- The
ollamarun command downloads the model and starts the chat interface in one step. - The Ollama REST API exposes endpoints for chat completions and model management.
- LocalLLM provides a Flask-based web frontend for Ollama with streaming responses and model switching.
- Custom models must be converted to GGUF format using
llama.cpp’sconvert_hf_to_gguf.pyscript. - A Modelfile defines an Ollama model’s templates, parameters, and stop tokens.
- LM Studio is a desktop app with a GUI for model management and chat. It supports GGUF and Apple MLX models for local inference.
- Speculative decoding uses a small draft model to propose tokens that a large target model verifies.
- The LM Studio Python SDK provides programmatic access to local models through convenient, scoped resource APIs.
- In LM Studio, agentic flows let models call Python functions as tools during a conversation.
- The Jan desktop app supports both local models and commercial API providers. Jan requires models in GGUF format and displays hardware-compatibility warnings during selection.
- Jan is powered by the Cortex engine, a C++ implementation with llama.cpp and ONNX Runtime backends.
- Cortex CLI provides commands to manage servers, pull models, and run chat sessions.
- All of these local assistants avoid sending data to external servers and still work fully offline.