Skip to content

Commit

Permalink
Merge branch 'PYTHON' of https://github.com/microsoft/teams-ai into P…
Browse files Browse the repository at this point in the history
…YTHON
  • Loading branch information
aacebo committed Feb 26, 2024
2 parents 9a3954b + 63ad30e commit d4b72fe
Show file tree
Hide file tree
Showing 17 changed files with 2,510 additions and 79 deletions.
26 changes: 21 additions & 5 deletions python/packages/ai/teams/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from aiohttp.web import Request, Response
from botbuilder.core import Bot, TurnContext
from botbuilder.integration.aiohttp import CloudAdapter
from botbuilder.schema import ActivityTypes
from botbuilder.schema.teams import (
FileConsentCardResponse,
Expand All @@ -32,6 +31,7 @@
from .route import Route, RouteHandler
from .state import TurnState
from .task_modules import TaskModules
from .teams_adapter import TeamsAdapter
from .typing import Typing


Expand All @@ -53,7 +53,7 @@ class Application(Bot):
_ai: Optional[AI]
_adaptive_card: AdaptiveCards
_options: ApplicationOptions
_adapter: Optional[CloudAdapter] = None
_adapter: Optional[TeamsAdapter] = None
_before_turn: List[RouteHandler] = []
_after_turn: List[RouteHandler] = []
_routes: List[Route] = []
Expand All @@ -78,16 +78,32 @@ def __init__(self, options: ApplicationOptions = ApplicationOptions()) -> None:
self._task_modules = TaskModules(self._routes, options.task_modules.task_data_filter)
self._meetings = Meetings(self._routes)

if options.long_running_messages and (not options.auth or not options.bot_app_id):
if options.long_running_messages and (not options.adapter or not options.bot_app_id):
raise ApplicationError(
"""
The `ApplicationOptions.long_running_messages` property is unavailable because
no adapter or `bot_app_id` was configured.
"""
)

if options.auth:
self._adapter = CloudAdapter(options.auth)
if options.adapter:
self._adapter = options.adapter

@property
def adapter(self) -> TeamsAdapter:
"""
The bot's adapter.
"""

if not self._adapter:
raise ApplicationError(
"""
The Application.adapter property is unavailable because it was
not configured when creating the Application.
"""
)

return self._adapter

@property
def ai(self) -> AI:
Expand Down
8 changes: 3 additions & 5 deletions python/packages/ai/teams/app_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,18 @@
from typing import Optional

from botbuilder.core import Storage
from botbuilder.integration.aiohttp import ConfigurationBotFrameworkAuthentication

from .adaptive_cards import AdaptiveCardsOptions
from .ai import AIOptions
from .task_modules import TaskModulesOptions
from .teams_adapter import TeamsAdapter


@dataclass
class ApplicationOptions:
auth: Optional[ConfigurationBotFrameworkAuthentication] = None
adapter: Optional[TeamsAdapter] = None
"""
Optional. Bot auth settings.
If using the `long_running_messages` option or calling the `continue_conversation_async`
method, this property is required.
Optional. Options used to initialize your `BotAdapter`
"""

bot_app_id: str = ""
Expand Down
10 changes: 10 additions & 0 deletions python/samples/01.messaging.a.echoBot/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Auto generated during deployment
requirements.txt

.env

# Teams Toolkit
env/.env.*.user
env/.env.local
appPackage/build
.deployment
14 changes: 0 additions & 14 deletions python/samples/01.messaging.a.echoBot/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,6 @@
},
"internalConsoleOptions": "neverOpen"
},
{
"name": "Attach to Local Service",
"type": "node",
"request": "attach",
"port": 9239,
"restart": true,
"presentation": {
"group": "all",
"hidden": true
},
"internalConsoleOptions": "neverOpen"
},
{
"name": "Start",
"type": "python",
Expand All @@ -76,7 +64,6 @@
"name": "Debug (Edge)",
"configurations": [
"Launch App (Edge)",
"Attach to Local Service",
"Start"
],
"preLaunchTask": "Start Teams App Locally",
Expand All @@ -90,7 +77,6 @@
"name": "Debug (Chrome)",
"configurations": [
"Launch App (Chrome)",
"Attach to Local Service",
"Start"
],
"preLaunchTask": "Start Teams App Locally",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
"python.terminal.activateEnvironment": true,
"python.terminal.activateEnvInCurrentTerminal": true,
"python.analysis.typeCheckingMode": "basic",
"python.defaultInterpreterPath": "${workspaceFolder}/.venv"
}
9 changes: 9 additions & 0 deletions python/samples/01.messaging.a.echoBot/.webappignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.venv/
.vscode/
.env
env/
README.md
teamsapp.yml
teamsapp.local.yml
__pycache__
.mypy_cache
5 changes: 4 additions & 1 deletion python/samples/01.messaging.a.echoBot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ This sample shows how to incorporate basic conversational flow into a Teams appl

- Install [Python](https://www.python.org/downloads/) (>= 3.8)
- Install [Python VSCode Extension](https://marketplace.visualstudio.com/items?itemName=ms-python.python)
- Install [Poetry](https://python-poetry.org/docs/#installation)
- Install [Teams Toolkit VSCode Plugin](https://marketplace.visualstudio.com/items?itemName=TeamsDevApp.ms-teams-vscode-extension)

## Run

> To run samples we encourage the use of the [Teams Toolkit VSCode Plugin](https://marketplace.visualstudio.com/items?itemName=TeamsDevApp.ms-teams-vscode-extension), to run the project using `Teams Toolkit` click the `Debug` button and select a profile.
> To run samples we encourage the use of the [Teams Toolkit VSCode Plugin](https://marketplace.visualstudio.com/items?itemName=TeamsDevApp.ms-teams-vscode-extension), to run the project using `Teams Toolkit`:
1. Use `Python: Create Environment` command to create a virtual environment. Python extension will install dependencies defined in `pyproject.toml` automatically.
2. Click the `Debug` button and select a profile.
![Teams Toolkit VSCode](./assets/screenshot_1.png)
![Teams Toolkit VSCode](./assets/screenshot_2.png)

Expand Down
28 changes: 13 additions & 15 deletions python/samples/01.messaging.a.echoBot/infra/azure.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -11,53 +11,51 @@ param botAadAppClientId string
param botAadAppClientSecret string

param webAppSKU string
param linuxFxVersion string

@maxLength(42)
param botDisplayName string

param serverfarmsName string = resourceBaseName
param webAppName string = resourceBaseName
param location string = resourceGroup().location
param pythonVersion string = linuxFxVersion

// Compute resources for your Web App
resource serverfarm 'Microsoft.Web/serverfarms@2021-02-01' = {
kind: 'app'
kind: 'app,linux'
location: location
name: serverfarmsName
sku: {
name: webAppSKU
}
properties:{
reserved: true
}
}

// Web App that hosts your bot
resource webApp 'Microsoft.Web/sites@2021-02-01' = {
kind: 'app'
kind: 'app,linux'
location: location
name: webAppName
properties: {
serverFarmId: serverfarm.id
httpsOnly: true
siteConfig: {
alwaysOn: true
appCommandLine: 'gunicorn --bind=0.0.0.0 --timeout 600 api:api'
linuxFxVersion: pythonVersion
appSettings: [
{
name: 'WEBSITE_RUN_FROM_PACKAGE'
value: '1' // Run Azure APP Service from a package file
}
{
name: 'WEBSITE_NODE_DEFAULT_VERSION'
value: '~16' // Set NodeJS version to 16.x for your site
}
{
name: 'RUNNING_ON_AZURE'
value: '1'
name: 'SCM_DO_BUILD_DURING_DEPLOYMENT'
value: 'true'
}
{
name: 'MicrosoftAppId'
name: 'BOT_ID'
value: botAadAppClientId
}
{
name: 'MicrosoftAppPassword'
name: 'BOT_PASSWORD'
value: botAadAppClientSecret
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
},
"botDisplayName": {
"value": "EchoBotInfra"
},
"linuxFxVersion": {
"value": "PYTHON|3.11"
}
}
}
Loading

0 comments on commit d4b72fe

Please sign in to comment.