Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Can pass QnAMakerOptions into both constructor and QnAMaker.GetAnswersAsync() w/o unintentional overwrite #1288

Merged
merged 5 commits into from
Jan 30, 2019

Conversation

Zerryth
Copy link
Contributor

@Zerryth Zerryth commented Jan 16, 2019

Fixes #1239, #1286

Description

  • Can pass QnAMakerOptions into QnAMaker constructor and QnAMaker.GetAnswersAsync() without accidentally overwriting the options passed into the constructor
  • Refactored code to make changes similar to the ones in Zerryth/qna parity botbuilder-js#704 that cleans up QnAMaker readability on the js side, to keep with parity
  • Replaced repeated code in constructor with ValidateOptions() (DRY)

Specific Changes

  • Can pass QnAMakerOptions into QnAMaker constructor and QnAMaker.GetAnswersAsync() without accidentally overwriting the options passed into the constructor

    • Added private method HydrateOptions() to combine options passed into the constructor and GetAnswersAsync() call
    • for example if I specified in the constructor ScoreThreshold = 0.5F and in GetAnswersAsync() I provide an addition option that I want Top = 3 results, your options in the request to the QnAMaker service will specify both ScoreThreshold = 0.5F and Top = 3
    • previously the behavior is that it would overwrite constructor-passed ScoreThreshold = 0.5F to default ScoreThreshold = 0.3F and take only the GetAnswersAsync() option
  • Exercised clean coding practice of abstracting lower-level detailed processes into helper functions to make code more expressive/readable. See below for functions

    • GetAnswersAsync(): HydrateOptions(), QueryQnaServiceAsync(), EmitTraceInfoAsync()
      • QueryQnaServiceAsync(): BuildRequest(), FormatQnaResultAsync()
        • BuildRequest(): SetHeaders()

@coveralls
Copy link
Collaborator

coveralls commented Jan 16, 2019

Pull Request Test Coverage Report for Build 48056

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 113 unchanged lines in 8 files lost coverage.
  • Overall coverage increased (+13.3%) to 69.112%

Files with Coverage Reduction New Missed Lines %
/libraries/Microsoft.Bot.Builder/Integration/BotFrameworkOptions.cs 3 63.64%
/libraries/Microsoft.Bot.Builder/TranscriptLoggerMiddleware.cs 4 95.51%
/libraries/Microsoft.Bot.Builder.Dialogs/Choices/ChoiceRecognizers.cs 4 95.35%
/libraries/Microsoft.Bot.Builder.AI.QnA/QnAMaker.cs 6 96.57%
/libraries/Microsoft.Bot.Builder.Dialogs/Choices/Find.cs 7 90.57%
/libraries/Microsoft.Bot.Builder.Dialogs/Choices/ChoiceFactory.cs 18 76.03%
/libraries/Microsoft.Bot.Builder/BotFrameworkAdapter.cs 23 15.59%
/libraries/Microsoft.Bot.Builder.Dialogs/Prompts/OAuthPrompt.cs 48 0.0%
Totals Coverage Status
Change from base Build 46954: 13.3%
Covered Lines: 3477
Relevant Lines: 5031

💛 - Coveralls

@Zerryth
Copy link
Contributor Author

Zerryth commented Jan 16, 2019

Copy link
Contributor

@cleemullins cleemullins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great to me, but I would like a 2nd set of eyes (John? Steven?) before merging it in. I'm still a bit out-of-it from recent medical events, so a 2nd detailed review is good.

@stevengum stevengum added the 4.3 February 14, 2019 Release label Jan 25, 2019
libraries/Microsoft.Bot.Builder.AI.QnA/QnAMaker.cs Outdated Show resolved Hide resolved
libraries/Microsoft.Bot.Builder.AI.QnA/QnAMaker.cs Outdated Show resolved Hide resolved
libraries/Microsoft.Bot.Builder.AI.QnA/QnAMaker.cs Outdated Show resolved Hide resolved
libraries/Microsoft.Bot.Builder.AI.QnA/QnAMaker.cs Outdated Show resolved Hide resolved
@Zerryth
Copy link
Contributor Author

Zerryth commented Jan 26, 2019

@stevengum I think you meant put the if-statement conditions into HydrateOptions() instead of ValidateOptions() :)

In any case, obliterated and removed helpers HasTopQueryOption(), HasTopQueryOption(), HasStrictFiltersQueryOption(), and HasMetadataBoostQueryOption()

And if-statement conditions are in HydrateOptions()

@Zerryth
Copy link
Contributor Author

Zerryth commented Jan 28, 2019

@stevengum post meeting ping! :)

Made changes on the edits you suggested. Please review

@stevengum
Copy link
Member

Just waiting on @Zerryth to fix the breaking changes and not return a null value.

@Zerryth
Copy link
Contributor Author

Zerryth commented Jan 29, 2019

Awesome, thank you John & Steven.

Just ran the code I had locally without making any changes to the commit and 7 of 22 tests are failing now (why me???)

Once I get passed this shenanigans, I'll work on the param name/error throwing :)

libraries/Microsoft.Bot.Builder.AI.QnA/QnAMaker.cs Outdated Show resolved Hide resolved
@cleemullins cleemullins dismissed johnataylor’s stale review January 30, 2019 20:30

Feedback addressed. NEeding to merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.3 February 14, 2019 Release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants