File size: 2,151 Bytes
9ec099b
7999da7
 
 
 
9ec099b
7999da7
9ec099b
 
 
7999da7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
---
title: CodeDebug Multi-LLM Debugger
emoji: ⚡
colorFrom: blue
colorTo: purple
sdk: docker
app_port: 7860
pinned: false
---

# ⚡ CodeDebug — Multi-LLM Debugging Engine (LangChain)

A code debugging assistant that queries **3 LLMs in parallel** using LangChain LCEL chains,
then uses **Qwen3 as a judge** to synthesize the best final answer.

## Architecture

```
Your query
    ├──▶ Trinity Large  (arcee-ai)  ─╮
    ├──▶ StepFun Flash  (stepfun)   ─┼──▶ Qwen3 Judge ──▶ Reasoning + Final Answer
    └──▶ Nemotron Nano  (nvidia)   ─╯

LangChain Stack:
  PANEL_PROMPT | ChatOpenAI | StrOutputParser   × 3  (asyncio.gather)
  JUDGE_PROMPT | ChatOpenAI | StrOutputParser   × 1
```

## Setup on Hugging Face Spaces

1. Fork this Space
2. **Settings → Variables and secrets → New secret**
   - Name:  `OPENROUTER_API_KEY`
   - Value: your key from [openrouter.ai](https://openrouter.ai)
3. The Space rebuilds automatically (~2 min)

## Local development

```bash
# 1. Create .env
echo "OPENROUTER_API_KEY=sk-or-v1-..." > .env

# 2. Install
pip install -r requirements.txt

# 3. Run
uvicorn app.main:app --reload --port 7860
```

Open http://localhost:7860

## File structure

```
├── app/
│   ├── __init__.py
│   ├── config.py        # pydantic-settings
│   ├── prompts.py       # LangChain ChatPromptTemplates
│   ├── llm_factory.py   # ChatOpenAI factory (OpenRouter)
│   ├── llm_chain.py     # LCEL pipeline (panel + judge)
│   └── main.py          # FastAPI routes
├── frontend/
│   └── index.html       # Single-file UI
├── requirements.txt
├── Dockerfile
└── README.md
```

## API

`POST /api/v1/debug`
```json
{ "question": "Why does my Python function return None?", "temperature": 0.3 }
```

Response:
```json
{
  "question": "...",
  "panel": [
    { "model": "...", "label": "Trinity Large", "response": "...", "latency_ms": 1200, "error": null },
    ...
  ],
  "judge": {
    "reasoning": "...",
    "final_answer": "...",
    "latency_ms": 3100,
    "error": null
  },
  "total_ms": 4300
}
```