95 lines
4.9 KiB
C#
95 lines
4.9 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)
|
|
{
|
|
//var msg = new List<ChatMessageContent>();
|
|
////msg.Add(new ChatMessageContent(AuthorRole.System, "Your name is SuperChat. \nYou only generate answers using portuguese.\nYou are friendly and polite.\nYou speak only Brazilian Portuguese.\nYou never create a response in English. Always brazilian portuguese."));
|
|
//msg.Add(new ChatMessageContent(AuthorRole.System, "Seu nome é SuperChat."));
|
|
//msg.Add(new ChatMessageContent(AuthorRole.System, "Você só gera respostas usando português do Brasil."));
|
|
//msg.Add(new ChatMessageContent(AuthorRole.System, "Você fala apenas português brasileiro."));
|
|
//msg.Add(new ChatMessageContent(AuthorRole.System, "Você nunca cria respostas em inglês, mas sempre em português brasileiro."));
|
|
//string json = JsonSerializer.Serialize(msg);
|
|
//var history = new ChatHistory(JsonSerializer.Deserialize<List<ChatMessageContent>>(json));
|
|
|
|
//return history;
|
|
|
|
if (_keyValues.ContainsKey(sessionId))
|
|
{
|
|
var history = _keyValues[sessionId];
|
|
return history;
|
|
}
|
|
else
|
|
{
|
|
var msg = new List<ChatMessageContent>();
|
|
TestePrompt(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>();
|
|
PromptLiliana(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 TestePromptBot(List<ChatMessageContent> msg)
|
|
{
|
|
msg.Add(new ChatMessageContent(AuthorRole.System, "Seu nome é Rosa, uma vendedora de bolos que está atendendo seus clientes. "));
|
|
msg.Add(new ChatMessageContent(AuthorRole.System, "Você tem apenas os seguintes sabores de bolo: chocolate, baunilha e morango. "));
|
|
msg.Add(new ChatMessageContent(AuthorRole.System, "Excepcionalmente hoje, o sabor morango está fora de estoque. Você não tem mais morangos. "));
|
|
msg.Add(new ChatMessageContent(AuthorRole.System, "Cada fatia de bolo custa 5 reais. \n"));
|
|
msg.Add(new ChatMessageContent(AuthorRole.User, "Responda sempre em portugues do Brasil as minhas perguntas."));
|
|
}
|
|
|
|
public void PromptLiliana(List<ChatMessageContent> msg)
|
|
{
|
|
msg.Add(new ChatMessageContent(AuthorRole.System, "Seu nome é LiliAna, um assistente virtual da Domvs It (Consultoria e RH)."));
|
|
msg.Add(new ChatMessageContent(AuthorRole.System, "Você responde sempre em português do Brasil e fala sobre serviços prestados pela Domvs iT."));
|
|
msg.Add(new ChatMessageContent(AuthorRole.System, "Você consegue fazer solicitações no portal do RH da Domvs iT."));
|
|
msg.Add(new ChatMessageContent(AuthorRole.System, "Você responde perguntas voltadas ao mercado de trabalho de tecnologia."));
|
|
msg.Add(new ChatMessageContent(AuthorRole.System, "Em breve, você será capaz de consultar o linkedin."));
|
|
msg.Add(new ChatMessageContent(AuthorRole.User, "Use sempre portugues do Brasil."));
|
|
}
|
|
|
|
public void TestePrompt(List<ChatMessageContent> msg)
|
|
{
|
|
msg.Add(new ChatMessageContent(AuthorRole.System, "Seu nome é Ian."));
|
|
msg.Add(new ChatMessageContent(AuthorRole.System, "Você só gera respostas usando português do Brasil."));
|
|
msg.Add(new ChatMessageContent(AuthorRole.System, "Você fala apenas português brasileiro."));
|
|
msg.Add(new ChatMessageContent(AuthorRole.System, "Você nunca cria respostas em inglês, mas sempre em português brasileiro."));
|
|
msg.Add(new ChatMessageContent(AuthorRole.User, "Responda sempre em portugues do Brasil as minhas perguntas."));
|
|
}
|
|
}
|
|
}
|