structure dialog meta data
This commit is contained in:
parent
1286f35d8b
commit
0df8f14b9a
|
|
@ -25,7 +25,7 @@ public class Conversation
|
|||
|
||||
public class DialogElement
|
||||
{
|
||||
public string MetaData { get; set; }
|
||||
public DialogMeta MetaData { get; set; }
|
||||
public string Content { get; set; }
|
||||
|
||||
public DialogElement()
|
||||
|
|
@ -33,9 +33,19 @@ public class DialogElement
|
|||
|
||||
}
|
||||
|
||||
public DialogElement(string meta, string content)
|
||||
public DialogElement(DialogMeta meta, string content)
|
||||
{
|
||||
MetaData = meta;
|
||||
Content = content;
|
||||
}
|
||||
}
|
||||
|
||||
public class DialogMeta
|
||||
{
|
||||
public string Role { get; set; }
|
||||
public string AgentId { get; set; }
|
||||
public string MessageId { get; set; }
|
||||
public string? FunctionName { get; set; }
|
||||
public string? SenderId { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,8 +24,15 @@ public class ConversationStorage : IConversationStorage
|
|||
|
||||
if (dialog.Role == AgentRole.Function)
|
||||
{
|
||||
// var args = dialog.FunctionArgs.RemoveNewLine();
|
||||
var meta = $"{dialog.CreatedAt}|{dialog.Role}|{agentId}|{dialog.MessageId}|{dialog.FunctionName}";
|
||||
var meta = new DialogMeta
|
||||
{
|
||||
Role = dialog.Role,
|
||||
AgentId = agentId,
|
||||
MessageId = dialog.MessageId,
|
||||
FunctionName = dialog.FunctionName,
|
||||
CreateTime = dialog.CreatedAt
|
||||
};
|
||||
|
||||
var content = dialog.Content.RemoveNewLine();
|
||||
if (string.IsNullOrEmpty(content))
|
||||
{
|
||||
|
|
@ -35,7 +42,15 @@ public class ConversationStorage : IConversationStorage
|
|||
}
|
||||
else
|
||||
{
|
||||
var meta = $"{dialog.CreatedAt}|{dialog.Role}|{agentId}|{dialog.MessageId}|{dialog.SenderId}";
|
||||
var meta = new DialogMeta
|
||||
{
|
||||
Role = dialog.Role,
|
||||
AgentId = agentId,
|
||||
MessageId = dialog.MessageId,
|
||||
SenderId = dialog.SenderId,
|
||||
CreateTime = dialog.CreatedAt
|
||||
};
|
||||
|
||||
var content = dialog.Content.RemoveNewLine();
|
||||
if (string.IsNullOrEmpty(content))
|
||||
{
|
||||
|
|
@ -58,13 +73,12 @@ public class ConversationStorage : IConversationStorage
|
|||
{
|
||||
var meta = dialog.MetaData;
|
||||
var content = dialog.Content;
|
||||
var blocks = meta.Split('|');
|
||||
var createdAt = DateTime.Parse(blocks[0]);
|
||||
var role = blocks[1];
|
||||
var currentAgentId = blocks[2];
|
||||
var messageId = blocks[3];
|
||||
var senderId = role == AgentRole.Function ? currentAgentId : blocks[4];
|
||||
var function = role == AgentRole.Function ? blocks[4] : null;
|
||||
var role = meta.Role;
|
||||
var currentAgentId = meta.AgentId;
|
||||
var messageId = meta.MessageId;
|
||||
var function = role == AgentRole.Function ? meta.FunctionName : null;
|
||||
var senderId = role == AgentRole.Function ? currentAgentId : meta.SenderId;
|
||||
var createdAt = meta.CreateTime;
|
||||
|
||||
results.Add(new RoleDialogModel(role, content)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1037,9 +1037,18 @@ public class FileRepository : IBotSharpRepository
|
|||
{
|
||||
for (int i = 0; i < rawDialogs.Count(); i += 2)
|
||||
{
|
||||
var meta = rawDialogs[i];
|
||||
var blocks = rawDialogs[i].Split("|");
|
||||
var content = rawDialogs[i + 1];
|
||||
var trimmed = content.Substring(4);
|
||||
var meta = new DialogMeta
|
||||
{
|
||||
Role = blocks[1],
|
||||
AgentId = blocks[2],
|
||||
MessageId = blocks[3],
|
||||
FunctionName = blocks[1] == AgentRole.Function ? blocks[4] : null,
|
||||
SenderId = blocks[1] == AgentRole.Function ? null : blocks[4],
|
||||
CreateTime = DateTime.Parse(blocks[0])
|
||||
};
|
||||
dialogs.Add(new DialogElement(meta, trimmed));
|
||||
}
|
||||
}
|
||||
|
|
@ -1053,7 +1062,10 @@ public class FileRepository : IBotSharpRepository
|
|||
|
||||
foreach (var element in dialogs)
|
||||
{
|
||||
dialogTexts.Add(element.MetaData);
|
||||
var meta = element.MetaData;
|
||||
var source = meta.FunctionName ?? meta.SenderId;
|
||||
var metaStr = $"{meta.CreateTime}|{meta.Role}|{meta.AgentId}|{meta.MessageId}|{source}";
|
||||
dialogTexts.Add(metaStr);
|
||||
var content = $" - {element.Content}";
|
||||
dialogTexts.Add(content);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ namespace BotSharp.Plugin.MongoStorage.Models;
|
|||
|
||||
public class DialogMongoElement
|
||||
{
|
||||
public string MetaData { get; set; }
|
||||
public DialogMetaMongoElement MetaData { get; set; }
|
||||
public string Content { get; set; }
|
||||
|
||||
public DialogMongoElement()
|
||||
|
|
@ -16,7 +16,7 @@ public class DialogMongoElement
|
|||
{
|
||||
return new DialogMongoElement
|
||||
{
|
||||
MetaData = dialog.MetaData,
|
||||
MetaData = DialogMetaMongoElement.ToMongoElement(dialog.MetaData),
|
||||
Content = dialog.Content
|
||||
};
|
||||
}
|
||||
|
|
@ -25,8 +25,49 @@ public class DialogMongoElement
|
|||
{
|
||||
return new DialogElement
|
||||
{
|
||||
MetaData = dialog.MetaData,
|
||||
MetaData = DialogMetaMongoElement.ToDomainElement(dialog.MetaData),
|
||||
Content = dialog.Content
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public class DialogMetaMongoElement
|
||||
{
|
||||
public string Role { get; set; }
|
||||
public string AgentId { get; set; }
|
||||
public string MessageId { get; set; }
|
||||
public string? FunctionName { get; set; }
|
||||
public string? SenderId { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
|
||||
public DialogMetaMongoElement()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static DialogMeta ToDomainElement(DialogMetaMongoElement meta)
|
||||
{
|
||||
return new DialogMeta
|
||||
{
|
||||
Role = meta.Role,
|
||||
AgentId = meta.AgentId,
|
||||
MessageId = meta.MessageId,
|
||||
FunctionName = meta.FunctionName,
|
||||
SenderId = meta.SenderId,
|
||||
CreateTime = meta.CreateTime,
|
||||
};
|
||||
}
|
||||
|
||||
public static DialogMetaMongoElement ToMongoElement(DialogMeta meta)
|
||||
{
|
||||
return new DialogMetaMongoElement
|
||||
{
|
||||
Role = meta.Role,
|
||||
AgentId = meta.AgentId,
|
||||
MessageId = meta.MessageId,
|
||||
FunctionName = meta.FunctionName,
|
||||
SenderId = meta.SenderId,
|
||||
CreateTime = meta.CreateTime,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue