You will build a pipeline that hooks into your Git workflow, extracts diffs from pull requests, sends them to a self-hosted DeepSeek Coder model for analysis, and returns structured code review comments — bugs found, security concerns, style issues, and suggested fixes. The end result: every PR gets an AI review within 60 seconds of opening, catching issues before human reviewers spend time on them. No code leaves your server. Here is the complete pipeline on dedicated GPU infrastructure.
Pipeline Architecture
| Stage | Tool | Input | Output |
|---|---|---|---|
| 1. Diff extraction | GitPython | PR branch vs main | File diffs |
| 2. Context gathering | File reader | Changed files | Full file context |
| 3. AI review | DeepSeek Coder 33B | Diff + context | Review comments |
| 4. Comment posting | Git forge API | Review comments | PR comments |
DeepSeek Coder Setup
# Start vLLM with DeepSeek Coder
python -m vllm.entrypoints.openai.api_server \
--model deepseek-ai/deepseek-coder-33b-instruct \
--quantization gptq \
--max-model-len 16384 \
--port 8000
DeepSeek Coder 33B at 4-bit quantisation uses approximately 20GB VRAM. The 16K context length accommodates large diffs. For smaller GPUs, use the 6.7B variant. Deploy via vLLM for efficient batched inference when multiple PRs arrive simultaneously.
Diff Extraction and Analysis
import subprocess
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8000/v1", api_key="none")
def get_diff(repo_path: str, base_branch: str = "main") -> str:
result = subprocess.run(
["git", "diff", base_branch, "--unified=5"],
cwd=repo_path, capture_output=True, text=True
)
return result.stdout
def review_diff(diff: str) -> dict:
response = client.chat.completions.create(
model="deepseek-ai/deepseek-coder-33b-instruct",
messages=[{
"role": "system",
"content": """You are an expert code reviewer. Analyse the diff and return JSON:
{"comments": [{"file": "path", "line": N, "severity": "bug|warning|info",
"message": "description", "suggestion": "fixed code if applicable"}],
"summary": "Overall assessment"}
Focus on: bugs, security issues, performance problems, and logic errors.
Do NOT comment on style preferences or trivial formatting."""
}, {
"role": "user",
"content": f"Review this diff:\n\n{diff}"
}],
max_tokens=2000, temperature=0.1
)
return parse_review(response.choices[0].message.content)
Adding File Context
Reviewing diffs without surrounding code misses context-dependent bugs. For each changed file, include the full file (up to a token budget) so the model understands the codebase structure. Prioritise files with the most changes. For large repositories, include only the changed functions plus their callers. Open-source code models handle this context better with longer context windows.
Git Webhook Integration
from fastapi import FastAPI, Request
app = FastAPI()
@app.post("/webhook/pr")
async def handle_pr(request: Request):
payload = await request.json()
if payload.get("action") != "opened":
return {"status": "skipped"}
repo_url = payload["repository"]["clone_url"]
branch = payload["pull_request"]["head"]["ref"]
# Clone and diff
repo_path = clone_and_checkout(repo_url, branch)
diff = get_diff(repo_path)
# AI review
review = review_diff(diff)
# Post comments back to PR
post_review_comments(
repo=payload["repository"]["full_name"],
pr_number=payload["pull_request"]["number"],
comments=review["comments"]
)
return {"status": "reviewed", "comments": len(review["comments"])}
Quality Tuning
Reduce false positives by adjusting the system prompt to match your team’s coding standards. Filter out low-confidence suggestions. Track which AI comments humans mark as helpful versus dismissed, and use that feedback to refine prompts. For specialised codebases, provide example reviews in the system prompt. Teams processing proprietary code benefit from self-hosting — no code snippets transit to external APIs. Combine with chatbot interfaces for interactive code Q&A. See pipeline tutorials for related workflows, use cases for development tool examples, and infrastructure guides for production deployment. Explore RAG integration to give the reviewer access to your documentation.
Code AI GPU Servers
Dedicated GPU servers for DeepSeek Coder and code analysis workloads. Keep proprietary code on your own infrastructure. UK-hosted.
Browse GPU Servers