microsoft / teams-ai

SDK focused on building AI based applications and extensions for Microsoft Teams and other Bot Framework channels
MIT License
359 stars 152 forks source link

[PY] feat: Twenty Questions #1577

Closed BMS-geodev closed 2 months ago

BMS-geodev commented 2 months ago

Linked issues

closes: #316

Details

A python implementation of the existing JS "Twenty Questions" sample bot. The bot leads the user through the twenty questions guessing game, with the user attempting to guess a secret word via successive guesses. Driven through the Teams toolkit, the sample launches a browser window where a instance of teams chat runs the bot locally. See screenshot for interaction.

Change details

Ported the code found in /js/samples/03.ai-concepts/a.twentyQuestions/... to Python, with usage of the existing Python implementation of things likeApplication, ActionPlanner, context, and so on.

code snippets: None.

screenshots: image

Attestation Checklist

Additional information

Feel free to add other relevant information below

BMS-geodev commented 2 months ago

@lilyydu addressed all your feeback, thank you!

Followed your idea to lace print statements into teams/app.py, and have a finding where I got stumped

here is the terminal feed:

turn_state_factory begin
======== Running on http://localhost:3978 ========
(Press CTRL+C to quit)
process begin
on_turn begin
_start_long_running_call begin
_on_turn begin
_on_turn start typing
_on_turn turn_state_factory
_on_activity begin
_on_activity []
_on_activity []

I hit the end of the thread in _on_activity()

    async def _on_activity(self, context: TurnContext, state: StateT) -> Tuple[bool, int]:
        matches = 0
        print("_on_activity begin")
        # ensure we handle invokes first
        routes = filter(lambda r: not r.is_invoke and r.selector(context), self._routes)
        print(f"_on_activity {list(routes)}")
        invoke_routes = filter(lambda r: r.is_invoke and r.selector(context), self._routes)
        print(f"_on_activity {list(invoke_routes)}")
        for route in invoke_routes:
            print("_on_activity invoke_routes")
            if route.selector(context):
                matches = matches + 1

                if not await route.handler(context, state):
                    return False, matches

        for route in routes:
            print("_on_activity routes")
            if route.selector(context):
                matches = matches + 1

                if not await route.handler(context, state):
                    return False, matches

        return True, matches

specifically it seems like routes, and invoke_routes are not finding any result from the filter.

what do you think?

I stopped logging to get your read, had to stop somewhere hah

BMS-geodev commented 2 months ago

@microsoft-github-policy-service agree company="Awarity Inc."