Merge pull request #201 from hchen2020/master
Adjust rich content data structure.
This commit is contained in:
commit
c20cdd13e5
|
|
@ -1,4 +1,6 @@
|
|||
using BotSharp.Abstraction.Functions.Models;
|
||||
using BotSharp.Abstraction.Messaging.Models;
|
||||
using BotSharp.Abstraction.Messaging.Models.RichContent;
|
||||
|
||||
namespace BotSharp.Abstraction.Conversations.Models;
|
||||
|
||||
|
|
@ -35,7 +37,7 @@ public class RoleDialogModel : ITrackableMessage
|
|||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public object Data { get; set; }
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public object? RichContent { get; set; }
|
||||
public RichContent<IMessageTemplate>? RichContent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Stop conversation completion
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ public class FunctionCallFromLlm : RoutingArgs
|
|||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public JsonDocument? Arguments { get; set; }
|
||||
|
||||
public bool IsExecutionOnce { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
var route = string.IsNullOrEmpty(AgentName) ? "" : $"<Route to {AgentName.ToUpper()} because {Reason}>";
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
namespace BotSharp.Abstraction.Messaging.Models;
|
||||
|
||||
public interface IMessageTemplate
|
||||
{
|
||||
string Text { get; set; }
|
||||
}
|
||||
|
|
@ -9,7 +9,6 @@ namespace BotSharp.Abstraction.Messaging.Models.RichContent
|
|||
public string? Payload { get; set; }
|
||||
[JsonPropertyName("image_url")]
|
||||
public string? ImageUrl { get; set; }
|
||||
[JsonPropertyName("postback_url")]
|
||||
public string? PostBackUrl { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
|
||||
namespace BotSharp.Abstraction.Messaging.Models.RichContent
|
||||
{
|
||||
public class QuickReplyMessage : TextMessage
|
||||
public class QuickReplyMessage : IMessageTemplate
|
||||
{
|
||||
public string Text { get; set; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("quick_replies")]
|
||||
public List<QuickReplyElement> QuickReplies { get; set; } = new List<QuickReplyElement>();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
namespace BotSharp.Abstraction.Messaging.Models.RichContent
|
||||
{
|
||||
public class RichContent<T>
|
||||
public class RichContent<T> where T : IMessageTemplate
|
||||
{
|
||||
public Recipient Recipient { get; set; } = new Recipient();
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -1,9 +0,0 @@
|
|||
|
||||
namespace BotSharp.Abstraction.Messaging.Models.RichContent.Template
|
||||
{
|
||||
public class AttachmentTemplate<T>
|
||||
{
|
||||
public string Type => "template";
|
||||
public T Payload { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,10 @@
|
|||
|
||||
namespace BotSharp.Abstraction.Messaging.Models.RichContent.Template
|
||||
{
|
||||
public class ButtonTemplate : TextMessage
|
||||
public class ButtonTemplate : IMessageTemplate
|
||||
{
|
||||
public string Text { get; set; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("template_type")]
|
||||
public string TemplateType => "button";
|
||||
public List<ButtonElement> Buttons { get; set; } = new List<ButtonElement>();
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
|
||||
namespace BotSharp.Abstraction.Messaging.Models.RichContent.Template
|
||||
{
|
||||
public class MultiSelectTemplate : TextMessage
|
||||
public class MultiSelectTemplate : IMessageTemplate
|
||||
{
|
||||
public string Text { get; set; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("template_type")]
|
||||
public string TemplateType => "multi-select";
|
||||
public List<OptionElement> Options { get; set; } = new List<OptionElement>();
|
||||
|
|
|
|||
|
|
@ -1,11 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace BotSharp.Abstraction.Messaging.Models.RichContent.Template
|
||||
{
|
||||
public class TemplateMessage<T>
|
||||
{
|
||||
public T Attachment { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,7 @@
|
|||
|
||||
namespace BotSharp.Abstraction.Messaging.Models.RichContent
|
||||
namespace BotSharp.Abstraction.Messaging.Models.RichContent;
|
||||
|
||||
public class TextMessage : IMessageTemplate
|
||||
{
|
||||
public class TextMessage
|
||||
{
|
||||
public string Text { get; set; } = string.Empty;
|
||||
}
|
||||
public string Text { get; set; } = string.Empty;
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
using System.Text.Json;
|
||||
|
||||
namespace BotSharp.Abstraction.Messaging.Models;
|
||||
|
||||
public class RichContentJsonConverter : JsonConverter<IMessageTemplate>
|
||||
{
|
||||
public override IMessageTemplate? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, IMessageTemplate value, JsonSerializerOptions options)
|
||||
{
|
||||
JsonSerializer.Serialize(writer, value, value.GetType(), options);
|
||||
}
|
||||
}
|
||||
|
|
@ -56,7 +56,6 @@
|
|||
<PackageReference Include="Colorful.Console" Version="1.2.15" />
|
||||
<PackageReference Include="EntityFrameworkCore.BootKit" Version="6.2.1" />
|
||||
<PackageReference Include="Fluid.Core" Version="2.5.0" />
|
||||
<PackageReference Include="TensorFlow.Keras" Version="0.11.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using BotSharp.Abstraction.Agents.Models;
|
||||
using BotSharp.Abstraction.Messaging.Models;
|
||||
using BotSharp.Abstraction.Messaging.Models.RichContent;
|
||||
using BotSharp.Abstraction.Routing;
|
||||
using BotSharp.Abstraction.Routing.Settings;
|
||||
|
|
@ -102,7 +103,7 @@ public partial class ConversationService
|
|||
|
||||
// Only read content from RichContent for UI rendering. When richContent is null, create a basic text message for richContent.
|
||||
var state = _services.GetRequiredService<IConversationStateService>();
|
||||
response.RichContent = response.RichContent ?? new RichContent<TextMessage>
|
||||
response.RichContent = response.RichContent ?? new RichContent<IMessageTemplate>
|
||||
{
|
||||
Recipient = new Recipient { Id = state.GetConversationId() },
|
||||
Message = new TextMessage { Text = response.Content }
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
using BotSharp.Abstraction.Functions.Models;
|
||||
using BotSharp.Abstraction.Messaging.Models;
|
||||
using BotSharp.Abstraction.Messaging.Models.RichContent;
|
||||
using BotSharp.Abstraction.Planning;
|
||||
using BotSharp.Abstraction.Routing;
|
||||
|
||||
|
|
@ -33,6 +35,14 @@ public class InstructExecutor : IExecutor
|
|||
response.MessageId = message.MessageId;
|
||||
response.Instruction = inst;
|
||||
|
||||
// Process rich content
|
||||
if (response.RichContent != null &&
|
||||
response.RichContent is RichContent<IMessageTemplate> template &&
|
||||
string.IsNullOrEmpty(template.Message.Text))
|
||||
{
|
||||
template.Message.Text = response.Content;
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,6 +36,10 @@ public class RouteToAgentRoutingHandler : RoutingHandlerBase, IRoutingHandler
|
|||
var ret = await function.Execute(message);
|
||||
|
||||
var agentId = context.GetCurrentAgentId();
|
||||
if (inst.IsExecutionOnce)
|
||||
{
|
||||
message.Content = inst.Question;
|
||||
}
|
||||
ret = await routing.InvokeAgent(agentId, _dialogs);
|
||||
|
||||
var response = _dialogs.Last();
|
||||
|
|
|
|||
|
|
@ -44,7 +44,9 @@ public partial class RoutingService : IRoutingService
|
|||
Function = "route_to_agent",
|
||||
Question = message.Content,
|
||||
Reason = message.Content,
|
||||
AgentName = agent.Name
|
||||
AgentName = agent.Name,
|
||||
OriginalAgent = agent.Name,
|
||||
IsExecutionOnce = true
|
||||
};
|
||||
|
||||
var result = await handler.Handle(this, inst, message);
|
||||
|
|
|
|||
Loading…
Reference in a new issue