Install a model manager, download a suitable LLM, raise the local API, attach a vector search for the "knowledge" of the project — and you have a private assistant without the Internet. Below is a step-by-step guide with code and checklists.
Why a local ChatGPT?
Privacy: data does not leave your machine/server.
Autonomy: works offline, is resistant to blocking and cloud SLA.
Customization: own "personality", own knowledge, integration under the project.
Cost: zero/predictable inference costs.
Hardware and software requirements
Scenario | CPU/RAM | GPU (preferably) | Notes |
|---|---|---|---|
Laptop / PoC | 4+ cores, 16 GB RAM | Without GPU or 4–6 GB VRAM | GGUF quantization (q4_0/q5) for 7B models |
Stationary / team | 8+ cores, 32–64 GB RAM | RTX 3060–4090, 8–24 GB VRAM | 13B–14B models, faster response and better quality |
Service within the company | 16+ cores, 64+ GB RAM | A100/RTX 6000, etc. | Servers, request batching, load tests |
Software: Linux/macOS/WSL2, Python 3.10+, Docker (as appropriate).

Model selection
Mistral 7B — quick start, excellent quality for its size.
LLaMA 3 (8B/70B) — strong responses, 8B is good on a laptop (in quantization).
Phi / Qwen / Gemma - compact and economical alternatives.
Scale format for localization: GGUF (for llama.cpp/Ollama/GPT4All). The lower the quantization (q4 → q8), the less memory is needed, but the higher the risk of quality loss.
Launch stack: three convenient paths.
Ollama - the simplest model manager.
curl -fsSL https://ollama.com/install.sh | sh ollama run mistralAdvantages: one command to the result, local REST API, model cache.
GPT4All — GUI/CLI, runs on Windows/macOS/Linux.
git clone https://github.com/nomic-ai/gpt4all cd gpt4all && pip install -r requirements.txt python gpt4all.pyAdvantages: friendly interface, simple presets.
LM Studio / text-generation-webui — flexible UI for experiments, quantization profiles, plugins.
We are raising our API (like ChatGPT) 🔌
Local REST is useful for integrations with IDE, bots and backend. Example — FastAPI + Ollama:
<!-- main.py -->
from fastapi import FastAPI
from pydantic import BaseModel
import subprocess, json
app = FastAPI()
class ChatRequest(BaseModel):
prompt: str
@app.post("/chat")
def chat(req: ChatRequest):
# Simple call ollama (response - stream or whole line)
proc = subprocess.run(
["ollama", "run", "mistral", req.prompt],
capture_output=True, text=True
)
return {"response": proc.stdout.strip()}
# API launch
uvicorn main:app --reload --port 8000
# request
curl -X POST http://localhost:8000/chat \
-H "Content-Type: application/json" \
-d '{"prompt":"Explain RAG in 1 sentence."}'For production, wrap in Docker, add logging, timeouts, and token limits.

Adding "memory": RAG through a vector database
RAG (Retrieval Augmented Generation) - the model responds based on your documents.
Split documents into chunks (Markdown/PDF/HTML → 300–800 tokens each).
Build embeddings (for example,
all-MiniLM-L6-v2or a local text-embedding model).Add to the vector database: Chroma, FAISS, Qdrant.
On request: find the top k nearest chunks, substitute them in the system prompt and send them to the LLM.
# pipeline pseudocode
context = retriever.search(query, top_k=5)
prompt = f"Answer using ONLY this context:\\n{context}\\n\\nQuestion: {query}"
answer = llm(prompt)Pros: up-to-date answers based on your database. Cons: data engineering and context quality control.
Fine tuning
System prompt: set the style, format, and restrictions.
Temperature/top-r: less - more deterministic and useful for documentation.
Chat templates: use the system/user/assistant role, store the dialog history in the database.
Fine tuning/LoRA: retrain on your dialogues — it improves domain responses in a targeted manner.
Safety and operation
Keep the API for Auth (keys, OAuth, mTLS), limit CORS sources.
Limit the length of prompts and the number of tokens, set timeouts.
Log requests/responses (with obfuscation of private data), monitor latency and OOM.
Separate Unix user/container, minimum permissions, regular updates of weights and dependencies.
Typical problems and quick solutions
Symptom | Reason | Fixed |
|---|---|---|
Slow responses | Large model / without GPU | Quantization GGUF q4/q5, smaller model, bim-search ↓, temperature ↓ |
Out Of Memory | Insufficient RAM/VRAM | Low quantization, offload to CPU, limit max_tokens/context |
Hallucinations | Lack of context | RAG + quality embeddings, source validation, system prompt |
Instability | Raw assemblies | Pin versions, docker-compose, healthchecks, retry policies |
Total
Local ChatGPT is real and useful. Start with Ollama + Mistral, raise the API, add RAG, and polish the quality with prompt engineering. Next comes security, monitoring, and dockerization. Done: you have a personal AI assistant under control and privacy.
Your GPT doesn't start with a button, it starts with a foundation: code, data, understanding of models.
Gain knowledge and practice in "Codice" — and assemble an assistant for your tasks. 💻🧠
And we also have an active Telegram channel, where we discuss cool ideas, share experiences and analyze tasks together — learning becomes not only useful, but also fun.
