Files
hack/tools/scripts/llm-key-hunter/results/_cache/content/2004style_asistente-ai.json
T

1 line
6.5 KiB
JSON

{"repo": "2004style/asistente-ai", "files": {"llm/providers/deepseek.py": {"5515df8276d5a63dbfee280e3e4bab95cc2eb181": {"t": 1785745987.4113116, "n": 3013, "h": "94ea5c342f2060fb", "c": "\"\"\"\nImplementation of the DeepSeek LLM provider.\n\"\"\"\nimport json\nimport urllib.request\nimport urllib.error\nimport asyncio\nfrom typing import List, Dict, Any\nfrom llm.base import BaseLLMProvider\nfrom llm.message import Message\n\nclass DeepSeekProvider(BaseLLMProvider):\n def __init__(self, api_key: str = \"\", model: str = \"deepseek-chat\", temperature: float = 0.7):\n self.api_key = api_key\n self.model = model\n self.temperature = temperature\n\n def get_model_name(self) -> str:\n return self.model\n\n async def generate(self, messages: List[Message], **kwargs) -> Message:\n if not self.api_key:\n return Message(\n role=\"assistant\",\n content=f\"[MOCK RESPONSE - DeepSeek API Key not configured]\\nRespuesta simulada para DeepSeek '{self.model}':\\nÚltimo mensaje: '{messages[-1].content}'\"\n )\n\n payload = {\n \"model\": self.model,\n \"messages\": [\n {\n \"role\": msg.role,\n \"content\": msg.content,\n **({\"tool_calls\": msg.tool_calls} if msg.tool_calls else {}),\n **({\"name\": msg.name} if msg.name else {}),\n **({\"tool_call_id\": msg.tool_call_id} if msg.tool_call_id else {})\n } for msg in messages\n ],\n \"temperature\": kwargs.get(\"temperature\", self.temperature)\n }\n\n # Handle tools if passed\n if \"tools\" in kwargs:\n payload[\"tools\"] = kwargs[\"tools\"]\n if \"tool_choice\" in kwargs:\n payload[\"tool_choice\"] = kwargs[\"tool_choice\"]\n\n headers = {\n \"Content-Type\": \"application/json\",\n \"Authorization\": f\"Bearer {self.api_key}\"\n }\n\n def _send_request():\n req = urllib.request.Request(\n \"https://api.deepseek.com/chat/completions\",\n data=json.dumps(payload).encode(\"utf-8\"),\n headers=headers,\n method=\"POST\"\n )\n try:\n with urllib.request.urlopen(req, timeout=30) as response:\n return json.loads(response.read().decode(\"utf-8\"))\n except urllib.error.HTTPError as e:\n error_body = e.read().decode(\"utf-8\")\n raise Exception(f\"DeepSeek API error ({e.code}): {error_body}\")\n except Exception as e:\n raise Exception(f\"Failed to communicate with DeepSeek: {str(e)}\")\n\n try:\n res_data = await asyncio.to_thread(_send_request)\n choice = res_data[\"choices\"][0][\"message\"]\n tool_calls = choice.get(\"tool_calls\")\n return Message(\n role=\"assistant\",\n content=choice.get(\"content\") or \"\",\n tool_calls=tool_calls\n )\n except Exception as e:\n return Message(\n role=\"assistant\",\n content=f\"Error calling DeepSeek API: {str(e)}\"\n )\n"}, "7894bf29067e898c09539c265032e488b5fd3c24": {"t": 1785758554.3736715, "n": 3013, "h": "94ea5c342f2060fb", "c": "\"\"\"\nImplementation of the DeepSeek LLM provider.\n\"\"\"\nimport json\nimport urllib.request\nimport urllib.error\nimport asyncio\nfrom typing import List, Dict, Any\nfrom llm.base import BaseLLMProvider\nfrom llm.message import Message\n\nclass DeepSeekProvider(BaseLLMProvider):\n def __init__(self, api_key: str = \"\", model: str = \"deepseek-chat\", temperature: float = 0.7):\n self.api_key = api_key\n self.model = model\n self.temperature = temperature\n\n def get_model_name(self) -> str:\n return self.model\n\n async def generate(self, messages: List[Message], **kwargs) -> Message:\n if not self.api_key:\n return Message(\n role=\"assistant\",\n content=f\"[MOCK RESPONSE - DeepSeek API Key not configured]\\nRespuesta simulada para DeepSeek '{self.model}':\\nÚltimo mensaje: '{messages[-1].content}'\"\n )\n\n payload = {\n \"model\": self.model,\n \"messages\": [\n {\n \"role\": msg.role,\n \"content\": msg.content,\n **({\"tool_calls\": msg.tool_calls} if msg.tool_calls else {}),\n **({\"name\": msg.name} if msg.name else {}),\n **({\"tool_call_id\": msg.tool_call_id} if msg.tool_call_id else {})\n } for msg in messages\n ],\n \"temperature\": kwargs.get(\"temperature\", self.temperature)\n }\n\n # Handle tools if passed\n if \"tools\" in kwargs:\n payload[\"tools\"] = kwargs[\"tools\"]\n if \"tool_choice\" in kwargs:\n payload[\"tool_choice\"] = kwargs[\"tool_choice\"]\n\n headers = {\n \"Content-Type\": \"application/json\",\n \"Authorization\": f\"Bearer {self.api_key}\"\n }\n\n def _send_request():\n req = urllib.request.Request(\n \"https://api.deepseek.com/chat/completions\",\n data=json.dumps(payload).encode(\"utf-8\"),\n headers=headers,\n method=\"POST\"\n )\n try:\n with urllib.request.urlopen(req, timeout=30) as response:\n return json.loads(response.read().decode(\"utf-8\"))\n except urllib.error.HTTPError as e:\n error_body = e.read().decode(\"utf-8\")\n raise Exception(f\"DeepSeek API error ({e.code}): {error_body}\")\n except Exception as e:\n raise Exception(f\"Failed to communicate with DeepSeek: {str(e)}\")\n\n try:\n res_data = await asyncio.to_thread(_send_request)\n choice = res_data[\"choices\"][0][\"message\"]\n tool_calls = choice.get(\"tool_calls\")\n return Message(\n role=\"assistant\",\n content=choice.get(\"content\") or \"\",\n tool_calls=tool_calls\n )\n except Exception as e:\n return Message(\n role=\"assistant\",\n content=f\"Error calling DeepSeek API: {str(e)}\"\n )\n"}}}}