Merge pull request #1154 from iceljc/master
add message wrapper to chat response
This commit is contained in:
commit
89e1acf17c
|
|
@ -371,9 +371,11 @@ public class ConversationController : ControllerBase
|
||||||
{
|
{
|
||||||
response.Text = !string.IsNullOrEmpty(msg.SecondaryContent) ? msg.SecondaryContent : msg.Content;
|
response.Text = !string.IsNullOrEmpty(msg.SecondaryContent) ? msg.SecondaryContent : msg.Content;
|
||||||
response.Function = msg.FunctionName;
|
response.Function = msg.FunctionName;
|
||||||
|
response.MessageLabel = msg.MessageLabel;
|
||||||
response.RichContent = msg.SecondaryRichContent ?? msg.RichContent;
|
response.RichContent = msg.SecondaryRichContent ?? msg.RichContent;
|
||||||
response.Instruction = msg.Instruction;
|
response.Instruction = msg.Instruction;
|
||||||
response.Data = msg.Data;
|
response.Data = msg.Data;
|
||||||
|
response.AdditionalMessageWrapper = ChatResponseWrapper.From(msg.AdditionalMessageWrapper, conversationId, inputMsg.MessageId);
|
||||||
});
|
});
|
||||||
|
|
||||||
var state = _services.GetRequiredService<IConversationStateService>();
|
var state = _services.GetRequiredService<IConversationStateService>();
|
||||||
|
|
@ -426,11 +428,13 @@ public class ConversationController : ControllerBase
|
||||||
async msg =>
|
async msg =>
|
||||||
{
|
{
|
||||||
response.Text = !string.IsNullOrEmpty(msg.SecondaryContent) ? msg.SecondaryContent : msg.Content;
|
response.Text = !string.IsNullOrEmpty(msg.SecondaryContent) ? msg.SecondaryContent : msg.Content;
|
||||||
|
response.MessageLabel = msg.MessageLabel;
|
||||||
response.Function = msg.FunctionName;
|
response.Function = msg.FunctionName;
|
||||||
response.RichContent = msg.SecondaryRichContent ?? msg.RichContent;
|
response.RichContent = msg.SecondaryRichContent ?? msg.RichContent;
|
||||||
response.Instruction = msg.Instruction;
|
response.Instruction = msg.Instruction;
|
||||||
response.Data = msg.Data;
|
response.Data = msg.Data;
|
||||||
response.States = state.GetStates();
|
response.States = state.GetStates();
|
||||||
|
response.AdditionalMessageWrapper = ChatResponseWrapper.From(msg.AdditionalMessageWrapper, conversationId, inputMsg.MessageId);
|
||||||
|
|
||||||
await OnChunkReceived(Response, response);
|
await OnChunkReceived(Response, response);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,46 @@
|
||||||
using BotSharp.Abstraction.Conversations.Dtos;
|
using BotSharp.Abstraction.Conversations.Dtos;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace BotSharp.OpenAPI.ViewModels.Conversations;
|
namespace BotSharp.OpenAPI.ViewModels.Conversations;
|
||||||
|
|
||||||
public class ChatResponseModel : ChatResponseDto
|
public class ChatResponseModel : ChatResponseDto
|
||||||
{
|
{
|
||||||
|
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||||
|
[JsonPropertyName("additional_message_wrapper")]
|
||||||
|
public ChatResponseWrapper? AdditionalMessageWrapper { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ChatResponseWrapper
|
||||||
|
{
|
||||||
|
[JsonPropertyName("sending_interval")]
|
||||||
|
public int SendingInterval { get; set; }
|
||||||
|
|
||||||
|
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||||
|
[JsonPropertyName("messages")]
|
||||||
|
public List<ChatResponseModel>? Messages { get; set; }
|
||||||
|
|
||||||
|
public static ChatResponseWrapper? From(ChatMessageWrapper? wrapper, string conversationId, string? messageId = null)
|
||||||
|
{
|
||||||
|
if (wrapper == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ChatResponseWrapper
|
||||||
|
{
|
||||||
|
SendingInterval = wrapper.SendingInterval,
|
||||||
|
Messages = wrapper?.Messages?.Select(x => new ChatResponseModel
|
||||||
|
{
|
||||||
|
ConversationId = conversationId,
|
||||||
|
MessageId = messageId ?? x.MessageId,
|
||||||
|
Text = !string.IsNullOrEmpty(x.SecondaryContent) ? x.SecondaryContent : x.Content,
|
||||||
|
MessageLabel = x.MessageLabel,
|
||||||
|
Function = x.FunctionName,
|
||||||
|
RichContent = x.SecondaryRichContent ?? x.RichContent,
|
||||||
|
Instruction = x.Instruction,
|
||||||
|
Data = x.Data,
|
||||||
|
IsAppend = true
|
||||||
|
})?.ToList()
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue