Files
hack/tools/scripts/llm-key-hunter/results/_cache/content/abdulhadihub_csmv-project-natural-language-to-policy.json
OpenCode 68a9071cf1 feat: reconcile local master with origin (exa/hot-platform hunters, leaks ledger, latest results)
Local branch had diverged from origin/master (sibling commits on the same base). Rewrote local history linearly on top of origin/master, folding in all local content: exa/hot-platform discovery hunters, leaks ledger, nightly sweep orchestrator, updated .gitignore and skill docs, plus the latest hunt output and vault state. Remote-only files (vault keys, channel scripts) were restored rather than dropped, so the resulting tree is a full union of both sides.
2026-08-07 12:53:47 +08:00

1 line
4.0 KiB
JSON

{"repo": "abdulhadihub/csmv-project-natural-language-to-policy", "files": {"custom_harness/llm/client.py": {"329799e3addeb2fbb89fb7139898eb150fbbf494": {"t": 1786067732.3882256, "n": 3612, "h": "7df8b11d7bf7bdae", "c": "import os\nimport re\nimport time\nimport json\nimport urllib.request\nimport urllib.error\n\nfrom dotenv import load_dotenv\n\nload_dotenv()\n\nDEEPSEEK_API_URL = \"https://api.deepseek.com/v1/chat/completions\"\n\n\nclass LLMClient:\n \"\"\"Thin wrapper around the DeepSeek chat completion API with function calling.\"\"\"\n\n def __init__(self, api_key: str | None = None, model: str = \"deepseek-chat\"):\n self.api_key = api_key or os.environ.get(\"DEEPSEEK_API_KEY\", \"\")\n if not self.api_key:\n raise ValueError(\"DEEPSEEK_API_KEY is not set\")\n self.model = model\n\n def chat(\n self,\n messages: list[dict],\n tools: list[dict] | None = None,\n tool_choice: str = \"auto\",\n temperature: float = 0.2,\n ) -> dict:\n body = {\n \"model\": self.model,\n \"messages\": messages,\n \"temperature\": temperature,\n }\n if tools:\n body[\"tools\"] = tools\n body[\"tool_choice\"] = tool_choice\n\n payload = json.dumps(body).encode()\n\n request = urllib.request.Request(\n DEEPSEEK_API_URL,\n data=payload,\n headers={\n \"Authorization\": f\"Bearer {self.api_key}\",\n \"Content-Type\": \"application/json\",\n },\n method=\"POST\",\n )\n\n last_error = None\n for attempt in range(3):\n try:\n with urllib.request.urlopen(request, timeout=60) as resp:\n data = json.loads(resp.read().decode())\n except urllib.error.HTTPError as e:\n if e.code == 429:\n last_error = f\"Rate limited (attempt {attempt + 1}/3)\"\n time.sleep(5)\n continue\n if e.code == 401:\n raise PermissionError(\n \"Invalid API key — check DEEPSEEK_API_KEY\"\n ) from e\n last_error = f\"HTTP {e.code}: {e.read().decode()}\"\n time.sleep(2 ** attempt)\n continue\n except urllib.error.URLError as e:\n last_error = f\"Connection error: {e.reason}\"\n time.sleep(2 ** attempt)\n continue\n\n choice = data[\"choices\"][0]\n message = choice[\"message\"]\n usage = data.get(\"usage\", {})\n finish_reason = choice.get(\"finish_reason\", \"stop\")\n\n result = {\n \"content\": message.get(\"content\"),\n \"tool_calls\": message.get(\"tool_calls\"),\n \"usage\": {\n \"prompt_tokens\": usage.get(\"prompt_tokens\", 0),\n \"completion_tokens\": usage.get(\"completion_tokens\", 0),\n },\n \"finish_reason\": finish_reason,\n }\n return result\n\n raise RuntimeError(f\"LLM call failed after 3 retries: {last_error}\")\n\n\nYAML_FENCE_RE = re.compile(r\"```(?:yaml)?\\n(.*?)```\", re.DOTALL)\n\n\ndef extract_yaml(response: dict) -> str:\n \"\"\"Extract YAML from an LLM response.\n\n Handles two formats:\n 1. Raw YAML string in response[\"content\"]\n 2. YAML inside ```yaml ... ``` markdown fences\n\n Returns the YAML string. Raises ValueError if no YAML content is found.\n \"\"\"\n content = response.get(\"content\")\n if not content:\n raise ValueError(\"No content in LLM response\")\n\n match = YAML_FENCE_RE.search(content)\n if match:\n return match.group(1).strip()\n\n stripped = content.strip()\n if stripped:\n return stripped\n\n raise ValueError(\"No YAML content found in LLM response\")\n"}}}}