using Microsoft.SemanticKernel; using Microsoft.SemanticKernel.ChatCompletion; using System.Text.Json; namespace ChatApi { public class ChatHistoryService { private readonly Dictionary _keyValues = new Dictionary(); public ChatHistoryService() { } public ChatHistory Get(string sessionId) { if (_keyValues.ContainsKey(sessionId)) { var history = _keyValues[sessionId]; return history; } else { var msg = new List(); PromptLiliana(msg); string json = JsonSerializer.Serialize(msg); var history = new ChatHistory(JsonSerializer.Deserialize>(json)); _keyValues[sessionId] = history; return _keyValues[sessionId]; } } public ChatHistory GetSumarizer(string sessionId, string language = "en") { if (_keyValues.ContainsKey(sessionId)) { var history = _keyValues[sessionId]; return history; } else { var msg = new List(); if (language == "pt") PromptPt(msg); else PromptEn(msg); string json = JsonSerializer.Serialize(msg); var history = new ChatHistory(JsonSerializer.Deserialize>(json)); _keyValues[sessionId] = history; return _keyValues[sessionId]; } } public void UpdateHistory(string sessionId, ChatHistory history) { _keyValues[sessionId] = history; } public void PromptLiliana(List msg) { msg.Add(new ChatMessageContent(AuthorRole.System, "Seu nome é LiliAna, uma assistente virtual para projetos.")); msg.Add(new ChatMessageContent(AuthorRole.System, "Você responde sempre em português do Brasil e fala sobre detalhes de projeto, arquitetura e criação de casos de teste.")); msg.Add(new ChatMessageContent(AuthorRole.User, "Use sempre portugues do Brasil.")); } public void PromptEn(List msg) { msg.Add(new ChatMessageContent(AuthorRole.System, "You are an expert software analyst and QA professional.")); msg.Add(new ChatMessageContent(AuthorRole.System, "Please provide a comprehensive response in English (US). Consider the project context and requirements above to generate accurate and relevant information.")); msg.Add(new ChatMessageContent(AuthorRole.System, "If you have test case requests: Use Gherkin format (Given-When-Then) with realistic scenarios covering happy path, edge cases, and error handling.")); msg.Add(new ChatMessageContent(AuthorRole.System, "If you have project summaries: Include objectives, key features, technologies, and main challenges.")); msg.Add(new ChatMessageContent(AuthorRole.System, "If you have a task list request for one developer: Organize tasks by priority and estimated effort for a single developer, including technical dependencies.")); //msg.Add(new ChatMessageContent(AuthorRole.User, "Use sempre portugues do Brasil.")); } public void PromptPt(List msg) { msg.Add(new ChatMessageContent(AuthorRole.System, "Você é um analista de software especialista e profissional de QA.")); msg.Add(new ChatMessageContent(AuthorRole.System, "Por favor, forneça uma resposta abrangente em português do Brasil. Considere o contexto do projeto e os requisitos acima para gerar informações precisas e relevantes.")); msg.Add(new ChatMessageContent(AuthorRole.System, "Se forem solicitados casos de teste: Use o formato Gherkin (Dado-Quando-Então) com cenários realistas cobrindo caminho feliz, casos extremos e tratamento de erros.")); msg.Add(new ChatMessageContent(AuthorRole.System, "Se for solicitado um resumo do projeto: Inclua objetivos, principais funcionalidades, tecnologias e principais desafios.")); msg.Add(new ChatMessageContent(AuthorRole.System, "Se for uma solicitação de lista de tarefas para um(ou mais) desenvolvedor(es): Organize as tarefas por prioridade e esforço estimado para um único desenvolvedor, incluindo dependências técnicas.")); //msg.Add(new ChatMessageContent(AuthorRole.User, "Use sempre português do Brasil.")); } } }