Files
EmailBill/Service/AgentFramework/TextProcessingTools.cs
2026-01-12 14:34:03 +08:00

52 lines
1.4 KiB
C#

namespace Service.AgentFramework;
/// <summary>
/// 文本处理工具集
/// </summary>
public interface ITextProcessingTools
{
/// <summary>
/// 提取关键词
/// </summary>
Task<List<string>> ExtractKeywordsAsync(string text);
/// <summary>
/// 分析文本结构
/// </summary>
Task<Dictionary<string, object?>> AnalyzeTextStructureAsync(string text);
}
/// <summary>
/// 文本处理工具实现
/// </summary>
public class TextProcessingTools(
ITextSegmentService textSegmentService,
ILogger<TextProcessingTools> logger
) : ITextProcessingTools
{
public async Task<List<string>> ExtractKeywordsAsync(string text)
{
logger.LogDebug("提取关键词: {Text}", text);
var keywords = await Task.FromResult(textSegmentService.ExtractKeywords(text));
logger.LogDebug("提取到 {Count} 个关键词: {Keywords}",
keywords.Count,
string.Join(", ", keywords));
return keywords;
}
public async Task<Dictionary<string, object?>> AnalyzeTextStructureAsync(string text)
{
logger.LogDebug("分析文本结构");
return await Task.FromResult(new Dictionary<string, object?>
{
["length"] = text.Length,
["wordCount"] = text.Split(' ').Length,
["timestamp"] = DateTime.UtcNow
});
}
}