Skip to content

Commit 017cff4

Browse files
Copilotjongalloway
andcommitted
refactor: extract hard-coded keywords and tool names into constants in ToolSelector
Co-authored-by: jongalloway <[email protected]>
1 parent 0753929 commit 017cff4

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

src/NLWebNet/Services/ToolSelector.cs

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,24 @@ public class ToolSelector : IToolSelector
1212
private readonly ILogger<ToolSelector> _logger;
1313
private readonly NLWebOptions _options;
1414

15+
/// <summary>
16+
/// Constants for tool names and associated keywords
17+
/// </summary>
18+
private static class ToolConstants
19+
{
20+
// Tool names
21+
public const string SearchTool = "search";
22+
public const string CompareTool = "compare";
23+
public const string DetailsTool = "details";
24+
public const string EnsembleTool = "ensemble";
25+
26+
// Keywords for each tool
27+
public static readonly string[] SearchKeywords = { "search", "find", "look for", "locate" };
28+
public static readonly string[] CompareKeywords = { "compare", "difference", "versus", "vs", "contrast" };
29+
public static readonly string[] DetailsKeywords = { "details", "information about", "tell me about", "describe" };
30+
public static readonly string[] EnsembleKeywords = { "recommend", "suggest", "what should", "ensemble", "set of" };
31+
}
32+
1533
public ToolSelector(ILogger<ToolSelector> logger, IOptions<NLWebOptions> options)
1634
{
1735
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
@@ -76,31 +94,31 @@ public bool ShouldSelectTool(NLWebRequest request)
7694
// Basic keyword-based intent detection
7795
// In production, this would use ML models or more sophisticated analysis
7896

79-
if (ContainsKeywords(queryLower, "search", "find", "look for", "locate"))
97+
if (ContainsKeywords(queryLower, ToolConstants.SearchKeywords))
8098
{
81-
return Task.FromResult<string?>("search");
99+
return Task.FromResult<string?>(ToolConstants.SearchTool);
82100
}
83101

84-
if (ContainsKeywords(queryLower, "compare", "difference", "versus", "vs", "contrast"))
102+
if (ContainsKeywords(queryLower, ToolConstants.CompareKeywords))
85103
{
86-
return Task.FromResult<string?>("compare");
104+
return Task.FromResult<string?>(ToolConstants.CompareTool);
87105
}
88106

89-
if (ContainsKeywords(queryLower, "details", "information about", "tell me about", "describe"))
107+
if (ContainsKeywords(queryLower, ToolConstants.DetailsKeywords))
90108
{
91-
return Task.FromResult<string?>("details");
109+
return Task.FromResult<string?>(ToolConstants.DetailsTool);
92110
}
93111

94-
if (ContainsKeywords(queryLower, "recommend", "suggest", "what should", "ensemble", "set of"))
112+
if (ContainsKeywords(queryLower, ToolConstants.EnsembleKeywords))
95113
{
96-
return Task.FromResult<string?>("ensemble");
114+
return Task.FromResult<string?>(ToolConstants.EnsembleTool);
97115
}
98116

99117
// Default to search tool for general queries
100-
return Task.FromResult<string?>("search");
118+
return Task.FromResult<string?>(ToolConstants.SearchTool);
101119
}
102120

103-
private static bool ContainsKeywords(string text, params string[] keywords)
121+
private static bool ContainsKeywords(string text, string[] keywords)
104122
{
105123
return keywords.Any(keyword => text.Contains(keyword));
106124
}

0 commit comments

Comments
 (0)