8000 Allow requests module as QnAMaker's HTTP client by Zerryth · Pull Request #1369 · microsoft/botbuilder-python · GitHub
[go: up one dir, main page]

Skip to content

Allow requests module as QnAMaker's HTTP client #1369

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

Merged
merged 4 commits into from
Aug 28, 2020
Merged

Conversation

Zerryth
Copy link
Contributor
@Zerryth Zerryth commented Aug 27, 2020

Fixes #1187

Description

Properly allow requests to be made and consumed using Python's built-in requests library.

This will allow the option to use an HTTP client that isn't from aiohttp, which may be a sought out option for frameworks that don't wrap their requests in a running "ProactorEventLoop" that's necessary for aiohttp.ClientSession's to work.

For example, using the Quart 13.core-bot sample, it can properly call QnAMaker service with just the following
app.py

import requests

QNAMAKER = QnAMaker(
    endpoint=QnAMakerEndpoint(
        knowledge_base_id=APP.config["QNA_KNOWLEDGEBASE_ID"],
        endpoint_key=APP.config["QNA_ENDPOINT_KEY"],
        host=APP.config["QNA_ENDPOINT_HOST"],
    ),
    http_client=requests
)

Specific Changes

  • Configures the request to QnAMaker to the proper shape for the given HTTP client, whether it be aiohttp or requests-based in generate_answer_utils.py and http_request_utils.py
  • HttpRequestUtils.execute_http_request method return type goes from aiohttp.ClientResponse -> Any, given that different clients can be passed in to make requests, which return different shapes
  • OpenQnAMaker._http_client type from aiohttp.ClientSession to Any
    • Note: we could create an interface instead, I suppose, instead of "Any" type with the requirement that it needs to have a post method, however I'm not sure if this is necessary or not, given that most do (but who knows!)

@Zerryth Zerryth marked this pull request as ready for review August 28, 2020 00:05
@Zerryth Zerryth requested a review from axelsrz August 28, 2020 00:05
@axelsrz axelsrz merged commit c1e98de into main Aug 28, 2020
@axelsrz axelsrz deleted the Zerryth/qna-requests branch August 28, 2020 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Timeout context manager should be used inside a task - botbuilder.ai.qna - qnaMaker.get_answers
2 participants
0