A lightweight API server and CLI for running LLM models
Project description
A lightweight, CLI modular tool for running Large Language Models (LLMs) & SLMs from Hugging Face.
PipeLM provides an intuitive CLI interface for interactive chat and a robust FastAPI server to integrate LLMs seamlessly into your applications.
Overview
PipeLM simplifies interaction with AI models, allowing you to:
- ๐ฅ Download and manage models from Hugging Face.
- ๐ Serve models through a standardized REST API.
- ๐ฌ Test prompts via an interactive chat interface & a client
- ๐ Maintain conversation history.
- ๐ Easily switch models with single command.
Features
- Interactive CLI Chat: Chat directly from your terminal.
- FastAPI Server: REST APIs with health monitoring.
- Efficient Model Management: Download and manage models easily.
- Support for different models: text2text and image2text models are supported
- Easy Authentication: Easily access HF models using only HF_TOKEN
- Client-Server Architecture: Model deployed on server can be accessed by client
- Docker Support: Containerize your models for better isolation.
- GPU Acceleration: Automatically utilize available GPUs.
- Model Quantization: Reduce memory usage (4-bit and 8-bit).
- Conversation History: Persistent chat context.
- Rich Terminal Interface: Enhanced CLI with markdown rendering.
- Robust Error Handling: Good handling of issues.
Installation
๐ป From Source (Recommended)
Step 1: Create a Python Virtual Environment
# Clone the source repository
git clone https://github.com/kashyaprparmar/PipeLM
cd PipeLM
# Create virtual environment with Python's venv
python -m venv .venv
# Activate the environment
# On Linux/macOS:
source .venv/bin/activate
# On Windows:
.venv\Scripts\activate
Step 2: Install uv Within the Virtual Environment
# Install uv package manager
pip install uv
Step 3: Install dependencies using uv
# Install the package with uv (recommended)
uv pip install -e .
# Install just the dependencies from requirements.txt
uv pip install -r requirements.txt
๐ฆ From PyPI (in development)
pip install pipelm
๐ณ With Docker
git clone https://github.com/kashyaprparmar/PipeLM
cd PipeLM
docker build -f docker/Dockerfile -t pipelm .
docker run -p 8080:8080 -v pipelm_data:/root/.pipelm -e HF_TOKEN=your_token -e MODEL_NAME=HuggingFaceTB/SmolLM2-1.7B-Instruct pipelm
Usage
Login with HF_TOKEN
pipelm login
# Enter your HF_TOKEN to terminal
Download a Huggingface Model
# Download a model with particular allowed patterns
pipelm download HuggingFaceTB/SmolLM2-1.7B-Instruct --include ['*.json','*.safetensors']
List all Downloaded Models
pipelm list
Interactive Chat
# (Streaming is ENABLED BY DEFAULT)
# Start chatting with model
pipelm chat HuggingFaceTB/SmolLM2-1.7B-Instruct
# Chatting with local model ( by default loads to port 8080)
pipelm chat /path/to/local/model
# Chatting using quantization
pipelm chat HuggingFaceTB/SmolLM2-1.7B-Instruct --quantize 4bit
# Chatting with model (Streaming DISABLED)
pipelm chat HuggingFaceTB/SmolLM2-1.7B-Instruct --no-stream
๐ Start API Server
pipelm server HuggingFaceTB/SmolLM2-1.7B-Instruct --port 8080
# Using local model
pipelm server /path/to/local/model --port 8080
# With quantization
pipelm server HuggingFaceTB/SmolLM2-1.7B-Instruct --quantize 8bit
Making Client Requests to model on Server
# Making client request on a text2text model
pipelm client HuggingFaceTB/SmolLM2-1.7B-Instruct
--prompt "Summarize the benefits of solar energy."
# Making client request on a text2text model with some model config
pipelm client HuggingFaceTB/SmolLM2-1.7B-Instruct
--prompt "Summarize the benefits of solar energy."
--max-tokens 80
--top-p 0.95
# Making client request on a image2text model with some model config
pipelm client HuggingFaceTB/SmolVLM-500M-Instruct
--port 8080
--model-type image2text
--image "/home/kashyap/Desktop/mywork/PipeLM/assets/logo.png"
--prompt "Describe what you see."
--max-tokens 80
--top-p 0.95
--no-stream
๐ณ Docker Compose
export HF_TOKEN=your_token
docker-compose up -d pipelm
API Endpoints
Quick Commands
Check Server Health:
curl http://localhost:8080/health
Script for Testing a Sample Prompt
# Checks the server health and runs a sample prompt in the server
python client.py
Send a Sample Prompt (cURL):
curl -X POST http://localhost:8080/generate \
-H "Content-Type: application/json" \
-d '{
"messages": [{"role": "user", "content": "Explain the difference between AI and machine learning."}],
"max_tokens": 200,
"temperature": 0.7,
"top_p": 0.9
}'
GET /health
Health status of server and model.
{
"status": "healthy",
"model": "HuggingFaceTB/SmolLM2-1.7B-Instruct",
"uptime": 42.5
}
GET /docs
Swagger UI for API documentation.
POST /generate
Generate text from conversation history.
Request:
{
"messages": [
{"role": "user", "content": "What is artificial intelligence?"}
],
"max_tokens": 1024,
"temperature": 0.7,
"top_p": 0.9
}
Response:
{
"generated_text": "Artificial intelligence (AI) refers to the simulation of human intelligence in machines..."
}
Chat Commands
/exitor/quitโ Exit chat/clearโ Clear conversation history/infoโ Display current model information
Environment Variables
HF_TOKEN: Your Hugging Face token (required).MODEL_DIR: Local model directory.PORT: Server port (default: 8080).
Project Structure
PipeLM/
โโโ pipelm/ # Main package
โ โโโ __init__.py
โ โโโ cli.py
โ โโโ server.py
โ โโโ client.py
โ โโโ downloader.py
โ โโโ chat.py
โ โโโ utils.py
โโโ docker/ # Docker setup
โ โโโ Dockerfile
โ โโโ docker-compose.yml
โโโ setup.py
โโโ README.md
โโโ requirements.txt
Requirements
- Python 3.8+
- Torch (GPU support recommended)
- 16+ GB RAM (model-dependent)
- CUDA-compatible GPU (recommended)
Troubleshooting
Model Download Issues
If you encounter issues downloading models:
- Check your Hugging Face token:
- Create or verify your token at https://huggingface.co/settings/tokens (MAKE SURE TO GENERATE A READ/WRITE HF ACCESS TOKEN)
- Set it in your environment as
export HF_TOKEN=your_token_here - Or store it in
.envfile asHF_TOKEN=your_token_here
- Network issues:
- Check your internet connection
- Verify you have permissions to download the model
Server Startup Issues
If the server fails to start:
- Check if another process is using port 8080:
- Use a different port:
pipelm server HuggingFaceTB/SmolLM2-1.7B-Instruct --port 8081
- Use a different port:
- Verify Python dependencies:
- Ensure all required packages are installed:
pip install -r requirements.txt
- Ensure all required packages are installed:
Memory Issues
If you encounter memory errors:
- Choose a smaller model
- Try quantization:
pipelm chat HuggingFaceTB/SmolLM2-1.7B-Instruct --quantize 4bit - Ensure you have enough RAM and GPU VRAM if using CUDA
Model Storage
Models are downloaded to:
- Linux/Mac:
~/.pipelm/models/[sanitized_model_name]OR.local/share/pipelm/modelsOR/home/kashyap/snap/code/190/.local/share/pipelm/models - Windows:
C:\Users\[username]\AppData\Local\pipelm\pipelm\models\[sanitized_model_name]
When using Docker, models are stored in /root/.pipelm/models/ in the container, typically mapped to a persistent volume.
Contributing
Contributions are welcome! Submit a Pull Request.
License
MIT License. See LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pipelm-0.1.2.tar.gz.
File metadata
- Download URL: pipelm-0.1.2.tar.gz
- Upload date:
- Size: 25.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aab92fbae42355bac0706115f35cf509baa04790aca09ebe8925cb16de518859
|
|
| MD5 |
c27e7f8131dc54317ec0d9ff2fc90789
|
|
| BLAKE2b-256 |
070ca85a86c5279592ed90fa072fba5c051d130cafa9c0fbe75244da44c26266
|
File details
Details for the file pipelm-0.1.2-py3-none-any.whl.
File metadata
- Download URL: pipelm-0.1.2-py3-none-any.whl
- Upload date:
- Size: 25.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
345e0499ffad3ea39bad7a86d08a4b2672938716f346387e954d2e8b199724ac
|
|
| MD5 |
1de923a57b45c37ab57cd7d79099724d
|
|
| BLAKE2b-256 |
925da99223c9a887228bd244545849f90a7768d108973fbddb6317266a3edb2c
|