-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Handle Q2A better in API * Fix typing * Add FaqDict for simple queries * Initialize Q2Q dictionary if in Q2A mode * Simplify FaqDict usage
- Loading branch information
1 parent
72f525a
commit c98a1cb
Showing
8 changed files
with
100 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
namespace BingusLib.FaqHandling | ||
{ | ||
public class FaqDict | ||
{ | ||
private readonly Dictionary<string, FaqEntry> _faqDict = []; | ||
|
||
public FaqDict(FaqConfig faqConfig) | ||
: this(faqConfig.QaEntryEnumerator()) { } | ||
|
||
public FaqDict(IEnumerable<(string title, string question, string answer)> tqaMapping) | ||
{ | ||
foreach (var (title, question, answer) in tqaMapping) | ||
{ | ||
_faqDict[CleanQuery(question)] = new FaqEntry() | ||
{ | ||
Title = title, | ||
Question = question, | ||
Answer = answer, | ||
}; | ||
} | ||
} | ||
|
||
private static string CleanQuery(string query) => query.Trim().ToLowerInvariant(); | ||
|
||
public FaqEntry? Search(string query) | ||
{ | ||
return _faqDict.TryGetValue(CleanQuery(query), out var entry) ? entry : null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using MathNet.Numerics.LinearAlgebra; | ||
|
||
namespace BingusLib.FaqHandling | ||
{ | ||
public record class FaqEntry | ||
{ | ||
public string Title { get; set; } = ""; | ||
public string Question { get; set; } = ""; | ||
public string Answer { get; set; } = ""; | ||
public Vector<float>? Vector { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters