forked from SciSharp/BotSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatResponseModel.cs
More file actions
46 lines (40 loc) · 1.54 KB
/
Copy pathChatResponseModel.cs
File metadata and controls
46 lines (40 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using BotSharp.Abstraction.Conversations.Dtos;
using System.Text.Json.Serialization;
namespace BotSharp.OpenAPI.ViewModels.Conversations;
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()
};
}
}