Files
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
5.0 KiB
JSON

{"repo": "caligian/deepseek-cli", "files": {"src/deepseek_cli/client.py": {"60710bc0a343092e3da4ba2e4c043f47c13db954": {"t": 1786068357.6112404, "n": 4672, "h": "4407bed15930056b", "c": "from __future__ import annotations\n\nfrom openai import OpenAI\nfrom termcolor import cprint\n\nimport os\n\n\nclass UserClient:\n def __init__(\n self,\n api_key_file: str | None = None,\n api_key: str | None = None,\n system_prompt: str = \"\",\n ) -> None:\n if not api_key_file and not api_key:\n api_key = os.getenv(\"DEEPSEEK_API_KEY\")\n\n self.api_key_file: str | None = api_key_file\n self.api_key: str | None = api_key\n self.default_system_prompt: str = f\"\"\"\n You are a helpful assistant who is clinical with their reasoning.\n You shall always output in English or translate your output in english.\n You will output all tables in CSV format \n You will structure your output in Markdown format.\n You will directly output in markdown format without any extra tokens\n You will only use ASCII characters\n {system_prompt}\n \"\"\"\n\n if not self.api_key and self.api_key_file:\n with open(self.api_key_file) as fh:\n self.api_key = fh.read()\n self.api_key = self.api_key.strip()\n\n if not self.api_key:\n raise ValueError(\n \"No Deepseek API key provided by either DEEPSEEK_API_KEY environment variable or UserClient(...)\"\n )\n\n self.base_url: str = \"https://api.deepseek.com\"\n self.client: OpenAI | None = None\n self.temperature: float = 0.4\n self.top_p: float = 0.9\n self.max_tokens: int = 4096\n self.reasoning_effort: str = \"high\"\n self.extra_body: dict[str, str | dict[str, str]] = dict(\n thinking=dict(type=\"disabled\")\n )\n self.thinking_enabled: bool = False\n self.models = [\"deepseek-v4-pro\", \"deepseek-v4-flash\"]\n self.model = \"deepseek-v4-flash\"\n self.thinking: bool = False\n\n def enable_pro(self) -> None:\n self.model = self.models[0]\n\n def enable_flash(self) -> None:\n self.model = self.models[1]\n\n def enable_thinking(self) -> None:\n self.extra_body[\"thinking\"][\"type\"] = \"enabled\"\n self.thinking_enabled = True\n\n def disable_thinking(self) -> None:\n self.extra_body[\"thinking\"][\"type\"] = \"disabled\"\n self.thinking_enabled = False\n\n def toggle_thinking(self) -> None:\n if self.thinking_enabled:\n self.disable_thinking()\n else:\n self.enable_thinking()\n\n def open(self) -> None:\n self.client = OpenAI(api_key=self.api_key, base_url=self.base_url)\n\n def has_reasoning(self, delta) -> bool:\n return (\n hasattr(delta, \"reasoning_content\")\n and delta.reasoning_content is not None\n )\n\n def has_content(self, delta) -> bool:\n return (\n hasattr(delta, \"content\")\n and delta.content is not None\n and delta.content != \"\"\n )\n\n def has_finished(self, chunk) -> bool:\n chunk = chunk.choices[0]\n return hasattr(chunk, \"finish_reason\") and chunk.finish_reason\n\n def stream(self, delta) -> None:\n if self.has_reasoning(delta):\n text = delta.reasoning_content\n if text != \"\":\n cprint(text, color=\"blue\", end=\"\", flush=True)\n self.thinking = True\n elif self.has_content(delta):\n if self.thinking:\n print(\"\\n\", flush=True)\n self.thinking = False\n print(delta.content, end=\"\", flush=True)\n\n def ask(\n self,\n question: str,\n system_prompt: str = \"\",\n ) -> bool:\n system_prompt = f\"{self.default_system_prompt}\\n{system_prompt}\"\n system_prompt = system_prompt.strip()\n\n resp = self.client.chat.completions.create(\n model=self.model,\n messages=[\n dict(role=\"system\", content=system_prompt),\n dict(role=\"user\", content=question),\n ],\n stream=True,\n temperature=self.temperature,\n top_p=self.top_p,\n max_tokens=self.max_tokens,\n reasoning_effort=self.reasoning_effort,\n extra_body=self.extra_body,\n )\n\n for chunk in resp:\n delta = chunk.choices[0].delta\n if self.has_finished(chunk):\n print(\"\\n\")\n else:\n self.stream(delta)\n\n return True\n\n\n# client = UserClient(\"/home/Kerambit/deepseek-api-key.txt\")\n# client.open()\n# client.ask(\"I am using an API. just pinging you\")\n# client.enable_thinking()\n# client.ask(\n# \"Are you in deepthink mode now? I have enabled it. I have passed the extra-body parameter\"\n# )\n"}}}}