Create model directory
Here's a complete **end-to-end guide** to create your local AI coding assistant with DeepSeek integration:
Here's a complete end-to-end guide to create your local AI coding assistant with DeepSeek integration:
Step 1: System Preparation
Hardware Requirements:
- Minimum: 16GB RAM + NVIDIA GPU (8GB VRAM)
- Recommended: 32GB RAM + NVIDIA RTX 3090/4090 (24GB VRAM)
Software Requirements:
- VS Code
- Docker Desktop
- NVIDIA Container Toolkit
- Python 3.10+
Step 2: Model Setup
- Download Models:
# Create model directory
mkdir -p ~/ai_models/deepseek && cd ~/ai_models
# Download DeepSeek-Coder (7B quantized GGUF version)
wget https://huggingface.co/TheBloke/deepseek-coder-6.7B-instruct-GGUF/resolve/main/deepseek-coder-6.7b-instruct.Q5_K_M.gguf
- Get Access Tokens:
- Hugging Face Token: https://huggingface.co/settings/tokens
- (Optional) Llama 2 Access: https://ai.meta.com/resources/models-and-libraries/llama-downloads/
Step 3: Docker Setup
- Create Project Structure:
ai-coding-agent/
├── docker/
│ ├── Dockerfile
│ └── requirements.txt
├── app/
│ ├── server.py
│ └── agents/
├── vscode-extension/
│ └── extension.js
└── docker-compose.yml
- docker/Dockerfile:
FROM nvidia/cuda:12.2.0-base-ubuntu22.04
RUN apt-get update && apt-get install -y \
python3.10 \
python3-pip \
git \
wget \
&& rm -rf /var/lib/apt/lists/*
COPY docker/requirements.txt .
RUN pip install -r requirements.txt
WORKDIR /app
COPY . /app
CMD ["python3", "app/server.py"]
- docker/requirements.txt:
fastapi>=0.104.0
uvicorn>=0.24.0
llama-cpp-python>=0.2.23
langchain>=0.1.0
transformers>=4.38.0
python-socketio>=5.11.0
watchdog>=3.0.0
Step 4: AI Server Implementation
app/server.py:
from fastapi import FastAPI, WebSocket
from llama_cpp import Llama
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
import uvicorn
app = FastAPI()
# Load DeepSeek model
llm = Llama(
model_path="/app/models/deepseek-coder-6.7b-instruct.Q5_K_M.gguf",
n_ctx=4096,
n_gpu_layers=35,
n_threads=8
)
class CodeChangeHandler(FileSystemEventHandler):
def on_modified(self, event):
if not event.is_directory and event.src_path.endswith(".py"):
with open(event.src_path, "r") as f:
code = f.read()
analysis = analyze_code(code)
# Send to all connected VS Code instances
manager.broadcast(analysis)
@app.websocket("/ws")
async def websocket_endpoint(websocket: WebSocket):
await websocket.accept()
while True:
code = await websocket.receive_text()
response = llm.create_chat_completion(
messages=[{"role": "user", "content": f"Analyze and debug:\n{code}"}],
temperature=0.3
)
await websocket.send_text(response['choices'][0]['message']['content'])
def analyze_code(code: str) -> str:
prompt = f"""As an expert code analyst, perform these tasks:
1. Static code analysis
2. Potential bug detection
3. Security vulnerability check
4. Performance optimization suggestions
Code:
{code}
Provide structured response in Markdown:"""
return llm(prompt, max_tokens=512)
if __name__ == "__main__":
# Start file watcher
event_handler = CodeChangeHandler()
observer = Observer()
observer.schedule(event_handler, path=".", recursive=True)
observer.start()
# Start server
uvicorn.run(app, host="0.0.0.0", port=8000)
Step 5: VS Code Extension
vscode-extension/extension.js:
const vscode = require('vscode');
const WebSocket = require('ws');
function activate(context) {
const ws = new WebSocket('ws://localhost:8000/ws');
const diagnostics = vscode.languages.createDiagnosticCollection('ai-analysis');
// Real-time code analysis
vscode.workspace.onDidChangeTextDocument(e => {
const code = e.document.getText();
ws.send(code);
});
// Handle AI responses
ws.on('message', data => {
const analysis = JSON.parse(data);
const uri = vscode.window.activeTextEditor.document.uri;
// Show diagnostics
diagnostics.set(uri, parseDiagnostics(analysis));
// Show suggestions
vscode.window.showInformationMessage(
analysis.summary,
...analysis.suggestions
);
});
// Debugger integration
vscode.debug.registerDebugAdapterTrackerFactory('*', {
createDebugAdapterTracker(session) {
return {
onDidSendMessage: m => {
if (m.event === 'stopped') {
ws.send(JSON.stringify({
type: 'debug',
data: m.body
}));
}
}
};
}
});
}
function parseDiagnostics(analysis) {
return analysis.issues.map(issue => {
const range = new vscode.Range(
issue.line-1, 0,
issue.line-1, Number.MAX_VALUE
);
return new vscode.Diagnostic(
range,
issue.message,
vscode.DiagnosticSeverity.Warning
);
});
}
exports.activate = activate;
Step 6: Build & Run
- Start AI Server:
docker-compose up --build
- Install VS Code Extension:
- Package the extension:
vsce package - Install the
.vsixfile in VS Code
- Configure Workspace:
// .vscode/settings.json
{
"ai-agent.modelPath": "~/ai_models/deepseek",
"ai-agent.enableRealTimeAnalysis": true,
"ai-agent.suggestionLevel": "advanced"
}
Step 7: Usage Workflow
- Real-Time Analysis:
- Open any code file
- AI automatically analyzes on save/change
- Suggestions appear as:
- Inline diagnostics
- Quick-fix lightbulbs
- Code completion suggestions
- Debug Integration:
- Start debugging session
- AI automatically:
- Analyzes stack traces
- Suggests potential fixes
- Recommends test cases
- Manual Commands:
AI: Full Codebase Analysis(Ctrl+Shift+A)AI: Optimize Current File(Ctrl+Shift+O)AI: Security Audit(Ctrl+Shift+S)
Step 8: Advanced Configuration
- Model Switching:
# In server.py
MODELS = {
'deepseek-7b': 'deepseek-coder-6.7b-instruct.Q5_K_M.gguf',
'llama2-13b': 'llama-2-13b-chat.Q4_K_M.gguf'
}
def switch_model(model_name):
global llm
llm = Llama(
model_path=f"/app/models/{MODELS[model_name]}",
n_gpu_layers=35
)
- Custom Prompts:
# Create prompts.yaml
analysis_prompt: |
You are Senior Software Engineer analyzing {language} code.
Perform these tasks:
1. Identify {level} issues
2. Suggest optimizations
3. Security audit
4. Provide code examples
Code:
{code}
Step 9: Security Considerations
- Local Network Only:
# In server.py
app = FastAPI(servers=[{"url": "http://localhost:8000"}])
- Model Sandboxing:
# Add to Dockerfile
RUN useradd -m aiuser && chown -R aiuser:aiuser /app
USER aiuser
Final Step: Test Your Setup
- Validation Tests:
# Test API endpoint
curl -X POST http://localhost:8000/analyze -d 'print("test")'
# Check GPU utilization
docker exec -it ai-container nvidia-smi
# Test WebSocket connection
wscat -c ws://localhost:8000/ws
- VS Code Test Cases:
- Introduce intentional bug in code
- Verify AI detection within 2-3 seconds
- Test debug session breakpoints
- Verify code completion suggestions
This setup provides a complete local AI development environment with:
- Real-time code analysis
- Intelligent debugging assistance
- Security vulnerability detection
- Performance optimization suggestions
- Full codebase understanding
- Context-aware completions
- Multi-model support
Let me know if you need any specific component explained in more detail!
Related Documents
Comprehensive AI Assistant Tools Reference
title: Comprehensive AI Assistant Tools Reference
iOS Deployment Guide
**Introduction:** Deploying the Krome app to iOS (iPhone/iPad) is a bit more involved due to Apple’s ecosystem requirements. This guide will cover setting up an iOS development environment, building the Tauri app for iOS, publishing on Apple’s App Store, alternative distribution options like TestFlight or Enterprise, the App Store review process, common pitfalls, and CI/CD for iOS. As before, we assume you know general development concepts but are new to iOS specifics.
How to Add Resources to Your FastMCP Server
In the Model Context Protocol (MCP), there are three main capabilities:
Continue.dev MCP Integration Setup Guide
Edit your Continue.dev configuration file: