Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

SearchSelectRefinerDialog.cs 2.0 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
  1. namespace Search.Dialogs
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Threading.Tasks;
  7. using Microsoft.Bot.Builder.Dialogs;
  8. using Microsoft.Bot.Builder.Internals.Fibers;
  9. using Search.Models;
  10. [Serializable]
  11. public class SearchSelectRefinerDialog : IDialog<string>
  12. {
  13. protected readonly SearchQueryBuilder QueryBuilder;
  14. protected readonly IEnumerable<string> Refiners;
  15. protected readonly PromptStyler PromptStyler;
  16. public SearchSelectRefinerDialog(IEnumerable<string> refiners, SearchQueryBuilder queryBuilder = null, PromptStyler promptStyler = null)
  17. {
  18. SetField.NotNull(out this.Refiners, nameof(refiners), refiners);
  19. this.QueryBuilder = queryBuilder ?? new SearchQueryBuilder();
  20. this.PromptStyler = promptStyler;
  21. }
  22. public async Task StartAsync(IDialogContext context)
  23. {
  24. IEnumerable<string> unusedRefiners = this.Refiners;
  25. if (this.QueryBuilder != null)
  26. {
  27. unusedRefiners = unusedRefiners.Except(this.QueryBuilder.Refinements.Keys, StringComparer.OrdinalIgnoreCase);
  28. }
  29. if (unusedRefiners.Any())
  30. {
  31. var promptOptions = new CancelablePromptOptions<string>("What do you want to refine by?", cancelPrompt: "Type 'cancel' if you changed your mind.", options: unusedRefiners.ToList(), promptStyler: this.PromptStyler);
  32. CancelablePromptChoice<string>.Choice(context, this.ReturnSelection, promptOptions);
  33. }
  34. else
  35. {
  36. await context.PostAsync("Oops! You used all the available refiners and you cannot refine the results anymore.");
  37. context.Done<string>(null);
  38. }
  39. }
  40. protected virtual async Task ReturnSelection(IDialogContext context, IAwaitable<string> input)
  41. {
  42. var selection = await input;
  43. context.Done(selection);
  44. }
  45. }
  46. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...