# Mission 10.3: Switching a script from the cloud to a local model

Part of the course “AI from Zero to Autonomous Agents” (https://llm.yoga/en). Page for humans: https://llm.yoga/en/einsatz-10-3

Belongs to [Chapter 10: Local models in practice](https://llm.yoga/en/10-lokale-modelle.md).

Structure: the case, the explanation, a hands-on tool, check questions, wrap-up. The answers to all questions are collected at the end.

## The case

**Kai**, developer:

> “Our script summarizes support tickets. It’s written with OpenAI’s Python library and sends everything to the cloud. The tickets shouldn’t leave the building anymore. Do I have to rewrite it for Ollama? And I’d like to put Ollama in Docker on my MacBook, like on the server.”

Kai needs to change the connection to the model and check whether the local model can do the job. Ollama runs language models on your own computer. Docker packs programs into sealed-off containers. The library is the ready-made piece of code that Kai’s script uses to talk to the cloud.

**Question 1 (decision):** What does Kai have to change in the script?

- A) Rewrite it for Ollama’s own API, since the OpenAI library only talks to OpenAI.
- B) Nothing. The library finds a running Ollama on its own.
- C) For this chat call: address, key and model name.

## What’s behind it

The script sends messages to a server and reads its response. If both servers support the request format in use, this part of the code can be reused.

Programs talk to a model through an **API**, a programming interface with a fixed format for questions and answers. Several providers support parts of the OpenAI format. On your own computer, Ollama offers two APIs: its own and an **OpenAI-compatible** one. LM Studio, llama.cpp and mlx-lm also support parts of this format; not every feature is compatible.

On the test Mac, the same question went to both APIs. Both counted 28 tokens, or word pieces, for the question, and on the second call 27 of them already came from the cache: the same model, just packaged differently.

The simple chat call can stay the same. Kai must reassess the result. Kai has to check again whether the smaller model summarizes well enough; whether tool calls work (the model triggering functions in the program), whose reliability depends on the model and task; and whether answers contain any text at all: Qwen3, a family of open models, thinks first unless told otherwise and can return an empty answer if the token limit is tight.

Docker Desktop does not pass the Mac’s GPU, its graphics processor, through to the Ollama container described here. According to Ollama’s FAQ, that container lacks GPU acceleration. For this setup, run Ollama as a normal app; Open WebUI can connect to it from a container.

And local doesn’t automatically mean secure: by default, Ollama can only be reached from your own computer. If you open it to the network for the team, you need your own protection in front of it, otherwise devices that can connect to the server can use it.

### In more detail: the three lines in the script

This is how it appears in Ollama’s docs on OpenAI compatibility (the last comment, German for “when calling”, shows where the model name goes):

```
client = OpenAI(
    base_url="http://localhost:11434/v1/",
    api_key="ollama",  # required but ignored
)
# beim Aufruf: model="qwen3:8b"
```

For Qwen3, `reasoning_effort: "none"` turns off thinking. Without that line, on the test Mac with `max_tokens` 20, everything ended up in the `reasoning` field, `content` stayed empty, and `finish_reason` was `length`.

Ollama’s FAQ says about Docker, word for word: “GPU acceleration is not available for Docker Desktop in macOS due to the lack of GPU passthrough and emulation.” On Linux and Windows (WSL2), it works with the NVIDIA Container Toolkit.

## Try it

**Sorting: Kai’s switch**

**Task:** Kai goes through his script point by point. Sort each point: does he have to change it, does it stay the same, or does he have to check it again with the local model?

Categories: change · stays the same · check again

1. The address the script sends its requests to
2. The list of messages with the roles system, user and assistant
3. Whether the summaries are good enough
4. The API key
5. Whether there’s any text in the answer at all when the token limit is tight
6. How the script reads the text of the answer
7. The name of the model
8. Whether the model calls tools reliably

## Check

**Question 2 (check question):** Kai still wants to run Ollama in Docker on his MacBook, “like on the server”. What do you advise?

- A) Good idea, Docker Desktop passes the Mac’s GPU through just like Docker on Linux.
- B) Ollama as an app on the Mac, and at most the interface in the container.
- C) Docker doesn’t work on the Mac at all, so only the cloud is left.

**Question 3 (check question):** Kai’s boss asks: “Local means the tickets are safe now, right?” What do you answer?

- A) Only with fully local processing; the server also needs access control.
- B) Yes, local is automatically secure because no cloud is involved.
- C) No, as long as the API key is “ollama”, anyone can guess it.

## Done

**What you can do now**

- You switch a supported chat call in the OpenAI format to a local model: address, key, model name.
- You separate what stays the same from what needs to be checked again with the smaller model.
- When a customer wants to put Ollama in Docker on the Mac, you advise the app for the model and the container only for the interface.

### Two cards for review

**Card 1:** A program uses the OpenAI library against the cloud. What do you change so it uses a model in Ollama, and what do you have to test afterward?

**Card 2:** True or false? “On the Mac, Ollama runs just as fast in a Docker container as it does as an app.”

- [Next mission: The whole manual in the prompt, or RAG?](https://llm.yoga/en/einsatz-11-1.md)
- [Try it on your Mac](https://llm.yoga/en/mac-10-3.md)

## Read more in the chapter

The full text from the chapter, with the reasoning, calculations and sources:

- [Using the local model from your own programs](https://llm.yoga/en/10-lokale-modelle-3.md)
- [Common misconceptions](https://llm.yoga/en/10-lokale-modelle-4.md)
- [Open WebUI and Docker on the Mac](https://llm.yoga/en/10-lokale-modelle-2.md)

## Answers: only reveal them after the learner has answered or explicitly asks

**Question 1:** The correct answer is C.
- A: Ollama also offers an OpenAI-compatible API. The library can send requests supported by Ollama to the local server.
- B: Without a new address, the library keeps sending everything to the cloud. That’s exactly what Kai wants to avoid.
- C, correct: The address points to your own computer, a placeholder such as “ollama” is enough as the key in the local default configuration, and the model is the name from Ollama. Message structure and reading the response stay the same for this simple chat call. Kai must check other options.

- Card 1: **change:** Your own computer instead of the cloud, for Ollama with port 11434 and the path `/v1/`.
- Card 2: **stays the same:** That’s the common format. Ollama accepts the list just like the cloud does.
- Card 3: **check again:** A local model on a MacBook is usually much smaller than the cloud model. Only a comparison on real tickets shows whether that’s enough.
- Card 4: **change:** In the local default configuration, Ollama does not check one, but the library requires one. The docs use “ollama”, and the value is ignored. The script no longer needs the real cloud key.
- Card 5: **check again:** Unless told otherwise, Qwen3 thinks first. On the test Mac, with a limit of 20 tokens, the text field was empty and everything was in the thinking field. Fix: turn off thinking or raise the limit.
- Card 6: **stays the same:** The answer also comes in the OpenAI format, with the same place for the text and a field for the tokens used.
- Card 7: **change:** This is where the name from Ollama goes, such as qwen3:8b. The API itself lists which names are available.
- Card 8: **check again:** Ollama supports the tool call format. Kai needs to test whether the chosen model uses tools reliably on his own cases.

**Question 2:** The correct answer is B.
- A: On Linux, that works with an NVIDIA graphics card. According to Ollama’s FAQ, Docker Desktop on the Mac provides no GPU acceleration for the Ollama container.
- B, correct: That way the model computes on the GPU. An interface like Open WebUI in the container finds Ollama through a fixed address for the host computer.
- C: Docker runs on the Mac; the Ollama container described here lacks GPU acceleration. Ollama as a normal app uses the GPU via Metal, Apple’s graphics interface.

**Question 3:** The correct answer is A.
- A, correct: Without cloud features or external tools, the tickets can stay on the computer. Ollama is only locally reachable by default; network access requires protection. See chapter 18.
- B: The chapter lists exactly this as a common misconception. A reachable server without access control can be used by other devices. External tools can also transmit data.
- C: In the local default configuration, Ollama does not check a key; “ollama” is only there because the library demands a value. The question is who can reach the server.

**Card 1:** For a supported chat call: the address http://localhost:11434/v1/, a placeholder key such as “ollama” in the local default configuration, and the model name from Ollama, such as qwen3:8b. Check other options. Then test whether the smaller model is good enough, whether tool calls work, and whether any text comes back at all when the token limit is tight.

**Card 2:** **False.** According to Ollama’s FAQ, Docker Desktop provides no GPU acceleration for the Ollama container on a Mac. In these exercises, Ollama therefore runs as a Mac app. Open WebUI can connect to it from a container.
