Merge pull request #438 from iceljc/features/add-attachment
add payload
This commit is contained in:
commit
7020298ba1
|
|
@ -37,6 +37,7 @@ public class DialogElement
|
|||
public string? SecondaryContent { get; set; }
|
||||
public string? RichContent { get; set; }
|
||||
public string? SecondaryRichContent { get; set; }
|
||||
public string? Payload { get; set; }
|
||||
|
||||
public DialogElement()
|
||||
{
|
||||
|
|
@ -44,13 +45,14 @@ public class DialogElement
|
|||
}
|
||||
|
||||
public DialogElement(DialogMetaData meta, string content, string? richContent = null,
|
||||
string? secondaryContent = null, string? secondaryRichContent = null)
|
||||
string? secondaryContent = null, string? secondaryRichContent = null, string? payload = null)
|
||||
{
|
||||
MetaData = meta;
|
||||
Content = content;
|
||||
RichContent = richContent;
|
||||
SecondaryContent = secondaryContent;
|
||||
SecondaryRichContent = secondaryRichContent;
|
||||
Payload = payload;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
|
|
|||
|
|
@ -28,6 +28,10 @@ public class RoleDialogModel : ITrackableMessage
|
|||
|
||||
public string? SecondaryContent { get; set; }
|
||||
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
[JsonPropertyName("payload")]
|
||||
public string? Payload { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicator message used to provide UI feedback for function execution
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -50,7 +50,13 @@ public class ConversationStorage : IConversationStorage
|
|||
{
|
||||
return;
|
||||
}
|
||||
dialogElements.Add(new DialogElement(meta, content, dialog.SecondaryContent));
|
||||
dialogElements.Add(new DialogElement
|
||||
{
|
||||
MetaData = meta,
|
||||
Content = dialog.Content,
|
||||
SecondaryContent = dialog.SecondaryContent,
|
||||
Payload = dialog.Payload
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -72,7 +78,15 @@ public class ConversationStorage : IConversationStorage
|
|||
|
||||
var richContent = dialog.RichContent != null ? JsonSerializer.Serialize(dialog.RichContent, _options.JsonSerializerOptions) : null;
|
||||
var secondaryRichContent = dialog.SecondaryRichContent != null ? JsonSerializer.Serialize(dialog.SecondaryRichContent, _options.JsonSerializerOptions) : null;
|
||||
dialogElements.Add(new DialogElement(meta, content, richContent, dialog.SecondaryContent, secondaryRichContent));
|
||||
dialogElements.Add(new DialogElement
|
||||
{
|
||||
MetaData = meta,
|
||||
Content = dialog.Content,
|
||||
SecondaryContent = dialog.SecondaryContent,
|
||||
RichContent = richContent,
|
||||
SecondaryRichContent = secondaryRichContent,
|
||||
Payload = dialog.Payload
|
||||
});
|
||||
}
|
||||
|
||||
db.AppendConversationDialogs(conversationId, dialogElements);
|
||||
|
|
@ -90,6 +104,7 @@ public class ConversationStorage : IConversationStorage
|
|||
var meta = dialog.MetaData;
|
||||
var content = dialog.Content;
|
||||
var secondaryContent = dialog.SecondaryContent;
|
||||
var payload = dialog.Payload;
|
||||
var role = meta.Role;
|
||||
var currentAgentId = meta.AgentId;
|
||||
var messageId = meta.MessageId;
|
||||
|
|
@ -111,6 +126,7 @@ public class ConversationStorage : IConversationStorage
|
|||
RichContent = richContent,
|
||||
SecondaryContent = secondaryContent,
|
||||
SecondaryRichContent = secondaryRichContent,
|
||||
Payload = payload
|
||||
};
|
||||
results.Add(record);
|
||||
|
||||
|
|
|
|||
|
|
@ -529,6 +529,7 @@ namespace BotSharp.Core.Repository
|
|||
var trimmedContent = content.Substring(4);
|
||||
var secondaryContent = rawDialogs[i + 4];
|
||||
var trimmedSecondaryContent = string.IsNullOrEmpty(secondaryContent) ? null : secondaryContent.Substring(4);
|
||||
var payload = blocks.Count() > 6 ? blocks[6] : null;
|
||||
|
||||
var meta = new DialogMetaData
|
||||
{
|
||||
|
|
@ -540,9 +541,17 @@ namespace BotSharp.Core.Repository
|
|||
CreateTime = DateTime.Parse(blocks[0])
|
||||
};
|
||||
|
||||
var richContent = DecodeRichContent(rawDialogs[i + 1]);
|
||||
var secondaryRichContent = DecodeRichContent(rawDialogs[i + 3]);
|
||||
dialogs.Add(new DialogElement(meta, trimmedContent, richContent, trimmedSecondaryContent, secondaryRichContent));
|
||||
var richContent = DecodeText(rawDialogs[i + 1]);
|
||||
var secondaryRichContent = DecodeText(rawDialogs[i + 3]);
|
||||
dialogs.Add(new DialogElement
|
||||
{
|
||||
MetaData = meta,
|
||||
Content = trimmedContent,
|
||||
SecondaryContent = trimmedSecondaryContent,
|
||||
RichContent = richContent,
|
||||
SecondaryRichContent = secondaryRichContent,
|
||||
Payload = payload
|
||||
});
|
||||
}
|
||||
}
|
||||
return dialogs;
|
||||
|
|
@ -557,9 +566,10 @@ namespace BotSharp.Core.Repository
|
|||
{
|
||||
var meta = element.MetaData;
|
||||
var createTime = meta.CreateTime.ToString("MM/dd/yyyy hh:mm:ss.ffffff tt", CultureInfo.InvariantCulture);
|
||||
var encodedRichContent = EncodeRichContent(element.RichContent);
|
||||
var encodedSecondaryRichContent = EncodeRichContent(element.SecondaryRichContent);
|
||||
var metaStr = $"{createTime}|{meta.Role}|{meta.AgentId}|{meta.MessageId}|{meta.SenderId}|{meta.FunctionName}";
|
||||
var encodedRichContent = EncodeText(element.RichContent);
|
||||
var encodedSecondaryRichContent = EncodeText(element.SecondaryRichContent);
|
||||
var payload = element.Payload;
|
||||
var metaStr = $"{createTime}|{meta.Role}|{meta.AgentId}|{meta.MessageId}|{meta.SenderId}|{meta.FunctionName}|{payload}";
|
||||
dialogTexts.Add(metaStr);
|
||||
|
||||
dialogTexts.Add(encodedRichContent);
|
||||
|
|
@ -715,20 +725,20 @@ namespace BotSharp.Core.Repository
|
|||
return true;
|
||||
}
|
||||
|
||||
private string? EncodeRichContent(string? content)
|
||||
private string? EncodeText(string? text)
|
||||
{
|
||||
if (string.IsNullOrEmpty(content)) return content;
|
||||
if (string.IsNullOrEmpty(text)) return text;
|
||||
|
||||
var bytes = Encoding.UTF8.GetBytes(content);
|
||||
var bytes = Encoding.UTF8.GetBytes(text);
|
||||
var encoded = Convert.ToBase64String(bytes);
|
||||
return encoded;
|
||||
}
|
||||
|
||||
private string? DecodeRichContent(string? content)
|
||||
private string? DecodeText(string? text)
|
||||
{
|
||||
if (string.IsNullOrEmpty(content)) return content;
|
||||
if (string.IsNullOrEmpty(text)) return text;
|
||||
|
||||
var decoded = Convert.FromBase64String(content);
|
||||
var decoded = Convert.FromBase64String(text);
|
||||
var origin = Encoding.UTF8.GetString(decoded);
|
||||
return origin;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,7 +89,8 @@ public class ConversationController : ControllerBase
|
|||
CreatedAt = message.CreatedAt,
|
||||
Text = !string.IsNullOrEmpty(message.SecondaryContent) ? message.SecondaryContent : message.Content,
|
||||
Data = message.Data,
|
||||
Sender = UserViewModel.FromUser(user)
|
||||
Sender = UserViewModel.FromUser(user),
|
||||
Payload = message.Payload
|
||||
});
|
||||
}
|
||||
else if (message.Role == AgentRole.Assistant)
|
||||
|
|
|
|||
|
|
@ -28,6 +28,10 @@ public class ChatResponseModel : InstructResult
|
|||
[JsonPropertyName("rich_content")]
|
||||
public RichContent<IRichMessage>? RichContent { get; set; }
|
||||
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
[JsonPropertyName("payload")]
|
||||
public string? Payload { get; set; }
|
||||
|
||||
[JsonPropertyName("created_at")]
|
||||
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ public class DialogMongoElement
|
|||
public string? SecondaryContent { get; set; }
|
||||
public string? RichContent { get; set; }
|
||||
public string? SecondaryRichContent { get; set; }
|
||||
public string? Payload { get; set; }
|
||||
|
||||
public DialogMongoElement()
|
||||
{
|
||||
|
|
@ -23,7 +24,8 @@ public class DialogMongoElement
|
|||
Content = dialog.Content,
|
||||
SecondaryContent = dialog.SecondaryContent,
|
||||
RichContent = dialog.RichContent,
|
||||
SecondaryRichContent = dialog.SecondaryRichContent
|
||||
SecondaryRichContent = dialog.SecondaryRichContent,
|
||||
Payload = dialog.Payload
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -35,7 +37,8 @@ public class DialogMongoElement
|
|||
Content = dialog.Content,
|
||||
SecondaryContent = dialog.SecondaryContent,
|
||||
RichContent = dialog.RichContent,
|
||||
SecondaryRichContent = dialog.SecondaryRichContent
|
||||
SecondaryRichContent = dialog.SecondaryRichContent,
|
||||
Payload = dialog.Payload
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue