From b5ff6c141c560cb1fefb408f9d9a7d458c78b4e2 Mon Sep 17 00:00:00 2001 From: ccnetcore Date: Thu, 8 Jan 2026 22:19:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=81=94=E7=BD=91=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=8C=89=E6=97=B6=E9=97=B4=E8=8C=83=E5=9B=B4?= =?UTF-8?q?=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - OnlineSearch 方法新增 daysAgo 参数,支持按最近天数筛选搜索结果 - 百度搜索请求增加 search_filter 时间范围(gte/lte) - 补充相关模型与 JSON 源生成配置 - 更新工具描述,明确近期与实时信息范围 --- .../Mcp/OnlineSearchTool.cs | 57 ++++++++++++++++++- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Mcp/OnlineSearchTool.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Mcp/OnlineSearchTool.cs index 6aebde0a..1e6ba1b5 100644 --- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Mcp/OnlineSearchTool.cs +++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Mcp/OnlineSearchTool.cs @@ -28,8 +28,8 @@ public class OnlineSearchTool : ISingletonDependency _baiduApiKey = configuration["BaiduSearch:ApiKey"] ?? ""; } - [YiAgentTool("联网搜索"), DisplayName("OnlineSearch"), Description("进行在线搜索,获取最新的网络信息")] - public async Task OnlineSearch(string keyword) + [YiAgentTool("联网搜索"), DisplayName("OnlineSearch"), Description("进行在线搜索,获取最新的网络信息,近期信息是7天,实时信息是1天")] + public async Task OnlineSearch([Description("搜索关键字")]string keyword, [Description("距离现在多久天")]int? daysAgo = null) { if (string.IsNullOrWhiteSpace(keyword)) { @@ -49,6 +49,22 @@ public class OnlineSearchTool : ISingletonDependency } }; + // 设置时间范围过滤 + if (daysAgo.HasValue) + { + requestBody.SearchFilter = new BaiduSearchFilter + { + Range = new BaiduSearchRange + { + PageTime = new BaiduSearchPageTime + { + Gte = $"now-{daysAgo.Value}d/d", + Lte = "now" + } + } + }; + } + var jsonContent = JsonSerializer.Serialize(requestBody, BaiduJsonContext.Default.BaiduSearchRequest); var content = new StringContent(jsonContent, Encoding.UTF8, "application/json"); @@ -135,6 +151,40 @@ public class BaiduSearchRequest { [JsonPropertyName("messages")] public List Messages { get; set; } = new(); + + [JsonPropertyName("search_filter")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public BaiduSearchFilter? SearchFilter { get; set; } +} + +/// +/// 百度搜索过滤器 +/// +public class BaiduSearchFilter +{ + [JsonPropertyName("range")] + public BaiduSearchRange? Range { get; set; } +} + +/// +/// 百度搜索范围 +/// +public class BaiduSearchRange +{ + [JsonPropertyName("page_time")] + public BaiduSearchPageTime? PageTime { get; set; } +} + +/// +/// 百度搜索时间范围 +/// +public class BaiduSearchPageTime +{ + [JsonPropertyName("gte")] + public string? Gte { get; set; } + + [JsonPropertyName("lte")] + public string? Lte { get; set; } } /// @@ -191,6 +241,9 @@ public class BaiduSearchReference [JsonSerializable(typeof(BaiduSearchRequest))] [JsonSerializable(typeof(BaiduSearchResponse))] +[JsonSerializable(typeof(BaiduSearchFilter))] +[JsonSerializable(typeof(BaiduSearchRange))] +[JsonSerializable(typeof(BaiduSearchPageTime))] [JsonSourceGenerationOptions(PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)] internal partial class BaiduJsonContext : JsonSerializerContext {