ChatRAG/ChatHistoryService.cs
2025-06-12 10:41:33 -03:00

75 lines
3.5 KiB
C#

using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.ChatCompletion;
using System.Text.Json;
namespace ChatApi
{
public class ChatHistoryService
{
private readonly Dictionary<string, ChatHistory> _keyValues = new Dictionary<string, ChatHistory>();
public ChatHistoryService()
{
}
public ChatHistory Get(string sessionId)
{
if (_keyValues.ContainsKey(sessionId))
{
var history = _keyValues[sessionId];
return history;
}
else
{
var msg = new List<ChatMessageContent>();
PromptLiliana(msg);
string json = JsonSerializer.Serialize(msg);
var history = new ChatHistory(JsonSerializer.Deserialize<List<ChatMessageContent>>(json));
_keyValues[sessionId] = history;
return _keyValues[sessionId];
}
}
public ChatHistory GetSumarizer(string sessionId)
{
if (_keyValues.ContainsKey(sessionId))
{
var history = _keyValues[sessionId];
return history;
}
else
{
var msg = new List<ChatMessageContent>();
PromptEn(msg);
string json = JsonSerializer.Serialize(msg);
var history = new ChatHistory(JsonSerializer.Deserialize<List<ChatMessageContent>>(json));
_keyValues[sessionId] = history;
return _keyValues[sessionId];
}
}
public void UpdateHistory(string sessionId, ChatHistory history)
{
_keyValues[sessionId] = history;
}
public void PromptLiliana(List<ChatMessageContent> 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<ChatMessageContent> 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. 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.System, "If you have a task list request for more than one developer: Organize tasks by priority and estimated effort for a every developer, including technical dependencies."));
//msg.Add(new ChatMessageContent(AuthorRole.User, "Use sempre portugues do Brasil."));
}
}
}