Skip to content

Commit

Permalink
Workaround to use Q2A in API
Browse files Browse the repository at this point in the history
  • Loading branch information
ButterscotchV committed Sep 24, 2024
1 parent 23133b2 commit d7cae26
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 5 additions & 1 deletion BingusApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ string GetConfig(string fileName)

// Load FAQ
app.Services.GetRequiredService<FaqHandler>()
.AddItems(app.Services.GetRequiredService<FaqConfig>().QaEntryEnumerator());
.AddItems(
app.Services.GetService<BingusConfig>()?.UseQ2A == true
? app.Services.GetRequiredService<FaqConfig>().AnswerEntryEnumerator()
: app.Services.GetRequiredService<FaqConfig>().QaEntryEnumerator()
);

app.Run();
14 changes: 12 additions & 2 deletions BingusLib/FaqHandling/FaqConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public record FaqConfigEntry
public string Answer { get; set; } = "";

[JsonPropertyName("matched_questions")]
public List<string> Questions { get; set; } = new();
public List<string> Questions { get; set; } = [];

public FaqConfigEntry() { }

Expand All @@ -33,7 +33,7 @@ public FaqConfigEntry(string answer, IEnumerable<string> questions)
}

[JsonPropertyName("faqs")]
public List<FaqConfigEntry> FaqEntries { get; set; } = new();
public List<FaqConfigEntry> FaqEntries { get; set; } = [];

public FaqConfigEntry? GetAnswerEntry(string answer)
{
Expand All @@ -56,5 +56,15 @@ public FaqConfigEntry(string answer, IEnumerable<string> questions)
}
}
}

public IEnumerable<(string title, string question, string answer)> AnswerEntryEnumerator()
{
foreach (var entry in FaqEntries)
{
// If we want to use an example question:
// entry.Questions.FirstOrDefault(entry.Title)
yield return (entry.Title, entry.Answer, entry.Answer);
}
}
}
}

0 comments on commit d7cae26

Please sign in to comment.