Feat: Ajustes y Preparación Docker

This commit is contained in:
2025-11-20 12:39:23 -03:00
parent c94936d56e
commit 1e85b2ed86
11 changed files with 317 additions and 56 deletions

View File

@@ -48,7 +48,7 @@ namespace ChatbotApi.Controllers
var baseUrl = configuration["Gemini:GeminiApiUrl"];
_apiUrl = $"{baseUrl}{apiKey}";
}
private async Task<IntentType> GetIntentAsync(string userMessage, string? activeArticleContent)
{
var promptBuilder = new StringBuilder();
@@ -92,12 +92,12 @@ namespace ChatbotApi.Controllers
return IntentType.Homepage;
}
}
[HttpPost("stream-message")]
[EnableRateLimiting("fixed")]
public async IAsyncEnumerable<string> StreamMessage(
[FromBody] ChatRequest request,
[EnumeratorCancellation] CancellationToken cancellationToken)
[FromBody] ChatRequest request,
[EnumeratorCancellation] CancellationToken cancellationToken)
{
if (string.IsNullOrWhiteSpace(request?.Message))
{
@@ -111,6 +111,9 @@ namespace ChatbotApi.Controllers
string? articleContext = null;
string? errorMessage = null;
// --- CORRECCIÓN: Declarar e inicializar 'intent' aquí ---
IntentType intent = IntentType.Homepage; // Default fallback
try
{
if (!string.IsNullOrEmpty(request.ContextUrl))
@@ -118,7 +121,8 @@ namespace ChatbotApi.Controllers
articleContext = await GetArticleContentAsync(request.ContextUrl);
}
IntentType intent = await GetIntentAsync(userMessage, articleContext);
// Ya no se declara con "IntentType intent", solo se le asigna el valor.
intent = await GetIntentAsync(userMessage, articleContext);
switch (intent)
{
@@ -138,7 +142,7 @@ namespace ChatbotApi.Controllers
case IntentType.Homepage:
default:
_logger.LogInformation("Ejecutando intención: Noticias de Portada.");
context = await GetWebsiteNewsAsync(_siteUrl, 15);
context = await GetWebsiteNewsAsync(_siteUrl, 25);
promptInstructions = "Tu tarea es responder la 'PREGUNTA DEL USUARIO' basándote ESTRICTA Y ÚNICAMENTE en el 'CONTEXTO' que contiene una lista de noticias de portada. Si encuentras una noticia relevante, proporciona su enlace en formato Markdown: '[título](URL)'.";
break;
}
@@ -151,6 +155,9 @@ namespace ChatbotApi.Controllers
promptInstructions = string.Empty;
}
// Ahora 'intent' es accesible aquí.
yield return $"INTENT::{intent}";
if (!string.IsNullOrEmpty(errorMessage))
{
yield return errorMessage;
@@ -267,7 +274,7 @@ namespace ChatbotApi.Controllers
_logger.LogError(logEx, "Error al guardar el log de la conversación después del streaming.");
}
}
private async Task<string?> FindBestDbItemAsync(string userMessage, Dictionary<string, string> knowledgeBase)
{
if (knowledgeBase == null || !knowledgeBase.Any()) return null;