feat: LLM enrichment (GPT-120) — 137 files, 1 failure (postgres_params_create timeout, copied original)
This commit is contained in:
@@ -7,7 +7,7 @@ LLM-улучшатель документации Nubes Terraform Provider.
|
|||||||
Использование:
|
Использование:
|
||||||
python3 05_generate_docs_llm.py generated/test/docs [--out generated/test/docs_llm]
|
python3 05_generate_docs_llm.py generated/test/docs [--out generated/test/docs_llm]
|
||||||
"""
|
"""
|
||||||
import json, os, re, shutil, sys, time
|
import json, os, re, shutil, sys, time, socket
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from urllib.request import Request, urlopen
|
from urllib.request import Request, urlopen
|
||||||
|
|
||||||
@@ -129,9 +129,10 @@ def call_llm(prompt: str) -> str:
|
|||||||
"Authorization": f"Bearer {API_KEY}",
|
"Authorization": f"Bearer {API_KEY}",
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
})
|
})
|
||||||
for attempt in range(3):
|
for attempt in range(2):
|
||||||
try:
|
try:
|
||||||
with urlopen(req, timeout=120) as resp:
|
socket.setdefaulttimeout(90)
|
||||||
|
with urlopen(req, timeout=90) as resp:
|
||||||
result = json.loads(resp.read())
|
result = json.loads(resp.read())
|
||||||
content = result["choices"][0]["message"]["content"].strip()
|
content = result["choices"][0]["message"]["content"].strip()
|
||||||
if content.startswith("```"):
|
if content.startswith("```"):
|
||||||
@@ -140,9 +141,9 @@ def call_llm(prompt: str) -> str:
|
|||||||
content = "\n".join(lines[1:-1])
|
content = "\n".join(lines[1:-1])
|
||||||
return content
|
return content
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f" retry {attempt+1}/3: {e}", file=sys.stderr)
|
print(f" retry {attempt+1}/2: {e}", file=sys.stderr)
|
||||||
time.sleep(5)
|
time.sleep(3)
|
||||||
raise RuntimeError("LLM failed after 3 retries")
|
raise RuntimeError("LLM failed after 2 retries")
|
||||||
|
|
||||||
|
|
||||||
def extract_man(text: str) -> str:
|
def extract_man(text: str) -> str:
|
||||||
@@ -237,6 +238,13 @@ def main():
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
total += 1
|
total += 1
|
||||||
|
dest = out_dir / f.name
|
||||||
|
|
||||||
|
# Skip already processed files
|
||||||
|
if dest.exists() and dest.stat().st_size > 100:
|
||||||
|
print(f" {f.name}... SKIP (already done)", flush=True)
|
||||||
|
continue
|
||||||
|
|
||||||
print(f" {f.name}...", end=" ", flush=True)
|
print(f" {f.name}...", end=" ", flush=True)
|
||||||
|
|
||||||
content = f.read_text()
|
content = f.read_text()
|
||||||
|
|||||||
Reference in New Issue
Block a user