mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-09-27 01:53:36 +00:00
Allowed restricting the web search to the past week
This commit is contained in:
parent
91de164d1c
commit
c17d726814
@ -94,6 +94,7 @@ public sealed class WebSearchTool(IEnumerable<IWebSearchBackend> backends, WebPa
|
||||
private const string LIMIT_ARGUMENT = "limit";
|
||||
|
||||
private const string TIME_RANGE_DAY = "day";
|
||||
private const string TIME_RANGE_WEEK = "week";
|
||||
private const string TIME_RANGE_MONTH = "month";
|
||||
private const string TIME_RANGE_YEAR = "year";
|
||||
|
||||
@ -101,11 +102,14 @@ public sealed class WebSearchTool(IEnumerable<IWebSearchBackend> backends, WebPa
|
||||
/// The time ranges a search can be restricted to.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Only those which every service with a time filter understands: SearXNG documents day, month,
|
||||
/// and year, while Tavily knows a week as well. The schema offers exactly these and the reader
|
||||
/// checks against them, so the two cannot drift apart.
|
||||
/// Those which both services with a time filter, SearXNG and Tavily, understand and take as
|
||||
/// they are. Tavily documents all four. SearXNG's API documentation names no week, but its code accepts
|
||||
/// one -- read on 2026-09-24 in parse_time_range of searx/webadapter.py. A model asked about
|
||||
/// "this week" wants exactly that, and without it, it asks for a week again and again.<br/><br/>
|
||||
/// The schema offers exactly these and the reader checks against them, so the two cannot drift
|
||||
/// apart.
|
||||
/// </remarks>
|
||||
private static readonly string[] TIME_RANGES = [TIME_RANGE_DAY, TIME_RANGE_MONTH, TIME_RANGE_YEAR];
|
||||
private static readonly string[] TIME_RANGES = [TIME_RANGE_DAY, TIME_RANGE_WEEK, TIME_RANGE_MONTH, TIME_RANGE_YEAR];
|
||||
|
||||
/// <summary>
|
||||
/// How much of a wrongly passed argument an error message repeats back to the model.
|
||||
|
||||
@ -93,9 +93,22 @@ public sealed class WebSearchToolArgumentTests
|
||||
});
|
||||
}
|
||||
|
||||
[TestCase("day")]
|
||||
[TestCase("week")]
|
||||
[TestCase("month")]
|
||||
[TestCase("year")]
|
||||
public void EveryOfferedTimeRangeIsAccepted(string timeRange)
|
||||
{
|
||||
//
|
||||
// The week is the one a model asks for when the user says "this week". Both services with
|
||||
// a time filter understand it, and refusing it only made the model try it again and again.
|
||||
//
|
||||
Assert.That(WebSearchTool.ReadTimeRange(Arguments($$"""{"query":"weather","time_range":"{{timeRange}}"}""")), Is.EqualTo(timeRange));
|
||||
}
|
||||
|
||||
[TestCase("\"\"")]
|
||||
[TestCase("\"Day\"")]
|
||||
[TestCase("\"week\"")]
|
||||
[TestCase("\"decade\"")]
|
||||
[TestCase("5")]
|
||||
public void AWrongTimeRangeIsRefusedWithTheValuesThatWouldDo(string value)
|
||||
{
|
||||
@ -103,7 +116,7 @@ public sealed class WebSearchToolArgumentTests
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(message, Does.Contain("'time_range'").And.Contain("one of day, month, year"));
|
||||
Assert.That(message, Does.Contain("'time_range'").And.Contain("one of day, week, month, year"));
|
||||
Assert.That(message, Does.Contain($"but was {value}."));
|
||||
Assert.That(message, Does.Contain("Leave it out"));
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user