TinyLLM

jasonacoxMIT活跃维护

用消费级硬件在本地搭建并运行大语言模型和聊天机器人,支持 llama-cpp-python、vLLM 和 RAG 检索增强。

Setup and run a local LLM and Chatbot using consumer grade hardware.

v0.16.5发布于 2025-11-20 06:11 UTC354star43fork同步于 2026-11-10 18:01 UTC

怎么上手

由 README 提炼,执行前请确认
git clone https://github.com/jasonacox/TinyLLM.git
cd TinyLLM
docker run -d --gpus=all -v $PWD/ollama:/root/.ollama -p 11434:11434 -p 8000:11434 --restart unless-stopped --name ollama ollama/ollama
硬件要求按 README 说明

CPU 支持 Intel、AMD 或 Apple Silicon,内存 8GB+ DDR4,硬盘 128G+ SSD;GPU 为 NVIDIA(如 GTX 1060 6GB、RTX 3090 24GB)或 Apple M1/M2;系统为 Ubuntu Linux 或 MacOS,CUDA 12.2。vLLM 因用非量化模型需要更大显存。

支持 Apple Silicon需要 CUDA有 Docker 镜像
下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

在消费级硬件上搭建本地 LLM 和类 ChatGPT 网页界面

用消费级硬件在本地搭建并运行大语言模型和聊天机器人,支持 llama-cpp-python、vLLM 和 RAG 检索增强。

核心能力

  • 用 Ollama、llama.cpp 或 vLLM 起 OpenAI 兼容 API 服务
  • 提供可自定义提示词的 Chatbot 网页界面
  • 支持读取外部网址、向量数据库、新闻股票天气等来源
  • 附推荐模型清单,标注量化级别与上下文长度
  • Ollama 可配置常驻模型与上下文长度避免重载

容易踩的坑

模型需单独下载,Ollama 首次运行或 ollama run 时会拉取,耗时较长;llama-cpp-python 需按平台设置 CMAKE_ARGS 编译安装,且 README 指定 0.2.27 版本;Ollama 和 llama-cpp-python 一次只能处理一个会话,且 Ollama 默认 5 分钟卸载空闲模型导致首 token 变慢。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v0.16.5
  1. v0.16.5v0.16.5 - Enhanced Markdown and Code Rendering最新正式版2025-11-20 · 2025-11-20 06:11 UTC

    What's Changed

    • v0.16.5 - Markdown and Code Rendering by @jasonacox in https://github.com/jasonacox/TinyLLM/pull/32
    • Added syntax highlighting for code blocks using Prism.js with support for Python, JavaScript, and HTML.
    • Improved streaming output rendering with proper HTML escaping to prevent code interpretation during display.
    • Enhanced code block styling with dark theme background and optimized font size and line spacing.
    • Fixed content jump issue when streaming text transitions to rendered markdown by adding consistent margin spacing.
    • Added comprehensive third-party license attribution for all frontend and backend libraries.
    • All static assets (Prism.js, marked.js, Socket.IO) now served locally to support air-gapped deployments.

    Full Changelog: https://github.com/jasonacox/TinyLLM/compare/v0.16.4...v0.16.5

  2. v0.16.4v0.16.4 - Document Generation2025-09-21 · 2025-09-21 07:53 UTC
    查看更新说明

    What's Changed

    Included Features:

    • Security - Download Route Hardening: The /download/{filename} endpoint now validates filenames to prevent path traversal.
      • Sanitizes input using os.path.basename() and rejects empty/./.. values.
      • Enforces allowed extensions: .pdf, .docx, .pptx, .xlsx.
      • Resolves real paths and ensures they stay within the generated_docs directory.
      • Returns 400 for invalid filenames and 404 for missing files.
    • Markdown Rendering:
      • PDF: Lightweight Markdown renderer (headings, bold/italic, bullet and numbered lists, Markdown tables).
        • Supports internal links: headings emit anchors, and [text](#anchor) links navigate within the PDF.
        • Fenced code blocks now render as shaded, monospaced sections with a small header (e.g., "Code (python)") instead of literal Markdown fences.
        • Fenced code blocks now render as shaded, monospaced sections with a small header (e.g., "Code (python)") instead of literal Markdown fences.
      • DOCX: Render a useful subset of Markdown (headings #..######, bullet/numbered lists, Markdown tables, inline bold/italic). Preserves table column structure and empty cells. Lists use built-in Word list styles.
      • XLSX: Spreadsheet-friendly Markdown rendering:
        • Headings styled and merged across columns for readability.
        • Bullet/numbered list items now in a single cell (e.g., • Item text, 1. Item text) with wrapping.
        • Tables with styled header row, borders, and wrapping; preserves empty cells to maintain column alignment.
        • Fenced code blocks (...) render as monospaced, shaded cells with wrapping.
        • Entire-line links [text](url) become clickable hyperlinks.
      • PPTX: Presentation-friendly behavior:
        • Added a PowerPoint-specific LLM prompt that requests a Markdown outline with # Presentation: and ## Slide N: sections, bullets, and tables.
        • Parser normalizes titles by stripping Presentation: and Slide N: prefixes so slides have clean titles.
        • Disabled native PowerPoint bullet styling on paragraphs to prevent double bullets when using manual prefixes; list items now render with a single bullet or number consistently.
    • Format Handling & UI:
      • Format aliases normalized (e.g., word|doc|docx -> docx, excel|spreadsheet|xlsx -> xlsx, powerpoint|ppt|pptx -> pptx).
      • /stats page lists supported document types and aliases.
    • Privacy & Reliability:
      • Generated filenames use UUID-based opaque IDs (no session identifiers).
      • Fixed route mounting order so Socket.IO is mounted last, preventing route interception of downloads.
      • Excel generator stability fixes (prevent infinite loops and Excel row overflow in extreme cases).

    Example Usage

    Write an algorithm in python to sort a list of number. Create a PDF to describe how it works.

    Full Changelog: https://github.com/jasonacox/TinyLLM/compare/v0.16.3...v0.16.4

  3. v0.16.3v0.16.3 - OpenAI Image Generation Support2025-08-03 · 2025-08-03 07:18 UTC
    查看更新说明

    What's Changed

    • OpenAI Image Generation Support by @jasonacox in https://github.com/jasonacox/TinyLLM/pull/30
    • Added OpenAI DALL-E image generation support with dedicated environment variables.
    • Added separate configuration for OpenAI image generation: OPENAI_IMAGE_API_KEY, OPENAI_IMAGE_API_BASE, OPENAI_IMAGE_MODEL, and OPENAI_IMAGE_SIZE.
    • Fixed "/image route not enabled" error by separating OpenAI image settings from LiteLLM proxy configuration.
    • Improved image generation route handling with automatic format detection for different providers (SwarmUI/OpenAI).
    • Container: jasonacox/chatbot:0.16.3

    Full Changelog: https://github.com/jasonacox/TinyLLM/compare/v0.16.2...v0.16.3

  4. v0.16.2v0.16.2 - Repetition Filter2025-06-25 · 2025-06-25 06:36 UTC
    查看更新说明

    What's Changed

    0.16.2 - Repetition Filter Settings

    • Added environment variables for repetition filter: REPEAT_WINDOW and REPEAT_COUNT.
    • These control the window size and repeat count for the LLM output repetition filter. Users can now adjust these via environment variables to fine-tune anti-repetition behavior.
    • MovieBot: Improved get_movies_released_today() to return a RAG-ready context string, listing only movies with popularity over 10, and including title, year, rated, genre, and popularity.
    • MovieBot: Refactored and optimized code for genre/holiday logic, prompt formatting, and error handling.
    • MovieBot: Fixed bug with TypeError in holiday detection and improved SearxNG integration for internet movie searches.
    • Documentation: Updated Chatbot and Document Manager environment variable sections in the README to use consistent tables.
    • Documentation: Improved clarity, formatting, and consistency in README and environment variable documentation.

    Full Changelog: https://github.com/jasonacox/TinyLLM/compare/v0.16.1...v0.16.2

  5. v0.16.1v0.16.1 - Image Generation Settings2025-05-11 · 2025-05-11 21:09 UTC
    查看更新说明

    What's Changed

    Full Changelog: https://github.com/jasonacox/TinyLLM/compare/v0.16.0...v0.16.1

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    TinyLLM

    TinyLLM? Yes, the name is a bit of a contradiction, but it means well. It's all about putting a large language model (LLM) on a tiny system that still delivers acceptable performance.

    This project helps you build a small locally hosted LLM with a ChatGPT-like web interface using consumer grade hardware. To read more about my research with llama.cpp and LLMs, see research.md.

    Table of Contents

    Key Features

    • Supports multiple LLMs (see list below)
    • Builds a local OpenAI API web service via Ollama, llama.cpp or vLLM.
    • Serves up a Chatbot web interface with customizable prompts, accessing external websites (URLs), vector databases and other sources (e.g. news, stocks, weather).

    Hardware Requirements

    • CPU: Intel, AMD or Apple Silicon
    • Memory: 8GB+ DDR4
    • Disk: 128G+ SSD
    • GPU: NVIDIA (e.g. GTX 1060 6GB, RTX 3090 24GB) or Apple M1/M2
    • OS: Ubuntu Linux, MacOS
    • Software: Python 3, CUDA Version: 12.2

    Quickstart

    TODO - Quick start setup script.

    Manual Setup

    # Clone the project
    git clone https://github.com/jasonacox/TinyLLM.git
    cd TinyLLM
    

    Run a Local LLM

    To run a local LLM, you will need an inference server for the model. This project recommends these options: vLLM, llama-cpp-python, and Ollama. All of these provide a built-in OpenAI API compatible web server that will make it easier for you to integrate with other tools.

    Ollama Server (Option 1)

    The Ollama project has made it super easy to install and run LLMs on a variety of systems (MacOS, Linux, Windows) with limited hardware. It serves up an OpenAI compatible API as well. The underlying LLM engine is llama.cpp. Like llama.cpp, the downside with this server is that it can only handle one session/prompt at a time. To run the Ollama server container:

    # Install and run Ollama server
    docker run -d --gpus=all \
        -v $PWD/ollama:/root/.ollama \
        -p 11434:11434 \
        -p 8000:11434 \
        --restart unless-stopped \
        --name ollama \
        ollama/ollama
    
    # Download and test run the llama3 model
    docker exec -it ollama ollama run llama3
    
    # Tell server to keep model loaded in GPU
    curl http://localhost:11434/api/generate -d '{"model": "llama3", "keep_alive": -1}'
    

    Ollama support several models (LLMs): https://ollama.com/library If you set up the docker container mentioned above, you can down and run them using:

    # Download and run Phi-3 Mini, open model by Microsoft.
    docker exec -it ollama ollama run phi3
    
    # Download and run mistral 7B model, by Mistral AI
    docker exec -it ollama ollama run mistral
    

    If you use the TinyLLM Chatbot (see below) with Ollama, make sure you specify the model via: LLM_MODEL="llama3" This will cause Ollama to download and run this model. It may take a while to start on first run unless you run one of the ollama run or curl commands above.

    Keeping models resident (no reloads)

    If the first token of a reply takes 30 seconds, the model was probably loaded, not slow. Ollama unloads idle models after 5 minutes, keeps only 3 loaded by default, and reserves KV-cache memory for the model's full default context (262k tokens for the Qwen3 family) — so one big model can evict the rest. Fix it once in the Ollama service environment:

    OLLAMA_KEEP_ALIVE=-1            # never unload on idle
    OLLAMA_MAX_LOADED_MODELS=3      # how many stay resident (size to your RAM)
    OLLAMA_CONTEXT_LENGTH=16384     # caps the KV reservation: 8192 on 16 GB, 16384 on 32 GB, 32768 on 64 GB+
    

    The chatbot can pin its own model: set KEEP_ALIVE=-1 and it sends Ollama a keep-alive for the active model at startup and whenever you switch with /model. The model dialog and /model list mark models that are ● resident (answer immediately) versus ○ not loaded (will load on first use), read live from Ollama's /api/ps.

    vLLM Server (Option 2)

    vLLM offers a robust OpenAI API compatible web server that supports multiple simultaneous inference threads (sessions). It automatically downloads the models you specify from HuggingFace and runs extremely well in containers. vLLM requires GPUs with more VRAM since it uses non-quantized models. AWQ models are also available and more optimizations are underway in the project to reduce the memory footprint. Note, for GPUs with a compute capability of 6 or less, Pascal architecture (see GPU table), follow details here instead.

    # Build Container
    cd vllm
    ./build.sh 
    
    # Make a Directory to store Models
    mkdir models
    
    # Edit run.sh or run-awq.sh to pull the model you want to use. Mistral is set by default.
    # Run the Container - This will download the model on the first run
    ./run.sh  
    
    # The trailing logs will be displayed so you can see the progress. Use ^C to exit without
    # stopping the container. 
    

    Llama-cpp-python Server (Option 3)

    The llama-cpp-python's OpenAI API compatible web server is easy to set up and use. It runs optimized GGUF models that work well on many consumer grade GPUs with small amounts of VRAM. As with Ollama, a downside with this server is that it can only handle one session/prompt at a time. The steps below outline how to setup and run the server via command line. Read the details in llmserver to see how to set it up as a persistent service or docker container on your Linux host.

    # Uninstall any old version of llama-cpp-python
    pip3 uninstall llama-cpp-python -y
    
    # Linux Target with Nvidia CUDA support
    CMAKE_ARGS="-DLLAMA_CUBLAS=on" FORCE_CMAKE=1 pip3 install llama-cpp-python==0.2.27 --no-cache-dir
    CMAKE_ARGS="-DLLAMA_CUBLAS=on" FORCE_CMAKE=1 pip3 install llama-cpp-python[server]==0.2.27 --no-cache-dir
    
    # MacOS Target with Apple Silicon M1/M2
    CMAKE_ARGS="-DLLAMA_METAL=on" pip3 install -U llama-cpp-python --no-cache-dir
    pip3 install 'llama-cpp-python[server]'
    
    # Download Models from HuggingFace
    cd llmserver/models
    
    # Get the Mistral 7B GGUF Q-5bit model Q5_K_M and Meta LLaMA-2 7B GGUF Q-5bit model Q5_K_M
    wget https://huggingface.co/TheBloke/Mistral-7B-Instruct-v0.1-GGUF/resolve/main/mistral-7b-instruct-v0.1.Q5_K_M.gguf
    wget https://huggingface.co/TheBloke/Llama-2-7b-Chat-GGUF/resolve/main/llama-2-7b-chat.Q5_K_M.gguf
    
    # Run Test - API Server
    python3 -m llama_cpp.server \
        --model ./models/mistral-7b-instruct-v0.1.Q5_K_M.gguf \
        --host localhost \
        --n_gpu_layers 99 \
        --n_ctx 2048 \
        --chat_format llama-2
    

    Run a Chatbot

    The TinyLLM Chatbot is a simple web based python FastAPI app that allows you to chat with an LLM using the OpenAI API. It supports multiple sessions and remembers your conversational history. Some RAG (Retrieval Augmented Generation) features including:

    • Summarizing external websites and PDFs (paste a URL in chat window)
    • List top 10 headlines from current news (use /news)
    • Display company stock symbol and current stock price (use /stock <company>)
    • Provide current weather conditions (use /weather <location>)
    • Use a vector databases for RAG queries - see RAG page for details
    # Move to chatbot folder
    cd ../chatbot
    touch prompts.json
    
    # Pull and run latest container - see run.sh
    docker run \
        -d \
        -p 5000:5000 \
        -e PORT=5000 \
        -e OPENAI_API_BASE="http://localhost:8000/v1" \
        -e LLM_MODEL="tinyllm" \
        -e USE_SYSTEM="false" \
        -e SENTENCE_TRANSFORMERS_HOME=/app/.tinyllm \
        -v $PWD/.tinyllm:/app/.tinyllm \
        --name chatbot \
        --restart unless-stopped \
        jasonacox/chatbot
    

    Example Session

    Open http://localhost:5000 - Example session:

    Read URLs

    If a URL is pasted in the text box, the chatbot will read and summarize it.

    Current News

    The /news command will fetch the latest news and have the LLM summarize the top ten headlines. It will store the raw feed in the context prompt to allow follow-up questions.

    Manual Setup

    You can also test the chatbot server without docker using the following.

    # Install required packages
    pip3 install fastapi uvicorn python-socketio jinja2 openai bs4 pypdf requests lxml aiohttp
    
    # Run the chatbot web server
    python3 server.py
    

    LLM Models

    Here are some suggested models that work well with llmserver (llama-cpp-python). You can test other models and different quantization, but in my experiments, the Q5_K_M models performed the best. Below are the download links from HuggingFace as well as the model card's suggested context length size and chat prompt mode.

    LLMQuantizedLink to DownloadContext LengthChat Prompt Mode
    7B Models
    Mistral v0.1 7B5-bitmistral-7b-instruct-v0.1.Q5_K_M.gguf4096llama-2
    Llama-2 7B5-bitllama-2-7b-chat.Q5_K_M.gguf2048llama-2
    Mistrallite 32K 7B5-bitmistrallite.Q5_K_M.gguf16384mistrallite (can be glitchy)
    10B Models
    Nous-Hermes-2-SOLAR 10.7B5-bitnous-hermes-2-solar-10.7b.Q5_K_M.gguf4096chatml
    13B Models
    Claude2 trained Alpaca 13B5-bitclaude2-alpaca-13b.Q5_K_M.gguf2048chatml
    Llama-2 13B5-bitllama-2-13b-chat.Q5_K_M.gguf2048llama-2
    Vicuna 13B v1.55-bitvicuna-13b-v1.5.Q5_K_M.gguf2048vicuna
    Mixture-of-Experts (MoE) Models
    Hai's Mixtral 11Bx2 MoE 19B5-bitmixtral_11bx2_moe_19b.Q5_K_M.gguf4096chatml
    Mixtral-8x7B v0.13-bitMixtral-8x7B-Instruct-v0.1-GGUF4096llama-2
    Mixtral-8x7B v0.14-bitMixtral-8x7B-Instruct-v0.1-GGUF4096llama-2

    Here are some suggested models that work well with vLLM.

    LLMQuantizedLink to DownloadContext LengthLicense
    Mistral v0.1 7BNonemistralai/Mistral-7B-Instruct-v0.132kApache 2
    Mistral v0.2 7BNonemistralai/Mistral-7B-Instruct-v0.232kApache 2
    Mistral v0.1 7B AWQAWQTheBloke/Mistral-7B-Instruct-v0.1-AWQ32kApache 2
    Mixtral-8x7BNonemistralai/Mixtral-8x7B-Instruct-v0.132kApache 2
    Pixtral-12B-2409 12B VisionNonemistralai/Pixtral-12B-2409128kApache 2
    Meta Llama-3 8BNonemeta-llama/Meta-Llama-3-8B-Instruct8kMeta
    Meta Llama-3.2 11B VisionFP8neuralmagic/Llama-3.2-11B-Vision-Instruct-FP8-dynamic128kMeta
    Qwen-2.5 7BNoneQwen/Qwen2.5-7B-Instruct128kApache 2
    Yi-1.5 9BNone01-ai/Yi-1.5-9B-Chat-16K16kApache 2
    Phi-3 Small 7BNonemicrosoft/Phi-3-small-8k-instruct16kMIT
    Phi-3 Medium 14BNonemicrosoft/Phi-3-medium-4k-instruct4kMIT
    Phi-3.5 Vision 4BNonemicrosoft/Phi-3.5-vision-instruct128kMIT
    Phi-4 14BNonemicrosoft/phi-416kMIT

    LLM Tools

    LLM

    A CLI utility (llm) and Python library for interacting with Large Language Models. To configure this tool to use your local LLM's OpenAI API:

    # Install llm command line tool
    pipx install llm
    
    # Location to store configuration files:
    dirname "$(llm logs path)"
    

    You define the model in the extra-openai-models.yaml file. Create this file in the directory discovered above. Edit the model_name and api_base to match your LLM OpenAI API setup:

    - model_id: tinyllm
      model_name: meta-llama/Meta-Llama-3.1-8B-Instruct
      api_base: "http://localhost:8000/v1"
    
    # Configure llm to use your local model
    llm models default tinyllm
    
    # Test
    llm "What is love?"
    

    References