Files
hack/tools/scripts/llm-key-hunter/results/_cache/content/cabezno_soda.json
T

1 line
11 KiB
JSON

{"repo": "cabezno/soda", "files": {"kernel/drivers/deepseek_driver.py": {"cac963f5db2efffebd3a03bb409074aaa0929e06": {"t": 1785746505.5872097, "n": 3692, "h": "3bbc2d49d1e8f576", "c": "import os\nimport asyncio\nimport httpx\nfrom time import perf_counter\nfrom dotenv import load_dotenv\nfrom kernel.drivers.base import BaseDriver, DriverResponse\n\nclass DeepSeekDriver(BaseDriver):\n \"\"\"\n Driver para DeepSeek API. \n Especializado en Deep Thinking (R1) y Auditoría (V3).\n \"\"\"\n provider = \"deepseek\"\n\n def __init__(self, model_name: str = \"deepseek-reasoner\"):\n super().__init__(model_name)\n load_dotenv()\n self.api_key = os.getenv(\"DEEPSEEK_API_KEY\")\n self.base_url = \"https://api.deepseek.com\"\n self._http = None\n\n def _get_client(self) -> httpx.AsyncClient:\n if self._http is None or self._http.is_closed:\n self._http = httpx.AsyncClient(timeout=httpx.Timeout(300.0, connect=15.0))\n return self._http\n\n async def call(\n self,\n system_prompt: str,\n user_message: str,\n max_tokens: int = 4096,\n temperature: float = 0.7,\n model: str = \"deepseek-reasoner\", # R1 por defecto para razonamiento superior\n **kwargs\n ) -> DriverResponse:\n t0 = perf_counter()\n client = self._get_client()\n \n # DeepSeek usa formato OpenAI\n messages = []\n if system_prompt:\n messages.append({\"role\": \"system\", \"content\": system_prompt})\n messages.append({\"role\": \"user\", \"content\": user_message})\n\n payload = {\n \"model\": model,\n \"messages\": messages,\n \"max_tokens\": max_tokens,\n \"temperature\": temperature,\n }\n\n try:\n print(f\" [DeepSeek] Llamando a {model}...\")\n response = await client.post(\n f\"{self.base_url}/chat/completions\",\n headers={\n \"Authorization\": f\"Bearer {self.api_key}\",\n \"Content-Type\": \"application/json\"\n },\n json=payload\n )\n\n if response.status_code == 200:\n res_json = response.json()\n content = res_json[\"choices\"][0][\"message\"][\"content\"]\n usage = res_json.get(\"usage\", {})\n \n t1 = perf_counter()\n latency_ms = int((t1 - t0) * 1000)\n \n # Costos aproximados V3/R1\n cost = (usage.get(\"prompt_tokens\", 0) * 0.00000014) + \\\n (usage.get(\"completion_tokens\", 0) * 0.00000028)\n\n return DriverResponse(\n content=content,\n tokens_input=usage.get(\"prompt_tokens\", 0),\n tokens_output=usage.get(\"completion_tokens\", 0),\n latency_ms=latency_ms,\n model_used=model,\n cost_usd=cost\n )\n else:\n print(f\" [DeepSeek] ERROR {response.status_code}: {response.text[:200]}\")\n return self._build_response(\n content=f\"ERROR:DEEPSEEK:{response.status_code}\",\n system_prompt=system_prompt,\n user_message=user_message,\n latency_start=t0,\n model_used=model\n )\n\n except Exception as e:\n print(f\" [DeepSeek] Excepción: {e}\")\n return self._build_response(\n content=f\"ERROR:EXCEPTION:{str(e)}\",\n system_prompt=system_prompt,\n user_message=user_message,\n latency_start=t0,\n model_used=model\n )\n\n async def prompt(self, system: str, user: str, **kwargs) -> str:\n resp = await self.call(system, user, **kwargs)\n return resp.content\n"}, "29419c2fc342ae439b36ddadad4eb679cabf550d": {"t": 1785765066.9427626, "n": 3692, "h": "3bbc2d49d1e8f576", "c": "import os\nimport asyncio\nimport httpx\nfrom time import perf_counter\nfrom dotenv import load_dotenv\nfrom kernel.drivers.base import BaseDriver, DriverResponse\n\nclass DeepSeekDriver(BaseDriver):\n \"\"\"\n Driver para DeepSeek API. \n Especializado en Deep Thinking (R1) y Auditoría (V3).\n \"\"\"\n provider = \"deepseek\"\n\n def __init__(self, model_name: str = \"deepseek-reasoner\"):\n super().__init__(model_name)\n load_dotenv()\n self.api_key = os.getenv(\"DEEPSEEK_API_KEY\")\n self.base_url = \"https://api.deepseek.com\"\n self._http = None\n\n def _get_client(self) -> httpx.AsyncClient:\n if self._http is None or self._http.is_closed:\n self._http = httpx.AsyncClient(timeout=httpx.Timeout(300.0, connect=15.0))\n return self._http\n\n async def call(\n self,\n system_prompt: str,\n user_message: str,\n max_tokens: int = 4096,\n temperature: float = 0.7,\n model: str = \"deepseek-reasoner\", # R1 por defecto para razonamiento superior\n **kwargs\n ) -> DriverResponse:\n t0 = perf_counter()\n client = self._get_client()\n \n # DeepSeek usa formato OpenAI\n messages = []\n if system_prompt:\n messages.append({\"role\": \"system\", \"content\": system_prompt})\n messages.append({\"role\": \"user\", \"content\": user_message})\n\n payload = {\n \"model\": model,\n \"messages\": messages,\n \"max_tokens\": max_tokens,\n \"temperature\": temperature,\n }\n\n try:\n print(f\" [DeepSeek] Llamando a {model}...\")\n response = await client.post(\n f\"{self.base_url}/chat/completions\",\n headers={\n \"Authorization\": f\"Bearer {self.api_key}\",\n \"Content-Type\": \"application/json\"\n },\n json=payload\n )\n\n if response.status_code == 200:\n res_json = response.json()\n content = res_json[\"choices\"][0][\"message\"][\"content\"]\n usage = res_json.get(\"usage\", {})\n \n t1 = perf_counter()\n latency_ms = int((t1 - t0) * 1000)\n \n # Costos aproximados V3/R1\n cost = (usage.get(\"prompt_tokens\", 0) * 0.00000014) + \\\n (usage.get(\"completion_tokens\", 0) * 0.00000028)\n\n return DriverResponse(\n content=content,\n tokens_input=usage.get(\"prompt_tokens\", 0),\n tokens_output=usage.get(\"completion_tokens\", 0),\n latency_ms=latency_ms,\n model_used=model,\n cost_usd=cost\n )\n else:\n print(f\" [DeepSeek] ERROR {response.status_code}: {response.text[:200]}\")\n return self._build_response(\n content=f\"ERROR:DEEPSEEK:{response.status_code}\",\n system_prompt=system_prompt,\n user_message=user_message,\n latency_start=t0,\n model_used=model\n )\n\n except Exception as e:\n print(f\" [DeepSeek] Excepción: {e}\")\n return self._build_response(\n content=f\"ERROR:EXCEPTION:{str(e)}\",\n system_prompt=system_prompt,\n user_message=user_message,\n latency_start=t0,\n model_used=model\n )\n\n async def prompt(self, system: str, user: str, **kwargs) -> str:\n resp = await self.call(system, user, **kwargs)\n return resp.content\n"}, "c66da31ab083c6b25cbea89cd542dde5b708da4d": {"t": 1785765068.3411422, "n": 3244, "h": "05b47c18b3211be4", "c": "import os\nimport asyncio\nimport httpx\nfrom time import perf_counter\nfrom dotenv import load_dotenv\nfrom kernel.drivers.base import BaseDriver, DriverResponse\n\nclass DeepSeekDriver(BaseDriver):\n \"\"\"\n Driver para DeepSeek API. \n Especializado en Deep Thinking (R1) y Auditoría (V3).\n \"\"\"\n provider = \"deepseek\"\n\n def __init__(self):\n load_dotenv()\n self.api_key = os.getenv(\"DEEPSEEK_API_KEY\")\n self.base_url = \"https://api.deepseek.com\"\n self._http = None\n\n def _get_client(self) -> httpx.AsyncClient:\n if self._http is None or self._http.is_closed:\n self._http = httpx.AsyncClient(timeout=httpx.Timeout(300.0, connect=15.0))\n return self._http\n\n async def call(\n self,\n system_prompt: str,\n user_message: str,\n max_tokens: int = 4096,\n temperature: float = 0.7,\n model: str = \"deepseek-reasoner\", # R1 por defecto para razonamiento superior\n **kwargs\n ) -> DriverResponse:\n t0 = perf_counter()\n client = self._get_client()\n \n # DeepSeek usa formato OpenAI\n messages = []\n if system_prompt:\n messages.append({\"role\": \"system\", \"content\": system_prompt})\n messages.append({\"role\": \"user\", \"content\": user_message})\n\n payload = {\n \"model\": model,\n \"messages\": messages,\n \"max_tokens\": max_tokens,\n \"temperature\": temperature,\n }\n\n try:\n print(f\" [DeepSeek] Llamando a {model}...\")\n response = await client.post(\n f\"{self.base_url}/chat/completions\",\n headers={\n \"Authorization\": f\"Bearer {self.api_key}\",\n \"Content-Type\": \"application/json\"\n },\n json=payload\n )\n\n if response.status_code == 200:\n res_json = response.json()\n content = res_json[\"choices\"][0][\"message\"][\"content\"]\n usage = res_json.get(\"usage\", {})\n \n t1 = perf_counter()\n latency_ms = int((t1 - t0) * 1000)\n \n # Costos aproximados V3/R1\n cost = (usage.get(\"prompt_tokens\", 0) * 0.00000014) + \\\n (usage.get(\"completion_tokens\", 0) * 0.00000028)\n\n return DriverResponse(\n content=content,\n tokens_input=usage.get(\"prompt_tokens\", 0),\n tokens_output=usage.get(\"completion_tokens\", 0),\n latency_ms=latency_ms,\n model_used=model,\n cost_usd=cost\n )\n else:\n print(f\" [DeepSeek] ERROR {response.status_code}: {response.text[:200]}\")\n return DriverResponse(content=f\"ERROR:DEEPSEEK:{response.status_code}\", model_used=model)\n\n except Exception as e:\n print(f\" [DeepSeek] Excepción: {e}\")\n return DriverResponse(content=f\"ERROR:EXCEPTION:{str(e)}\", model_used=model)\n\n async def prompt(self, system: str, user: str, **kwargs) -> str:\n resp = await self.call(system, user, **kwargs)\n return resp.content\n"}}}}