Local ChatGPT on Linux: 2 Setups Tested, 1 Easy Winner

A local ChatGPT is a chat model that runs on your own machine and answers through a web page or an OpenAI-style API, with no prompt leaving the box. The 2024 version of this post built one with Flask and GPT-2 and then said GitHub Copilot could be "integrated" with it. On 22 November 2026 I ran that code as published, then built the setup I would actually use today: llama.cpp's llama-server with a small instruction-tuned model, on CPU only, in containers. I also checked what VS Code's documentation says about using Copilot's chat with a local model, because that part changed a lot.

Test 1: the old Flask + GPT-2 local ChatGPT

I ran the post's app.py unchanged in python:3.12-slim with CPU PyTorch. Versions installed that day:

Flask             3.1.3
torch             2.15.0+cpu
transformers      5.24.0

It starts and answers. GPT-2 is a text-completion model, not a chat model, so it continues your prompt instead of replying to it:

{"response":"What is the capital of France?\n\nThe capital of France is Paris.\n\nThe capital of France is Paris.\n\nThe capital of France is Paris.\n\nThe capital of France is Paris.\n\nThe capital of France is"}

The right fact is in there, repeated until max_length=50 cuts it off. A coding question shows the real limit:

{"response":"Write a bash one-liner that counts lines in all .log files.\n\n$ echo \" %s \" % ( $ ( \" $ ( \" $ ( \" $ ( \" $ ( \" $ ( \" $ ( \" $ ( \" $"}

Two smaller points from the same run. Flask's app.run(port=5000) listens on 127.0.0.1 only ("Running on http://127.0.0.1:5000"), so other machines on the LAN cannot reach it, which is a safe default. And the endpoint is POST only; opening it in a browser gives HTTP Error 405: METHOD NOT ALLOWED. The download was 526 MB of model files for GPT-2. It works as a demo of the transformers API, but it is not a local ChatGPT in any useful sense.

Test 2: a real local ChatGPT with llama-server

llama-server from llama.cpp loads a GGUF model, serves a chat web UI and exposes an OpenAI-compatible API on the same port. I used the official container image and Qwen2.5-0.5B-Instruct in Q4_K_M quantization (about 490 MB) from Hugging Face:

podman run -d --name lab-llama -p 127.0.0.1:18080:8080 \
  -v ~/models:/models:ro,Z ghcr.io/ggml-org/llama.cpp:server \
  -m /models/qwen2.5-0.5b-instruct-q4_k_m.gguf --host 0.0.0.0 --port 8080 -c 4096

The server reported build 12602 and was ready in about half a second:

version: 1.0.0-dev (build 12602, commit 418fe97b5)
0.00.556.454 I srv  server_run_i: model loaded
0.00.556.459 I srv  server_on_li: listening on http://0.0.0.0:8080
Local ChatGPT with llama-server: health check, chat completion on CPU at 72 tokens per second and conversation memory test
Lab: the same question to the local ChatGPT API, and what happens without chat history.

Same question as before, sent to the local ChatGPT through the OpenAI-style endpoint:

$ curl -s 127.0.0.1:18080/v1/chat/completions -H "Content-Type: application/json" \
  -d '{"messages":[{"role":"user","content":"What is the capital of France?"}],"temperature":0}'
The capital of France is Paris.
{'completion_tokens': 8, 'prompt_tokens': 36, 'total_tokens': 44, 'prompt_tokens_details': {'cached_tokens': 0}}
71.91066640641854

One clean answer in 0.3 seconds, about 72 tokens per second on the CPU. The coding question got a usable command with an explanation:

find . -name "*.log" -exec wc -l {} \;

Usable, not perfect: find . also walks subdirectories, while the question said "the current directory", and wc runs once per file, so there is no total. A 0.5B model is fast and small, and you should still read what it writes. A 3B or 7B model fixes many of these slips if you have the RAM.

Your local ChatGPT has no memory of its own

The local ChatGPT API is stateless. The client has to send the whole conversation every time, which is what the ChatGPT web app does for you behind the scenes:

turn1: Hello! It's nice to meet you, Huu. How can I assist you today?
turn2 without history: Your name is Qwen, created by Alibaba Cloud.
turn2 with history: Your name is Huu.

If you write your own front end, keep the message list and send it back with each request, and trim it before it passes the context size (-c 4096 here).

Web UI and access control

The web UI is served at /. My first curl without compression got 415 text/plain; with Accept-Encoding: gzip, as every browser sends, the page came back as 200 text/html. So use a browser for the UI and do not read much into curl results there.

By default anyone who can reach the port can use the model. The OpenAI-style Authorization header is ignored: a request with "Bearer anything" got 200. Start the server with --api-key and the API refuses requests without it:

$ curl -s http://127.0.0.1:18081/v1/models
{"error":{"message":"Invalid API Key","type":"authentication_error","code":401}}
$ curl -s -H "Authorization: Bearer s3cret-lab-key" http://127.0.0.1:18081/v1/models -o /dev/null -w "%{http_code}\n"
200
$ curl -s http://127.0.0.1:18081/health
{"status":"ok"}

The health check stays open, which is handy for monitoring. I also published the container port on 127.0.0.1 only. Do both before you expose a local ChatGPT to anyone else. The full option list is in the llama.cpp server README.

Copilot and a local model: what VS Code supports now

The old post told readers to "configure Copilot to suggest code based on your local project files" as if it could use the Flask server. It cannot. According to the VS Code documentation on AI language models (read 22 November 2026), there are two different ways to put a local model behind the Copilot chat interface:

  • Bring your own model (BYOK). You add a model provider in the Language Models editor; for a locally running model the docs say to "add a model provider extension, such as Ollama". BYOK models "work without signing into a GitHub account and without a Copilot plan", including offline use with local models. For Copilot Business or Enterprise, an administrator has to enable the BYOK policy first.
  • Copilot-managed on-device models. VS Code downloads the model and serves it with llama.cpp itself. This needs GitHub sign-in with Copilot access and, per the requirements list, "an NVIDIA GPU with 96 GB or more of GPU memory (VRAM)".

I did not test either inside VS Code for this post, only the local ChatGPT server itself. For most laptops the practical path is BYOK with an Ollama-backed model; the Ollama chatbot guide covers installing Ollama and its API, and the DeepSeek-R1 post shows a reasoning model on the same stack.

Which local ChatGPT setup to pick

Flask + GPT-2 (old post)llama-server + Qwen2.5 0.5B
Answers questionsNo, continues textYes, chat-tuned
Download526 MB model + PyTorch~490 MB GGUF + server image
Latency (same question, CPU)1.4 s, repeated text0.3 s, one sentence
Web UInonebuilt in
OpenAI-compatible APInoyes, /v1/chat/completions
Authnone (localhost only)--api-key

My advice after this run: skip the hand-written Flask wrapper unless you are learning the transformers API. Start llama-server (or Ollama) with a chat model that fits your RAM, bind it to localhost, set an API key, and point your tools at the /v1 endpoint. You get a local ChatGPT in two commands, and you can swap the model file later without touching anything else.

Comments

Popular posts from this blog

Linux Desktop Frozen? 5 Proven Fixes Before a Hard Reboot

Minecraft Bedrock on Linux: 4 Proven Ways to Play in 2026

DXVK in Wine on Linux: 7 Easy Setup Steps, Tested