neuralbroker commited on
Commit
e24f62d
Β·
verified Β·
1 Parent(s): e89e956

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +166 -0
README.md ADDED
@@ -0,0 +1,166 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # BlitzKode
2
+
3
+ BlitzKode is a local AI coding assistant that runs entirely on your machine. It generates code in Python, JavaScript, Java, C++, and other languages through a web interface or API. The model is fine-tuned from Qwen2.5-1.5B and quantized to GGUF format for fast inference.
4
+
5
+ ## Tech Stack
6
+
7
+ - Model: Qwen2.5-1.5B (fine-tuned, GGUF format)
8
+ - Backend: Python, FastAPI, uvicorn
9
+ - Inference: llama.cpp / llama-cpp-python
10
+ - Frontend: Vanilla HTML, CSS, JavaScript
11
+ - Training: HuggingFace Transformers, PEFT, TRL
12
+
13
+ ## Features
14
+
15
+ - Local code generation without external API calls
16
+ - Real-time streaming responses (token-by-token)
17
+ - Web UI with dark theme, conversation history, copy-to-clipboard
18
+ - REST API with streaming (SSE) support
19
+ - Multi-language support: Python, JavaScript, Java, C++, TypeScript, SQL
20
+ - Conversation context across multiple turns
21
+ - Configurable via environment variables
22
+ - Optional API key authentication
23
+ - CPU and GPU inference support
24
+ - Docker support
25
+
26
+ ## Prerequisites
27
+
28
+ - Python 3.9+
29
+ - GGUF model file (`blitzkode.gguf`)
30
+ - 4GB+ RAM recommended
31
+
32
+ ## Installation
33
+
34
+ ```bash
35
+ # Clone the repository
36
+ git clone https://github.com/neuralbroker/blitzkode.git
37
+ cd blitzkode
38
+
39
+ # Install dependencies
40
+ pip install -r requirements.txt
41
+
42
+ # Ensure model file exists
43
+ # Place blitzkode.gguf in the project root, or set BLITZKODE_MODEL_PATH
44
+ ```
45
+
46
+ ## Usage
47
+
48
+ Start the server:
49
+
50
+ ```bash
51
+ python server.py
52
+ ```
53
+
54
+ Open `http://localhost:7860` in your browser.
55
+
56
+ ### Docker
57
+
58
+ ```bash
59
+ docker build -t blitzkode .
60
+ docker run -p 7860:7860 -v ./blitzkode.gguf:/app/blitzkode.gguf blitzkode
61
+ ```
62
+
63
+ ### API Examples
64
+
65
+ ```bash
66
+ # Generate code
67
+ curl -X POST http://localhost:7860/generate -H 'Content-Type: application/json' -d '{
68
+ \"prompt\": \"Write a Python function to reverse a string\"
69
+ }'
70
+
71
+ # Stream tokens
72
+ curl -X POST http://localhost:7860/generate/stream -H 'Content-Type: application/json' -d '{
73
+ \"prompt\": \"Binary search implementation in Python\"
74
+ }'
75
+
76
+ # With conversation history
77
+ curl -X POST http://localhost:7860/generate -H 'Content-Type: application/json' -d '{
78
+ \"prompt\": \"Add error handling to that function\",
79
+ \"messages\": [
80
+ {\"role\": \"user\", \"content\": \"Write a Python function to reverse a string\"},
81
+ {\"role\": \"assistant\", \"content\": \"def reverse_string(s): return s[::-1]\"}
82
+ ]
83
+ }'
84
+
85
+ # Check server health
86
+ curl http://localhost:7860/health
87
+
88
+ # Get API info
89
+ curl http://localhost:7860/info
90
+ ```
91
+
92
+ ### API Parameters
93
+
94
+ | Parameter | Type | Default | Description |
95
+ |-----------|------|---------|-------------|
96
+ | prompt | string | required | Your question or request |
97
+ | messages | array | [] | Conversation history (last 8 messages) |
98
+ | temperature | float | 0.5 | Response randomness (0.0-2.0) |
99
+ | max_tokens | int | 256 | Maximum tokens to generate |
100
+ | top_p | float | 0.95 | Nucleus sampling threshold |
101
+ | top_k | int | 20 | Top-k sampling |
102
+ | repeat_penalty | float | 1.05 | Repetition penalty |
103
+
104
+ ## Project Structure
105
+
106
+ ```
107
+ blitzkode/
108
+ β”œβ”€β”€ server.py # FastAPI backend, main entry point
109
+ β”œβ”€β”€ blitzkode.gguf # Quantized model file (~3GB)
110
+ β”œβ”€β”€ Dockerfile # Docker container
111
+ β”œβ”€β”€ requirements.txt # Serving dependencies
112
+ β”œβ”€β”€ requirements-training.txt # Training dependencies
113
+ β”œβ”€β”€ LICENSE # MIT License
114
+ β”œβ”€β”€ .env.example # Environment variable template
115
+ β”œβ”€β”€ frontend/
116
+ β”‚ └── index.html # Web UI (HTML/CSS/JS)
117
+ β”œβ”€β”€ tests/
118
+ β”‚ └── test_server.py # HTTP endpoint tests
119
+ β”œβ”€β”€ scripts/
120
+ β”‚ β”œβ”€β”€ train_sft.py # Supervised fine-tuning (LoRA)
121
+ β”‚ β”œβ”€β”€ train_grpo.py # Reward-based SFT continuation
122
+ β”‚ β”œβ”€β”€ train_dpo.py # Direct Preference Optimization
123
+ β”‚ β”œβ”€β”€ export_gguf.py # Merge checkpoints and export GGUF
124
+ β”‚ └── test_inference.py # Direct model inference test
125
+ β”œβ”€β”€ checkpoints/ # Trained LoRA adapter checkpoints
126
+ β”œβ”€β”€ exported/ # Merged model for GGUF export
127
+ β”œβ”€β”€ datasets/
128
+ β”‚ └── raw/ # Training datasets
129
+ β”œβ”€β”€ models/ # Base model files
130
+ β”œβ”€β”€ .github/workflows/
131
+ β”‚ └── ci.yml # GitHub Actions CI
132
+ β”œβ”€β”€ MODEL_CARD.md # Model documentation
133
+ └── README.md # This file
134
+ ```
135
+
136
+ ## Environment Variables
137
+
138
+ | Variable | Default | Description | Example |
139
+ |----------|---------|-------------|---------|
140
+ | BLITZKODE_PORT | 7860 | Server port | 8080 |
141
+ | BLITZKODE_HOST | 0.0.0.0 | Server bind address | 127.0.0.1 |
142
+ | BLITZKODE_GPU_LAYERS | 0 | GPU layers (0=CPU only) | 35 |
143
+ | BLITZKODE_N_CTX | 2048 | Context window size | 4096 |
144
+ | BLITZKODE_THREADS | auto | CPU threads for inference | 8 |
145
+ | BLITZKODE_BATCH | 128 | Batch size for processing | 256 |
146
+ | BLITZKODE_WORKERS | 2 | Concurrent request workers | 4 |
147
+ | BLITZKODE_MODEL_PATH | blitzkode.gguf | Path to model file | /path/to/model.gguf |
148
+ | BLITZKODE_FRONTEND_PATH | frontend/index.html | Path to frontend file | ./ui.html |
149
+ | BLITZKODE_MAX_PROMPT_LENGTH | 4000 | Max prompt characters | 8000 |
150
+ | BLITZKODE_PRELOAD_MODEL | false | Load model on startup | true |
151
+ | BLITZKODE_CORS_ORIGINS | * | CORS origins (comma-separated) | http://localhost:3000 |
152
+ | BLITZKODE_API_KEY | empty | API key (empty=disabled) | my-secret-key |
153
+
154
+ ## Tests
155
+
156
+ ```bash
157
+ python -m unittest discover -s tests -v
158
+ ```
159
+
160
+ ## Contributing
161
+
162
+ Contributions are welcome. Open an issue first for major changes.
163
+
164
+ ## License
165
+
166
+ MIT License. See LICENSE file for details.