Skip to content

Commit

Permalink
Merge branch 'main' into cg/gpt-tokenizer
Browse files Browse the repository at this point in the history
  • Loading branch information
corinagum authored Feb 28, 2024
2 parents 1750064 + 86192b5 commit 212b5c8
Show file tree
Hide file tree
Showing 23 changed files with 379 additions and 291 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ jobs:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Setup Python ${{ env.python-version }}
uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0
with:
python-version: ${{ env.python-version }}
- name: Install Dependencies
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/python-build-test-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ jobs:
permissions:
contents: read
steps:
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0
with:
python-version: ${{ matrix.python-version }}
- name: Install Dependencies
Expand All @@ -51,6 +51,6 @@ jobs:
run: |
python scripts/lint.py
- name: Harden Runner
uses: step-security/harden-runner@8ca2b8b2ece13480cda6dacd3511b49857a23c09 # v2.5.1
uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0
with:
egress-policy: audit
6 changes: 3 additions & 3 deletions .github/workflows/python-codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ jobs:
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Initialize CodeQL
uses: github/codeql-action/init@701f152f28d4350ad289a5e31435e9ab6169a7ca # v2.21.6
uses: github/codeql-action/init@47b3d888fe66b639e431abf22ebca059152f1eea # v3.24.5
with:
languages: python
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@701f152f28d4350ad289a5e31435e9ab6169a7ca # v2.21.6
uses: github/codeql-action/analyze@47b3d888fe66b639e431abf22ebca059152f1eea # v3.24.5
with:
category: "/language:python"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
|---------------|-----------------------|
| Javascript | [![Javascript Build Status](https://dev.azure.com/DomoreexpGithub/Github_Pipelines/_apis/build/status%2Fteams-ai%2Fmicrosoft.teams-ai.javascript?branchName=main)](https://dev.azure.com/DomoreexpGithub/Github_Pipelines/_build/latest?definitionId=5&branchName=main) |
| C# | [![C# Build Status](https://dev.azure.com/DomoreexpGithub/Github_Pipelines/_apis/build/status%2Fteams-ai%2Fmicrosoft.teams-ai.dotnet?branchName=main)](https://dev.azure.com/DomoreexpGithub/Github_Pipelines/_build/latest?definitionId=4&branchName=main) |
| Python | [![Build Status](https://dev.azure.com/DomoreexpGithub/Github_Pipelines/_apis/build/status%2Fteams-ai%2Fmicrosoft.teams-ai.python?branchName=main)](https://dev.azure.com/DomoreexpGithub/Github_Pipelines/_build/latest?definitionId=10&branchName=main) |

Welcome to the Teams AI Library! This SDK is specifically designed to assist you in creating bots capable of interacting with Teams and Microsoft 365 applications. It is constructed using the [Bot Framework SDK](https://github.com/microsoft/botbuilder-js) as its foundation, simplifying the process of developing bots that interact with Teams' artificial intelligence capabilities.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.21.1" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.57.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="SharpToken" Version="1.2.15" />
<PackageReference Include="SharpToken" Version="1.2.17" />
<PackageReference Include="System.Text.Json" Version="7.0.4" />
</ItemGroup>

Expand Down
3 changes: 3 additions & 0 deletions js/packages/teams-ai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"teams",
"ai"
],
"engines": {
"node": "^16 || ^18"
},
"bugs": {
"url": "https://github.com/microsoft/teams-ai/issues"
},
Expand Down
67 changes: 67 additions & 0 deletions pipelines/python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
trigger:
batch: true
branches:
include:
- main
paths:
include:
- python
- pipelines/python.yml

pool:
vmImage: 'ubuntu-latest'

strategy:
matrix:
Python38:
python.version: '3.8'
Python39:
python.version: '3.9'
Python310:
python.version: '3.10'

steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '$(python.version)'
displayName: 'Use Python $(python.version)'

- script: |
python -m pip install --upgrade pip
pip install poetry
python scripts/install.py
displayName: 'Install Dependencies'
workingDirectory: 'python'

- script: |
python scripts/check.py
displayName: 'Check'
workingDirectory: 'python'

- script: |
python scripts/build.py
displayName: 'Build'
workingDirectory: 'python'

- script: |
python scripts/test.py
displayName: 'Test'
workingDirectory: 'python'

- script: |
python scripts/lint.py
displayName: 'Lint'
workingDirectory: 'python'

- task: CopyFiles@2
inputs:
sourceFolder: '$(Build.SourcesDirectory)'
contents: |
python/packages/ai/dist/*
targetFolder: $(Build.ArtifactStagingDirectory)

- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact'
inputs:
PathToPublish: '$(Build.ArtifactStagingDirectory)/python/packages/ai'
ArtifactName: Packages
21 changes: 21 additions & 0 deletions python/packages/ai/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Microsoft Corporation. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
62 changes: 7 additions & 55 deletions python/packages/ai/README.md
Original file line number Diff line number Diff line change
@@ -1,61 +1,13 @@
# Teams AI
# Teams AI Library

SDK focused on building AI based applications for Microsoft Teams.
Welcome to the Teams AI Library Python package!

## Development
This SDK is specifically designed to assist you in creating bots capable of interacting with Teams and Microsoft 365 applications. It is constructed using the [Bot Framework SDK](https://github.com/microsoft/botbuilder-python) as its foundation, simplifying the process of developing bots that interact with Teams' artificial intelligence capabilities. See the [Teams AI repo README.md](https://github.com/microsoft/teams-ai), for general information.

### Prerequisites
## Getting Started

[Install Poetry](https://python-poetry.org/docs/)
To get started, take a look at the [getting started docs](https://github.com/microsoft/teams-ai/blob/main/getting-started/README.md).

```bash
$: pip install poetry
```
## Migration

### Install Dependencies

```bash
$: poetry install
```

### Build

```bash
$: poetry build
```

### Test

```bash
$: poetry run test
```

### Lint

```bash
$: poetry run lint
```

## Format

```bash
$: poetry run fmt
```

## Clean

```bash
$: poetry run clean
```

### Install Local

```bash
$: pip install .
```

### Publish

```bash
$: poetry publish
```
If you're migrating an existing project, switching to add on the Teams AI Library layer is quick and simple. See the [migration guide](https://github.com/microsoft/teams-ai/blob/main/getting-started/MIGRATION/PYTHON.md).
2 changes: 1 addition & 1 deletion python/packages/ai/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "teams-ai"
version = "0.0.0"
version = "1.0.0.rc1"
description = "SDK focused on building AI based applications for Microsoft Teams."
authors = ["Microsoft <teams@microsoft.com>"]
readme = "README.md"
Expand Down
2 changes: 2 additions & 0 deletions python/packages/ai/teams/adaptive_cards/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
from .adaptive_cards_options import AdaptiveCardsOptions
from .adaptive_cards_search_params import AdaptiveCardsSearchParams
from .adaptive_cards_search_result import AdaptiveCardsSearchResult

__all__ = ["AdaptiveCardsOptions", "AdaptiveCardsSearchParams", "AdaptiveCardsSearchResult"]
42 changes: 22 additions & 20 deletions python/packages/ai/teams/adaptive_cards/adaptive_cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from __future__ import annotations

import re
from typing import Awaitable, Callable, List, Pattern, Union
from typing import Awaitable, Callable, Generic, List, Pattern, TypeVar, Union

from botbuilder.core import TurnContext
from botbuilder.schema import (
Expand All @@ -27,8 +27,10 @@
ACTION_EXECUTE_TYPE = "Action.Execute"
SEARCH_INVOKE_NAME = "application/search"

StateT = TypeVar("StateT", bound=TurnState)

class AdaptiveCards:

class AdaptiveCards(Generic[StateT]):
_route_registry: List[Route]
_action_submit_filter: str

Expand All @@ -39,8 +41,8 @@ def __init__(self, route_registry: List[Route], action_submit_filter: str) -> No
def action_execute(
self, verb: Union[str, Pattern[str], Callable[[TurnContext], bool]]
) -> Callable[
[Callable[[TurnContext, TurnState, dict], Awaitable[Union[str, dict]]]],
Callable[[TurnContext, TurnState, dict], Awaitable[Union[str, dict]]],
[Callable[[TurnContext, StateT, dict], Awaitable[Union[str, dict]]]],
Callable[[TurnContext, StateT, dict], Awaitable[Union[str, dict]]],
]:
"""
Adds a route for handling Adaptive Card Action.Execute events.
Expand Down Expand Up @@ -84,9 +86,9 @@ def __selector__(context: TurnContext) -> bool:
return False

def __call__(
func: Callable[[TurnContext, TurnState, dict], Awaitable[Union[str, dict]]]
) -> Callable[[TurnContext, TurnState, dict], Awaitable[Union[str, dict]]]:
async def __handler__(context: TurnContext, state: TurnState) -> bool:
func: Callable[[TurnContext, StateT, dict], Awaitable[Union[str, dict]]]
) -> Callable[[TurnContext, StateT, dict], Awaitable[Union[str, dict]]]:
async def __handler__(context: TurnContext, state: StateT) -> bool:
result = await func(context, state, context.activity.value["action"]["data"])
if context.turn_state.get(ActivityTypes.invoke_response) is None:
if isinstance(result, str):
Expand All @@ -108,16 +110,16 @@ async def __handler__(context: TurnContext, state: TurnState) -> bool:
)
return True

self._route_registry.append(Route(__selector__, __handler__))
self._route_registry.append(Route[StateT](__selector__, __handler__))
return func

return __call__

def action_submit(
self, verb: Union[str, Pattern[str], Callable[[TurnContext], bool]]
) -> Callable[
[Callable[[TurnContext, TurnState, dict], Awaitable[None]]],
Callable[[TurnContext, TurnState, dict], Awaitable[None]],
[Callable[[TurnContext, StateT, dict], Awaitable[None]]],
Callable[[TurnContext, StateT, dict], Awaitable[None]],
]:
"""
Adds a route for handling Adaptive Card Action.Submit events.
Expand Down Expand Up @@ -160,13 +162,13 @@ def __selector__(context: TurnContext) -> bool:
return False

def __call__(
func: Callable[[TurnContext, TurnState, dict], Awaitable[None]]
) -> Callable[[TurnContext, TurnState, dict], Awaitable[None]]:
async def __handler__(context: TurnContext, state: TurnState) -> bool:
func: Callable[[TurnContext, StateT, dict], Awaitable[None]]
) -> Callable[[TurnContext, StateT, dict], Awaitable[None]]:
async def __handler__(context: TurnContext, state: StateT) -> bool:
await func(context, state, context.activity.value)
return True

self._route_registry.append(Route(__selector__, __handler__))
self._route_registry.append(Route[StateT](__selector__, __handler__))
return func

return __call__
Expand All @@ -176,12 +178,12 @@ def search(
) -> Callable[
[
Callable[
[TurnContext, TurnState, Query[AdaptiveCardsSearchParams]],
[TurnContext, StateT, Query[AdaptiveCardsSearchParams]],
Awaitable[List[AdaptiveCardsSearchResult]],
]
],
Callable[
[TurnContext, TurnState, Query[AdaptiveCardsSearchParams]],
[TurnContext, StateT, Query[AdaptiveCardsSearchParams]],
Awaitable[List[AdaptiveCardsSearchResult]],
],
]:
Expand Down Expand Up @@ -227,14 +229,14 @@ def __selector__(context: TurnContext) -> bool:

def __call__(
func: Callable[
[TurnContext, TurnState, Query[AdaptiveCardsSearchParams]],
[TurnContext, StateT, Query[AdaptiveCardsSearchParams]],
Awaitable[List[AdaptiveCardsSearchResult]],
]
) -> Callable[
[TurnContext, TurnState, Query[AdaptiveCardsSearchParams]],
[TurnContext, StateT, Query[AdaptiveCardsSearchParams]],
Awaitable[List[AdaptiveCardsSearchResult]],
]:
async def __handler__(context: TurnContext, state: TurnState) -> bool:
async def __handler__(context: TurnContext, state: StateT) -> bool:
params = context.activity.value
# Flatten search parameters
query = Query[AdaptiveCardsSearchParams](
Expand Down Expand Up @@ -263,7 +265,7 @@ async def __handler__(context: TurnContext, state: TurnState) -> bool:
)
return True

self._route_registry.append(Route(__selector__, __handler__))
self._route_registry.append(Route[StateT](__selector__, __handler__))
return func

return __call__
Loading

0 comments on commit 212b5c8

Please sign in to comment.