Re-format dialog history.
This commit is contained in:
parent
b6c0d47b02
commit
3f49d11eff
|
|
@ -6,6 +6,7 @@ public class RoleDialogModel
|
|||
/// user, system, assistant, function
|
||||
/// </summary>
|
||||
public string Role { get; set; }
|
||||
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||
public string Content { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -19,5 +19,6 @@ public class FunctionExecutionValidationResult
|
|||
public string ValidationStatus { get; set; }
|
||||
|
||||
[JsonPropertyName("validation_message")]
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public string ValidationMessage { get; set; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using BotSharp.Abstraction.Conversations.Models;
|
||||
using System.IO;
|
||||
using Tensorflow;
|
||||
|
||||
namespace BotSharp.Core.Conversations.Services;
|
||||
|
||||
|
|
@ -14,20 +15,32 @@ public class ConversationStorage : IConversationStorage
|
|||
public void Append(string agentId, string conversationId, RoleDialogModel dialog)
|
||||
{
|
||||
var conversationFile = GetStorageFile(agentId, conversationId);
|
||||
File.AppendAllText(conversationFile, $"{dialog.Role}: {dialog.Content}\n");
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine($"{dialog.Role}|{dialog.CreatedAt}");
|
||||
sb.AppendLine($" - {dialog.Content}");
|
||||
var conversation = sb.ToString();
|
||||
File.AppendAllText(conversationFile, conversation);
|
||||
}
|
||||
|
||||
public List<RoleDialogModel> GetDialogs(string agentId, string conversationId)
|
||||
{
|
||||
var conversationFile = GetStorageFile(agentId, conversationId);
|
||||
var dialogs = File.ReadAllLines(conversationFile);
|
||||
return dialogs.Select(x =>
|
||||
|
||||
var results = new List<RoleDialogModel>();
|
||||
for (int i = 0; i < dialogs.Length; i += 2)
|
||||
{
|
||||
var pos = x.IndexOf(':');
|
||||
var role = x.Substring(0, pos);
|
||||
var text = x.Substring(pos + 1);
|
||||
return new RoleDialogModel(role, text);
|
||||
}).ToList();
|
||||
var meta = dialogs[i];
|
||||
var dialog = dialogs[i + 1];
|
||||
var role = meta.Split('|')[0];
|
||||
var createdAt = DateTime.Parse(meta.Split('|')[1]);
|
||||
var text = dialog.Substring(4);
|
||||
results.Add(new RoleDialogModel(role, text)
|
||||
{
|
||||
CreatedAt = createdAt
|
||||
});
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
public void InitStorage(string agentId, string conversationId)
|
||||
|
|
|
|||
|
|
@ -105,6 +105,13 @@ public class WebhookController : ControllerBase
|
|||
Recipient = JsonSerializer.Serialize(new { Id = sessionId }, jsonOpt),
|
||||
Message = JsonSerializer.Serialize(new { Text = "I'm pulling the relevent information, please wait a second ..." }, jsonOpt)
|
||||
});
|
||||
|
||||
await messenger.SendMessage(setting.ApiVersion, setting.PageId, new SendingMessageRequest
|
||||
{
|
||||
AccessToken = setting.PageAccessToken,
|
||||
Recipient = JsonSerializer.Serialize(new { Id = sessionId }, jsonOpt),
|
||||
SenderAction = SenderActionEnum.TypingOn
|
||||
});
|
||||
});
|
||||
|
||||
// Response to user
|
||||
|
|
|
|||
Loading…
Reference in a new issue