-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsummary_rewrite_llm.py
More file actions
44 lines (34 loc) · 1.1 KB
/
Copy pathsummary_rewrite_llm.py
File metadata and controls
44 lines (34 loc) · 1.1 KB
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
# src/summary_rewrite_llm.py
import subprocess
from pathlib import Path
MODEL = Path("models/llm/model.gguf")
PROMPT = Path("data/output/summary.txt")
OUT = Path("data/output/summary_final.txt")
def main():
prompt = PROMPT.read_text().strip()
if not prompt:
raise RuntimeError("Summary input is empty")
print("▶ Running llama-cli (batch mode)...")
proc = subprocess.Popen(
["llama-cli", "-m", str(MODEL), "-n", "512", "--temp", "0.2"],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL,
text=True
)
stdout, _ = proc.communicate(prompt + "\n\n/exit\n", timeout=120)
# 🧠 Extract only model response
lines = []
record = False
for line in stdout.splitlines():
if line.strip().startswith("SUMMARY:"):
record = True
if record:
lines.append(line)
text = "\n".join(lines).strip()
if len(text) < 50:
raise RuntimeError("LLM produced empty output")
OUT.write_text(text)
print("✅ Final LLM summary saved")
if __name__ == "__main__":
main()