diff --git a/TOOLS/scripts/05_generate_docs_llm.py b/TOOLS/scripts/05_generate_docs_llm.py index a4523c1..39721f3 100644 --- a/TOOLS/scripts/05_generate_docs_llm.py +++ b/TOOLS/scripts/05_generate_docs_llm.py @@ -7,7 +7,7 @@ LLM-улучшатель документации Nubes Terraform Provider. Использование: 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 urllib.request import Request, urlopen @@ -129,9 +129,10 @@ def call_llm(prompt: str) -> str: "Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json", }) - for attempt in range(3): + for attempt in range(2): try: - with urlopen(req, timeout=120) as resp: + socket.setdefaulttimeout(90) + with urlopen(req, timeout=90) as resp: result = json.loads(resp.read()) content = result["choices"][0]["message"]["content"].strip() if content.startswith("```"): @@ -140,9 +141,9 @@ def call_llm(prompt: str) -> str: content = "\n".join(lines[1:-1]) return content except Exception as e: - print(f" retry {attempt+1}/3: {e}", file=sys.stderr) - time.sleep(5) - raise RuntimeError("LLM failed after 3 retries") + print(f" retry {attempt+1}/2: {e}", file=sys.stderr) + time.sleep(3) + raise RuntimeError("LLM failed after 2 retries") def extract_man(text: str) -> str: @@ -237,6 +238,13 @@ def main(): continue 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) content = f.read_text()