1
votes

I added multi turn prompt to Qna maker. It renders the hyperlinks as buttons in QnAmaker but not on webchat. Is there a way to render them on webchat channel?

Note: I found a nodejs solution to this problem but I am looking for python way.

Here is my current code:

from botbuilder.ai.qna import QnAMaker, QnAMakerEndpoint
from botbuilder.core import ActivityHandler, MessageFactory, TurnContext
from botbuilder.schema import ChannelAccount

from config import DefaultConfig


class QnABot(ActivityHandler):
    def __init__(self, config: DefaultConfig):
        self.qna_maker = QnAMaker(
            QnAMakerEndpoint(
                knowledge_base_id=config.QNA_KNOWLEDGEBASE_ID,
                endpoint_key=config.QNA_ENDPOINT_KEY,
                host=config.QNA_ENDPOINT_HOST,
            )
        )

    async def on_members_added_activity(
        self, members_added: [ChannelAccount], turn_context: TurnContext
    ):
        for member in members_added:
            if member.id != turn_context.activity.recipient.id:
                await turn_context.send_activity(
                    "Hi I am your Engineering Bot! Ask me a question and I will try "
                    "to answer it."
                )

    async def on_message_activity(self, turn_context: TurnContext):
        # The actual call to the QnA Maker service.
        response = await self.qna_maker.get_answers(turn_context)
        if response and len(response) > 0:
            await turn_context.send_activity(MessageFactory.text(response[0].answer))
        else:
            await turn_context.send_activity("No QnA Maker answers were found.")

Thanks!!

1
Update your question with link to the nodejs solution you found. It might help someone to understand. Also, it should not be too difficult to try to re-write the solution that you found in python.Amol

1 Answers

0
votes

The Bot Framework doesn't currently have a working 'Multi-Turn QnA' sample in Python yet. There is a sample being worked on here:

https://github.com/microsoft/BotBuilder-Samples/tree/trboehre/python-49.qnamaker-all-features/samples/python/49.qnamaker-all-features

As the Python SDK is being actively worked on, it's possible that the library here doesn't have the right methods to return whether or not a question has a follow up prompt (aka multi-turn). Keep an eye on the Python SDK for further work!