refine multilanguage log
This commit is contained in:
parent
4f5df7f857
commit
e3da6db9d7
|
|
@ -83,8 +83,7 @@ public class ConversationController : ControllerBase
|
|||
ConversationId = conversationId,
|
||||
MessageId = message.MessageId,
|
||||
CreatedAt = message.CreatedAt,
|
||||
Text = message.Content,
|
||||
SecondaryText = message.SecondaryContent,
|
||||
Text = !string.IsNullOrEmpty(message.SecondaryContent) ? message.SecondaryContent : message.Content,
|
||||
Data = message.Data,
|
||||
Sender = UserViewModel.FromUser(user)
|
||||
});
|
||||
|
|
@ -97,8 +96,7 @@ public class ConversationController : ControllerBase
|
|||
ConversationId = conversationId,
|
||||
MessageId = message.MessageId,
|
||||
CreatedAt = message.CreatedAt,
|
||||
Text = message.Content,
|
||||
SecondaryText = message.SecondaryContent,
|
||||
Text = !string.IsNullOrEmpty(message.SecondaryContent) ? message.SecondaryContent : message.Content,
|
||||
Function = message.FunctionName,
|
||||
Data = message.Data,
|
||||
Sender = new UserViewModel
|
||||
|
|
@ -106,8 +104,7 @@ public class ConversationController : ControllerBase
|
|||
FirstName = agent.Name,
|
||||
Role = message.Role,
|
||||
},
|
||||
RichContent = message.RichContent,
|
||||
SecondaryRichContent = message.SecondaryRichContent
|
||||
RichContent = message.SecondaryRichContent ?? message.RichContent
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -180,9 +177,9 @@ public class ConversationController : ControllerBase
|
|||
replyMessage: input.Postback,
|
||||
async msg =>
|
||||
{
|
||||
response.Text = msg.Content;
|
||||
response.Text = !string.IsNullOrEmpty(msg.SecondaryContent) ? msg.SecondaryContent : msg.Content;
|
||||
response.Function = msg.FunctionName;
|
||||
response.RichContent = msg.RichContent;
|
||||
response.RichContent = msg.SecondaryRichContent ?? msg.RichContent;
|
||||
response.Instruction = msg.Instruction;
|
||||
response.Data = msg.Data;
|
||||
},
|
||||
|
|
|
|||
|
|
@ -21,9 +21,6 @@ public class ChatResponseModel : InstructResult
|
|||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public FunctionCallFromLlm? Instruction { get; set; }
|
||||
|
||||
[JsonPropertyName("secondary_text")]
|
||||
public string? SecondaryText { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Rich message for UI rendering
|
||||
/// </summary>
|
||||
|
|
@ -31,10 +28,6 @@ public class ChatResponseModel : InstructResult
|
|||
[JsonPropertyName("rich_content")]
|
||||
public RichContent<IRichMessage>? RichContent { get; set; }
|
||||
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
[JsonPropertyName("secondary_rich_content")]
|
||||
public RichContent<IRichMessage>? SecondaryRichContent { get; set; }
|
||||
|
||||
[JsonPropertyName("created_at")]
|
||||
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ public class ChatHubConversationHook : ConversationHookBase
|
|||
{
|
||||
ConversationId = conv.ConversationId,
|
||||
MessageId = message.MessageId,
|
||||
Text = message.Content,
|
||||
Text = !string.IsNullOrEmpty(message.SecondaryContent) ? message.SecondaryContent : message.Content,
|
||||
Sender = UserViewModel.FromUser(sender)
|
||||
});
|
||||
|
||||
|
|
@ -71,9 +71,9 @@ public class ChatHubConversationHook : ConversationHookBase
|
|||
{
|
||||
ConversationId = conv.ConversationId,
|
||||
MessageId = message.MessageId,
|
||||
Text = message.Content,
|
||||
Text = !string.IsNullOrEmpty(message.SecondaryContent) ? message.SecondaryContent : message.Content,
|
||||
Function = message.FunctionName,
|
||||
RichContent = message.RichContent,
|
||||
RichContent = message.SecondaryRichContent ?? message.RichContent,
|
||||
Data = message.Data,
|
||||
Sender = new UserViewModel()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ using BotSharp.Abstraction.Options;
|
|||
using BotSharp.Abstraction.Repositories;
|
||||
using BotSharp.Abstraction.Routing;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Unicode;
|
||||
|
||||
namespace BotSharp.Plugin.ChatHub.Hooks;
|
||||
|
||||
|
|
@ -45,7 +47,7 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook, IR
|
|||
public override async Task OnMessageReceived(RoleDialogModel message)
|
||||
{
|
||||
var conversationId = _state.GetConversationId();
|
||||
var log = $"{message.Content}";
|
||||
var log = $"{GetMessageContent(message)}";
|
||||
|
||||
var input = new ContentLogInputModel(conversationId, message)
|
||||
{
|
||||
|
|
@ -59,7 +61,7 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook, IR
|
|||
public override async Task OnPostbackMessageReceived(RoleDialogModel message, PostbackMessageModel replyMsg)
|
||||
{
|
||||
var conversationId = _state.GetConversationId();
|
||||
var log = $"{message.Content}";
|
||||
var log = $"{GetMessageContent(message)}";
|
||||
var replyContent = JsonSerializer.Serialize(replyMsg, _options.JsonSerializerOptions);
|
||||
log += $"\r\n```json\r\n{replyContent}\r\n```";
|
||||
|
||||
|
|
@ -183,10 +185,18 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook, IR
|
|||
if (message.Role == AgentRole.Assistant)
|
||||
{
|
||||
var agent = await _agentService.LoadAgent(message.CurrentAgentId);
|
||||
var log = $"{message.Content}";
|
||||
if (message.RichContent != null)
|
||||
var log = $"{GetMessageContent(message)}";
|
||||
if (message.RichContent != null || message.SecondaryRichContent != null)
|
||||
{
|
||||
var richContent = JsonSerializer.Serialize(message.RichContent, _options.JsonSerializerOptions);
|
||||
var jsonOptions = new JsonSerializerOptions
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
AllowTrailingCommas = true,
|
||||
WriteIndented = true,
|
||||
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All)
|
||||
};
|
||||
var richContent = JsonSerializer.Serialize(message.SecondaryRichContent ?? message.RichContent, jsonOptions);
|
||||
log += $"\r\n```json\r\n{richContent}\r\n```";
|
||||
}
|
||||
|
||||
|
|
@ -204,7 +214,7 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook, IR
|
|||
public override async Task OnTaskCompleted(RoleDialogModel message)
|
||||
{
|
||||
var conversationId = _state.GetConversationId();
|
||||
var log = $"{message.Content}";
|
||||
var log = $"{GetMessageContent(message)}";
|
||||
var agent = await _agentService.LoadAgent(message.CurrentAgentId);
|
||||
|
||||
var input = new ContentLogInputModel(conversationId, message)
|
||||
|
|
@ -479,4 +489,9 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook, IR
|
|||
|
||||
return JsonSerializer.Serialize(model, _options.JsonSerializerOptions);
|
||||
}
|
||||
|
||||
private string GetMessageContent(RoleDialogModel message)
|
||||
{
|
||||
return !string.IsNullOrEmpty(message.SecondaryContent) ? message.SecondaryContent : message.Content;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue