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

1 line
13 KiB
JSON

{"repo": "chester0802/epycusapp", "files": {"Servicios/Implementaciones/ProveedorDeepSeek.cs": {"089339409061266efa949aad3920cbcddbdc1919": {"t": 1785746210.6065147, "n": 6190, "h": "82008537c57384c4", "c": "using System.Net.Http.Json;\nusing System.Text.Json.Serialization;\nusing EpycusApp.Models.Entidades;\nusing EpycusApp.Servicios.Interfaces;\nusing Microsoft.Extensions.Logging;\n\nnamespace EpycusApp.Servicios.Implementaciones\n{\n public class ProveedorDeepSeek : IProveedorDeepSeek\n {\n private readonly HttpClient _httpClient;\n private readonly string _apiKey;\n private readonly string _modelo;\n private readonly ILogger<ProveedorDeepSeek> _logger;\n\n public ProveedorDeepSeek(IHttpClientFactory httpClientFactory, IConfiguration config, ILogger<ProveedorDeepSeek> logger)\n {\n _httpClient = httpClientFactory.CreateClient(\"DeepSeek\");\n _apiKey = config[\"DeepSeek:ApiKey\"] ?? \"\";\n _modelo = config[\"DeepSeek:Modelo\"] ?? \"deepseek-v4-flash\";\n _logger = logger;\n }\n\n public async Task<string> LlamarAsync(ContextoUsuarioIA ctx, List<MensajeIA> historial, string? resumen = null)\n {\n var systemPrompt = ConstructorContextoIA.ConstruirSystemPrompt(ctx);\n\n var messages = new List<DeepSeekMessage>\n {\n new() { Role = \"system\", Content = systemPrompt }\n };\n\n if (!string.IsNullOrEmpty(resumen))\n {\n messages.Add(new DeepSeekMessage\n {\n Role = \"user\",\n Content = \"[Contexto previo] \" + resumen\n });\n }\n\n foreach (var m in historial)\n {\n messages.Add(new DeepSeekMessage\n {\n Role = m.Rol == \"user\" ? \"user\" : \"assistant\",\n Content = m.Contenido\n });\n }\n\n var request = new DeepSeekRequest\n {\n Model = _modelo,\n Messages = messages,\n Temperature = 0.75,\n MaxTokens = 900,\n Stream = false\n };\n\n var url = \"https://api.deepseek.com/chat/completions\";\n\n var maxReintentos = 2;\n for (var intento = 0; intento <= maxReintentos; intento++)\n {\n try\n {\n using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30));\n var reqMsg = new HttpRequestMessage(HttpMethod.Post, url)\n {\n Content = JsonContent.Create(request)\n };\n reqMsg.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(\"Bearer\", _apiKey);\n\n var httpResp = await _httpClient.SendAsync(reqMsg, cts.Token);\n if (!httpResp.IsSuccessStatusCode)\n {\n var errorBody = await httpResp.Content.ReadAsStringAsync(cts.Token);\n _logger.LogWarning(\"DeepSeek respondio {StatusCode}: {Error}\", httpResp.StatusCode, errorBody);\n if (intento < maxReintentos && (int)httpResp.StatusCode >= 500)\n {\n await Task.Delay(TimeSpan.FromSeconds(1 << intento));\n continue;\n }\n if ((int)httpResp.StatusCode == 429)\n return \"La IA esta saturada en este momento. Espera un momento y vuelve a intentarlo.\";\n return \"Lo siento, no pude conectarme a la IA en este momento. Intentelo de nuevo mas tarde.\";\n }\n\n var deepSeekResp = await httpResp.Content.ReadFromJsonAsync<DeepSeekResponse>(cancellationToken: cts.Token);\n\n var choice = deepSeekResp?.Choices?.FirstOrDefault();\n if (choice?.FinishReason == \"length\")\n {\n _logger.LogWarning(\"DeepSeek respuesta truncada por longitud maxima\");\n }\n\n var texto = choice?.Message?.Content;\n\n return string.IsNullOrWhiteSpace(texto)\n ? \"No recibi respuesta de la IA. Intenta reformular tu pregunta.\"\n : texto;\n }\n catch (OperationCanceledException)\n {\n if (intento < maxReintentos) continue;\n return \"La conexion con EDY AI tardo demasiado. Intentelo de nuevo.\";\n }\n catch (HttpRequestException)\n {\n if (intento < maxReintentos)\n {\n await Task.Delay(TimeSpan.FromSeconds(1 << intento));\n continue;\n }\n return \"Hubo un error al comunicarme con EDY AI. Verifica tu conexion e intentelo de nuevo.\";\n }\n }\n\n return \"Hubo un error al comunicarme con EDY AI. Verifica tu conexion e intentelo de nuevo.\";\n }\n }\n\n internal sealed class DeepSeekRequest\n {\n [JsonPropertyName(\"model\")]\n public string Model { get; set; } = \"deepseek-v4-flash\";\n\n [JsonPropertyName(\"messages\")]\n public List<DeepSeekMessage> Messages { get; set; } = new();\n\n [JsonPropertyName(\"temperature\")]\n public double Temperature { get; set; } = 0.75;\n\n [JsonPropertyName(\"max_tokens\")]\n public int MaxTokens { get; set; } = 900;\n\n [JsonPropertyName(\"stream\")]\n public bool Stream { get; set; } = false;\n }\n\n internal sealed class DeepSeekMessage\n {\n [JsonPropertyName(\"role\")]\n public string Role { get; set; } = string.Empty;\n\n [JsonPropertyName(\"content\")]\n public string Content { get; set; } = string.Empty;\n }\n\n internal sealed class DeepSeekResponse\n {\n [JsonPropertyName(\"choices\")]\n public List<DeepSeekChoice>? Choices { get; set; }\n }\n\n internal sealed class DeepSeekChoice\n {\n [JsonPropertyName(\"message\")]\n public DeepSeekMessage? Message { get; set; }\n\n [JsonPropertyName(\"finish_reason\")]\n public string? FinishReason { get; set; }\n }\n}\n"}, "8dba046745e4f5a8eca4b471c40150922075068f": {"t": 1785760644.1111014, "n": 6190, "h": "82008537c57384c4", "c": "using System.Net.Http.Json;\nusing System.Text.Json.Serialization;\nusing EpycusApp.Models.Entidades;\nusing EpycusApp.Servicios.Interfaces;\nusing Microsoft.Extensions.Logging;\n\nnamespace EpycusApp.Servicios.Implementaciones\n{\n public class ProveedorDeepSeek : IProveedorDeepSeek\n {\n private readonly HttpClient _httpClient;\n private readonly string _apiKey;\n private readonly string _modelo;\n private readonly ILogger<ProveedorDeepSeek> _logger;\n\n public ProveedorDeepSeek(IHttpClientFactory httpClientFactory, IConfiguration config, ILogger<ProveedorDeepSeek> logger)\n {\n _httpClient = httpClientFactory.CreateClient(\"DeepSeek\");\n _apiKey = config[\"DeepSeek:ApiKey\"] ?? \"\";\n _modelo = config[\"DeepSeek:Modelo\"] ?? \"deepseek-v4-flash\";\n _logger = logger;\n }\n\n public async Task<string> LlamarAsync(ContextoUsuarioIA ctx, List<MensajeIA> historial, string? resumen = null)\n {\n var systemPrompt = ConstructorContextoIA.ConstruirSystemPrompt(ctx);\n\n var messages = new List<DeepSeekMessage>\n {\n new() { Role = \"system\", Content = systemPrompt }\n };\n\n if (!string.IsNullOrEmpty(resumen))\n {\n messages.Add(new DeepSeekMessage\n {\n Role = \"user\",\n Content = \"[Contexto previo] \" + resumen\n });\n }\n\n foreach (var m in historial)\n {\n messages.Add(new DeepSeekMessage\n {\n Role = m.Rol == \"user\" ? \"user\" : \"assistant\",\n Content = m.Contenido\n });\n }\n\n var request = new DeepSeekRequest\n {\n Model = _modelo,\n Messages = messages,\n Temperature = 0.75,\n MaxTokens = 900,\n Stream = false\n };\n\n var url = \"https://api.deepseek.com/chat/completions\";\n\n var maxReintentos = 2;\n for (var intento = 0; intento <= maxReintentos; intento++)\n {\n try\n {\n using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30));\n var reqMsg = new HttpRequestMessage(HttpMethod.Post, url)\n {\n Content = JsonContent.Create(request)\n };\n reqMsg.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(\"Bearer\", _apiKey);\n\n var httpResp = await _httpClient.SendAsync(reqMsg, cts.Token);\n if (!httpResp.IsSuccessStatusCode)\n {\n var errorBody = await httpResp.Content.ReadAsStringAsync(cts.Token);\n _logger.LogWarning(\"DeepSeek respondio {StatusCode}: {Error}\", httpResp.StatusCode, errorBody);\n if (intento < maxReintentos && (int)httpResp.StatusCode >= 500)\n {\n await Task.Delay(TimeSpan.FromSeconds(1 << intento));\n continue;\n }\n if ((int)httpResp.StatusCode == 429)\n return \"La IA esta saturada en este momento. Espera un momento y vuelve a intentarlo.\";\n return \"Lo siento, no pude conectarme a la IA en este momento. Intentelo de nuevo mas tarde.\";\n }\n\n var deepSeekResp = await httpResp.Content.ReadFromJsonAsync<DeepSeekResponse>(cancellationToken: cts.Token);\n\n var choice = deepSeekResp?.Choices?.FirstOrDefault();\n if (choice?.FinishReason == \"length\")\n {\n _logger.LogWarning(\"DeepSeek respuesta truncada por longitud maxima\");\n }\n\n var texto = choice?.Message?.Content;\n\n return string.IsNullOrWhiteSpace(texto)\n ? \"No recibi respuesta de la IA. Intenta reformular tu pregunta.\"\n : texto;\n }\n catch (OperationCanceledException)\n {\n if (intento < maxReintentos) continue;\n return \"La conexion con EDY AI tardo demasiado. Intentelo de nuevo.\";\n }\n catch (HttpRequestException)\n {\n if (intento < maxReintentos)\n {\n await Task.Delay(TimeSpan.FromSeconds(1 << intento));\n continue;\n }\n return \"Hubo un error al comunicarme con EDY AI. Verifica tu conexion e intentelo de nuevo.\";\n }\n }\n\n return \"Hubo un error al comunicarme con EDY AI. Verifica tu conexion e intentelo de nuevo.\";\n }\n }\n\n internal sealed class DeepSeekRequest\n {\n [JsonPropertyName(\"model\")]\n public string Model { get; set; } = \"deepseek-v4-flash\";\n\n [JsonPropertyName(\"messages\")]\n public List<DeepSeekMessage> Messages { get; set; } = new();\n\n [JsonPropertyName(\"temperature\")]\n public double Temperature { get; set; } = 0.75;\n\n [JsonPropertyName(\"max_tokens\")]\n public int MaxTokens { get; set; } = 900;\n\n [JsonPropertyName(\"stream\")]\n public bool Stream { get; set; } = false;\n }\n\n internal sealed class DeepSeekMessage\n {\n [JsonPropertyName(\"role\")]\n public string Role { get; set; } = string.Empty;\n\n [JsonPropertyName(\"content\")]\n public string Content { get; set; } = string.Empty;\n }\n\n internal sealed class DeepSeekResponse\n {\n [JsonPropertyName(\"choices\")]\n public List<DeepSeekChoice>? Choices { get; set; }\n }\n\n internal sealed class DeepSeekChoice\n {\n [JsonPropertyName(\"message\")]\n public DeepSeekMessage? Message { get; set; }\n\n [JsonPropertyName(\"finish_reason\")]\n public string? FinishReason { get; set; }\n }\n}\n"}}}}