pkheria commited on
Commit
f8b5831
·
1 Parent(s): 49fb46a

completed

Browse files
Files changed (3) hide show
  1. .DS_Store +0 -0
  2. app.py +1 -58
  3. index.html +126 -1
.DS_Store CHANGED
Binary files a/.DS_Store and b/.DS_Store differ
 
app.py CHANGED
@@ -155,42 +155,6 @@ def _build_mellum_prompt(user_content: str) -> str:
155
  add_generation_prompt=True,
156
  )
157
 
158
-
159
- def _generate_batch(prompts: list[str]) -> list[str]:
160
- """
161
- Single batched model.generate() call for all prompts.
162
- Left-padding aligns sequences for parallel decode.
163
- max_new_tokens is kept low (256) because SUMMARY_SYSTEM_PROMPT
164
- instructs the model to stay under 120 words.
165
- """
166
- log.info("Batch inference: %d prompts", len(prompts))
167
- _tokenizer.padding_side = "left"
168
- enc = _tokenizer(
169
- prompts,
170
- return_tensors="pt",
171
- padding=True,
172
- truncation=True,
173
- max_length=3072, # cap input so batch fits in VRAM
174
- ).to("cuda")
175
-
176
- log.info("Input shape: %s", enc.input_ids.shape)
177
- with torch.no_grad():
178
- out = _model.generate(
179
- **enc,
180
- max_new_tokens=4096, # ≈ 200 words — enough for our tight prompt
181
- use_cache=True,
182
- do_sample=False,
183
- pad_token_id=_tokenizer.pad_token_id,
184
- )
185
-
186
- results = []
187
- for seq in out:
188
- new_tok = seq[enc.input_ids.shape[1]:]
189
- text = _tokenizer.decode(new_tok, skip_special_tokens=True)
190
- results.append(_strip_thinking(text))
191
- return results
192
-
193
-
194
  def _generate_sequential(prompts: list[str]) -> list[str]:
195
  """Fallback single-prompt inference when batch would OOM."""
196
  log.info("Sequential inference: %d prompts", len(prompts))
@@ -202,7 +166,7 @@ def _generate_sequential(prompts: list[str]) -> list[str]:
202
  with torch.no_grad():
203
  out = _model.generate(
204
  **enc,
205
- max_new_tokens=1024,
206
  use_cache=True,
207
  do_sample=True,
208
  temperature=0.4,
@@ -213,27 +177,6 @@ def _generate_sequential(prompts: list[str]) -> list[str]:
213
  results.append(_strip_thinking(text))
214
  return results
215
 
216
-
217
- def _smart_generate(prompts: list[str]) -> list[str]:
218
- """
219
- Route to batch or sequential based on estimated token count.
220
- Catches OOM and retries sequentially.
221
- """
222
- estimated_tokens = sum(len(p) for p in prompts) // 4
223
- use_sequential = (len(prompts) == 1) or (estimated_tokens > BATCH_TOKEN_BUDGET)
224
-
225
- if use_sequential:
226
- log.info("Routing to sequential (est. %d tokens)", estimated_tokens)
227
- return _generate_sequential(prompts)
228
-
229
- try:
230
- return _generate_batch(prompts)
231
- except torch.cuda.OutOfMemoryError:
232
- log.warning("Batch OOM — retrying sequentially")
233
- torch.cuda.empty_cache()
234
- return _generate_sequential(prompts)
235
-
236
-
237
  # ---------------------------------------------------------------------------
238
  # Groq final report (pure API call — no GPU needed)
239
  # ---------------------------------------------------------------------------
 
155
  add_generation_prompt=True,
156
  )
157
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  def _generate_sequential(prompts: list[str]) -> list[str]:
159
  """Fallback single-prompt inference when batch would OOM."""
160
  log.info("Sequential inference: %d prompts", len(prompts))
 
166
  with torch.no_grad():
167
  out = _model.generate(
168
  **enc,
169
+ max_new_tokens=256,
170
  use_cache=True,
171
  do_sample=True,
172
  temperature=0.4,
 
177
  results.append(_strip_thinking(text))
178
  return results
179
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
180
  # ---------------------------------------------------------------------------
181
  # Groq final report (pure API call — no GPU needed)
182
  # ---------------------------------------------------------------------------
index.html CHANGED
@@ -1,6 +1,7 @@
1
  <!DOCTYPE html>
2
  <html lang="en">
3
  <head>
 
4
  <meta charset="UTF-8"/>
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
6
  <title>CommitLens — AI Code Review</title>
@@ -106,6 +107,64 @@ canvas{position:fixed;inset:0;width:100%;height:100%;pointer-events:none;z-index
106
  .ov-close{background:none;border:0.5px solid #1a1a2a;border-radius:6px;color:#666;font-size:11px;font-family:'Space Mono',monospace;padding:6px 14px;cursor:pointer;letter-spacing:.1em}
107
  .ov-close:hover{color:#e6edf3;border-color:#3a3a5a}
108
  .ov-body{font-size:12px;color:#8a9ab0;line-height:1.9;white-space:pre-wrap;word-break:break-word;max-width:760px}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  </style>
110
  </head>
111
  <body>
@@ -376,9 +435,75 @@ function renderFiles(files) {
376
  `).join('');
377
  }
378
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
379
  function renderReport(md) {
 
 
380
  const pane = document.getElementById('pane-r');
381
- pane.innerHTML = `<pre class="rp">${escHtml(md)}</pre>`;
 
 
 
 
 
 
 
 
 
 
 
382
  }
383
 
384
  function escHtml(s) {
 
1
  <!DOCTYPE html>
2
  <html lang="en">
3
  <head>
4
+ <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
5
  <meta charset="UTF-8"/>
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
7
  <title>CommitLens — AI Code Review</title>
 
107
  .ov-close{background:none;border:0.5px solid #1a1a2a;border-radius:6px;color:#666;font-size:11px;font-family:'Space Mono',monospace;padding:6px 14px;cursor:pointer;letter-spacing:.1em}
108
  .ov-close:hover{color:#e6edf3;border-color:#3a3a5a}
109
  .ov-body{font-size:12px;color:#8a9ab0;line-height:1.9;white-space:pre-wrap;word-break:break-word;max-width:760px}
110
+
111
+ .report-actions{
112
+ display:flex;
113
+ justify-content:flex-end;
114
+ margin-bottom:12px;
115
+ }
116
+
117
+ .report-actions button{
118
+ background:#238636;
119
+ border:none;
120
+ color:white;
121
+ padding:8px 14px;
122
+ border-radius:6px;
123
+ cursor:pointer;
124
+ font-family:'Space Mono',monospace;
125
+ font-size:10px;
126
+ letter-spacing:.08em;
127
+ }
128
+
129
+ .report-actions button:hover{
130
+ background:#2ea043;
131
+ }
132
+
133
+ .markdown-body{
134
+ color:#d6dee8;
135
+ line-height:1.8;
136
+ font-size:13px;
137
+ }
138
+
139
+ .markdown-body h2{
140
+ color:#58a6ff;
141
+ margin:20px 0 10px;
142
+ font-size:18px;
143
+ }
144
+
145
+ .markdown-body h3{
146
+ color:#3fb950;
147
+ margin:16px 0 8px;
148
+ font-size:15px;
149
+ }
150
+
151
+ .markdown-body ul{
152
+ padding-left:20px;
153
+ }
154
+
155
+ .markdown-body li{
156
+ margin:6px 0;
157
+ }
158
+
159
+ .markdown-body p{
160
+ margin:10px 0;
161
+ }
162
+
163
+ .markdown-body code{
164
+ background:#0d1117;
165
+ padding:2px 6px;
166
+ border-radius:4px;
167
+ }
168
  </style>
169
  </head>
170
  <body>
 
435
  `).join('');
436
  }
437
 
438
+ window._currentReport = "";
439
+
440
+ function downloadReport() {
441
+ const html = `
442
+ <!DOCTYPE html>
443
+ <html>
444
+ <head>
445
+ <meta charset="utf-8">
446
+ <title>CommitLens Report</title>
447
+
448
+ <style>
449
+ body{
450
+ max-width:900px;
451
+ margin:40px auto;
452
+ padding:20px;
453
+ font-family:system-ui,sans-serif;
454
+ line-height:1.7;
455
+ }
456
+ h2{
457
+ color:#2563eb;
458
+ }
459
+ h3{
460
+ color:#16a34a;
461
+ }
462
+ code{
463
+ background:#f3f4f6;
464
+ padding:2px 6px;
465
+ border-radius:4px;
466
+ }
467
+ </style>
468
+
469
+ </head>
470
+ <body>
471
+ ${marked.parse(window._currentReport)}
472
+ </body>
473
+ </html>
474
+ `;
475
+
476
+ const blob = new Blob(
477
+ [html],
478
+ { type: "text/html" }
479
+ );
480
+
481
+ const url = URL.createObjectURL(blob);
482
+
483
+ const a = document.createElement("a");
484
+ a.href = url;
485
+ a.download = "commitlens-report.html";
486
+ a.click();
487
+
488
+ URL.revokeObjectURL(url);
489
+ }
490
+
491
  function renderReport(md) {
492
+ window._currentReport = md || "";
493
+
494
  const pane = document.getElementById('pane-r');
495
+
496
+ pane.innerHTML = `
497
+ <div class="report-actions">
498
+ <button onclick="downloadReport()">
499
+ ⬇ DOWNLOAD REPORT
500
+ </button>
501
+ </div>
502
+
503
+ <div class="rp markdown-body">
504
+ ${marked.parse(md || "")}
505
+ </div>
506
+ `;
507
  }
508
 
509
  function escHtml(s) {