fix issues
This commit is contained in:
@@ -246,7 +246,10 @@ namespace ChatBot.Services
|
|||||||
if (content.Length < _aiSettings.MinMessageLengthForSummarization)
|
if (content.Length < _aiSettings.MinMessageLengthForSummarization)
|
||||||
{
|
{
|
||||||
return content.Length > _aiSettings.MaxSummarizedMessageLength
|
return content.Length > _aiSettings.MaxSummarizedMessageLength
|
||||||
? content.Substring(0, _aiSettings.MaxSummarizedMessageLength) + "..."
|
? string.Concat(
|
||||||
|
content.AsSpan(0, _aiSettings.MaxSummarizedMessageLength),
|
||||||
|
"..."
|
||||||
|
)
|
||||||
: content;
|
: content;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,10 +270,13 @@ namespace ChatBot.Services
|
|||||||
var summary = await GenerateSummaryAsync(summaryMessages, cancellationToken);
|
var summary = await GenerateSummaryAsync(summaryMessages, cancellationToken);
|
||||||
|
|
||||||
return string.IsNullOrEmpty(summary)
|
return string.IsNullOrEmpty(summary)
|
||||||
? content.Substring(
|
? string.Concat(
|
||||||
|
content.AsSpan(
|
||||||
0,
|
0,
|
||||||
Math.Min(content.Length, _aiSettings.MaxSummarizedMessageLength)
|
Math.Min(content.Length, _aiSettings.MaxSummarizedMessageLength)
|
||||||
) + "..."
|
),
|
||||||
|
"..."
|
||||||
|
)
|
||||||
: summary;
|
: summary;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -345,7 +351,7 @@ namespace ChatBot.Services
|
|||||||
|
|
||||||
var result = response.ToString().Trim();
|
var result = response.ToString().Trim();
|
||||||
return result.Length > _aiSettings.MaxSummarizedMessageLength
|
return result.Length > _aiSettings.MaxSummarizedMessageLength
|
||||||
? result.Substring(0, _aiSettings.MaxSummarizedMessageLength) + "..."
|
? string.Concat(result.AsSpan(0, _aiSettings.MaxSummarizedMessageLength), "...")
|
||||||
: result;
|
: result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -419,8 +425,10 @@ namespace ChatBot.Services
|
|||||||
return new ChatMessage
|
return new ChatMessage
|
||||||
{
|
{
|
||||||
Role = message.Role,
|
Role = message.Role,
|
||||||
Content =
|
Content = string.Concat(
|
||||||
message.Content.Substring(0, _aiSettings.MaxSummarizedMessageLength) + "...",
|
message.Content.AsSpan(0, _aiSettings.MaxSummarizedMessageLength),
|
||||||
|
"..."
|
||||||
|
),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ namespace ChatBot.Services.Telegram.Commands
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class CommandRegistry
|
public class CommandRegistry
|
||||||
{
|
{
|
||||||
private readonly Dictionary<string, ITelegramCommand> _commands = new();
|
private readonly Dictionary<string, ITelegramCommand> _commands = new(
|
||||||
|
StringComparer.OrdinalIgnoreCase
|
||||||
|
);
|
||||||
private readonly ILogger<CommandRegistry> _logger;
|
private readonly ILogger<CommandRegistry> _logger;
|
||||||
|
|
||||||
public CommandRegistry(
|
public CommandRegistry(
|
||||||
@@ -32,12 +34,9 @@ namespace ChatBot.Services.Telegram.Commands
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void RegisterCommand(ITelegramCommand command)
|
private void RegisterCommand(ITelegramCommand command)
|
||||||
{
|
{
|
||||||
if (command == null)
|
ArgumentNullException.ThrowIfNull(command);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(command));
|
|
||||||
}
|
|
||||||
|
|
||||||
var commandName = command.CommandName.ToLower();
|
var commandName = command.CommandName;
|
||||||
if (_commands.ContainsKey(commandName))
|
if (_commands.ContainsKey(commandName))
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Command '{CommandName}' is already registered", commandName);
|
_logger.LogWarning("Command '{CommandName}' is already registered", commandName);
|
||||||
@@ -53,8 +52,7 @@ namespace ChatBot.Services.Telegram.Commands
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public ITelegramCommand? GetCommand(string commandName)
|
public ITelegramCommand? GetCommand(string commandName)
|
||||||
{
|
{
|
||||||
var key = commandName.ToLower();
|
return _commands.TryGetValue(commandName, out var command) ? command : null;
|
||||||
return _commands.TryGetValue(key, out var command) ? command : null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ namespace ChatBot.Services.Telegram.Commands
|
|||||||
command = command.Split('@')[0];
|
command = command.Split('@')[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
return command == CommandName.ToLower();
|
return string.Equals(command, CommandName, StringComparison.OrdinalIgnoreCase);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ namespace ChatBot.Services.Telegram.Services
|
|||||||
messageText,
|
messageText,
|
||||||
chatId,
|
chatId,
|
||||||
userName,
|
userName,
|
||||||
message.Chat.Type.ToString().ToLower(),
|
message.Chat.Type.ToString(),
|
||||||
message.Chat.Title ?? "",
|
message.Chat.Title ?? "",
|
||||||
replyInfo,
|
replyInfo,
|
||||||
cancellationToken
|
cancellationToken
|
||||||
|
|||||||
Reference in New Issue
Block a user