teams-ai 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (168) hide show
  1. teams_ai-1.0.0/LICENSE +21 -0
  2. teams_ai-1.0.0/PKG-INFO +44 -0
  3. teams_ai-1.0.0/README.md +13 -0
  4. teams_ai-1.0.0/pyproject.toml +71 -0
  5. teams_ai-1.0.0/teams/__init__.py +25 -0
  6. teams_ai-1.0.0/teams/activity_type.py +47 -0
  7. teams_ai-1.0.0/teams/adaptive_cards/__init__.py +9 -0
  8. teams_ai-1.0.0/teams/adaptive_cards/adaptive_cards.py +271 -0
  9. teams_ai-1.0.0/teams/adaptive_cards/adaptive_cards_options.py +18 -0
  10. teams_ai-1.0.0/teams/adaptive_cards/adaptive_cards_search_params.py +14 -0
  11. teams_ai-1.0.0/teams/adaptive_cards/adaptive_cards_search_result.py +14 -0
  12. teams_ai-1.0.0/teams/ai/__init__.py +9 -0
  13. teams_ai-1.0.0/teams/ai/actions/__init__.py +10 -0
  14. teams_ai-1.0.0/teams/ai/actions/action_entry.py +38 -0
  15. teams_ai-1.0.0/teams/ai/actions/action_turn_context.py +31 -0
  16. teams_ai-1.0.0/teams/ai/actions/action_types.py +19 -0
  17. teams_ai-1.0.0/teams/ai/ai.py +269 -0
  18. teams_ai-1.0.0/teams/ai/ai_options.py +32 -0
  19. teams_ai-1.0.0/teams/ai/augmentations/__init__.py +16 -0
  20. teams_ai-1.0.0/teams/ai/augmentations/augmentation.py +52 -0
  21. teams_ai-1.0.0/teams/ai/augmentations/default_augmentation.py +75 -0
  22. teams_ai-1.0.0/teams/ai/augmentations/monologue_augmentation.py +263 -0
  23. teams_ai-1.0.0/teams/ai/augmentations/sequence_augmentation.py +183 -0
  24. teams_ai-1.0.0/teams/ai/clients/__init__.py +8 -0
  25. teams_ai-1.0.0/teams/ai/clients/llm_client.py +227 -0
  26. teams_ai-1.0.0/teams/ai/data_sources/__init__.py +9 -0
  27. teams_ai-1.0.0/teams/ai/data_sources/data_source.py +47 -0
  28. teams_ai-1.0.0/teams/ai/data_sources/text_data_source.py +80 -0
  29. teams_ai-1.0.0/teams/ai/embeddings/__init__.py +19 -0
  30. teams_ai-1.0.0/teams/ai/embeddings/azure_openai_embeddings.py +123 -0
  31. teams_ai-1.0.0/teams/ai/embeddings/azure_openai_embeddings_options.py +37 -0
  32. teams_ai-1.0.0/teams/ai/embeddings/embeddings_model.py +34 -0
  33. teams_ai-1.0.0/teams/ai/embeddings/embeddings_response.py +31 -0
  34. teams_ai-1.0.0/teams/ai/embeddings/openai_embeddings.py +105 -0
  35. teams_ai-1.0.0/teams/ai/embeddings/openai_embeddings_options.py +37 -0
  36. teams_ai-1.0.0/teams/ai/models/__init__.py +19 -0
  37. teams_ai-1.0.0/teams/ai/models/chat_completion_action.py +34 -0
  38. teams_ai-1.0.0/teams/ai/models/openai_model.py +217 -0
  39. teams_ai-1.0.0/teams/ai/models/prompt_completion_model.py +46 -0
  40. teams_ai-1.0.0/teams/ai/models/prompt_response.py +41 -0
  41. teams_ai-1.0.0/teams/ai/moderators/__init__.py +21 -0
  42. teams_ai-1.0.0/teams/ai/moderators/azure_content_safety_moderator.py +205 -0
  43. teams_ai-1.0.0/teams/ai/moderators/default_moderator.py +26 -0
  44. teams_ai-1.0.0/teams/ai/moderators/moderator.py +52 -0
  45. teams_ai-1.0.0/teams/ai/moderators/openai_moderator.py +134 -0
  46. teams_ai-1.0.0/teams/ai/planners/__init__.py +23 -0
  47. teams_ai-1.0.0/teams/ai/planners/action_planner.py +179 -0
  48. teams_ai-1.0.0/teams/ai/planners/plan.py +69 -0
  49. teams_ai-1.0.0/teams/ai/planners/planner.py +39 -0
  50. teams_ai-1.0.0/teams/ai/prompts/__init__.py +47 -0
  51. teams_ai-1.0.0/teams/ai/prompts/assistant_message.py +26 -0
  52. teams_ai-1.0.0/teams/ai/prompts/augmentation_config.py +34 -0
  53. teams_ai-1.0.0/teams/ai/prompts/completion_config.py +90 -0
  54. teams_ai-1.0.0/teams/ai/prompts/function_call.py +20 -0
  55. teams_ai-1.0.0/teams/ai/prompts/function_call_message.py +88 -0
  56. teams_ai-1.0.0/teams/ai/prompts/function_response_message.py +98 -0
  57. teams_ai-1.0.0/teams/ai/prompts/message.py +75 -0
  58. teams_ai-1.0.0/teams/ai/prompts/prompt.py +38 -0
  59. teams_ai-1.0.0/teams/ai/prompts/prompt_functions.py +86 -0
  60. teams_ai-1.0.0/teams/ai/prompts/prompt_manager.py +415 -0
  61. teams_ai-1.0.0/teams/ai/prompts/prompt_manager_options.py +48 -0
  62. teams_ai-1.0.0/teams/ai/prompts/prompt_section_layout.py +20 -0
  63. teams_ai-1.0.0/teams/ai/prompts/prompt_template.py +40 -0
  64. teams_ai-1.0.0/teams/ai/prompts/prompt_template_config.py +62 -0
  65. teams_ai-1.0.0/teams/ai/prompts/rendered_prompt_section.py +27 -0
  66. teams_ai-1.0.0/teams/ai/prompts/sections/__init__.py +26 -0
  67. teams_ai-1.0.0/teams/ai/prompts/sections/action_augmentation_section.py +121 -0
  68. teams_ai-1.0.0/teams/ai/prompts/sections/conversation_history_section.py +197 -0
  69. teams_ai-1.0.0/teams/ai/prompts/sections/data_source_section.py +71 -0
  70. teams_ai-1.0.0/teams/ai/prompts/sections/group_section.py +100 -0
  71. teams_ai-1.0.0/teams/ai/prompts/sections/layout_engine_section.py +256 -0
  72. teams_ai-1.0.0/teams/ai/prompts/sections/prompt_section.py +87 -0
  73. teams_ai-1.0.0/teams/ai/prompts/sections/prompt_section_base.py +202 -0
  74. teams_ai-1.0.0/teams/ai/prompts/sections/template_section.py +266 -0
  75. teams_ai-1.0.0/teams/ai/prompts/sections/text_section.py +98 -0
  76. teams_ai-1.0.0/teams/ai/prompts/system_message.py +24 -0
  77. teams_ai-1.0.0/teams/ai/prompts/user_input_message.py +112 -0
  78. teams_ai-1.0.0/teams/ai/prompts/user_message.py +26 -0
  79. teams_ai-1.0.0/teams/ai/tokenizers/__init__.py +9 -0
  80. teams_ai-1.0.0/teams/ai/tokenizers/gpt_tokenizer.py +44 -0
  81. teams_ai-1.0.0/teams/ai/tokenizers/tokenizer.py +39 -0
  82. teams_ai-1.0.0/teams/ai/utilities.py +52 -0
  83. teams_ai-1.0.0/teams/ai/validators/__init__.py +22 -0
  84. teams_ai-1.0.0/teams/ai/validators/action_response_validator.py +147 -0
  85. teams_ai-1.0.0/teams/ai/validators/default_response_validator.py +30 -0
  86. teams_ai-1.0.0/teams/ai/validators/json_response_validator.py +110 -0
  87. teams_ai-1.0.0/teams/ai/validators/prompt_response_validator.py +44 -0
  88. teams_ai-1.0.0/teams/ai/validators/validation.py +34 -0
  89. teams_ai-1.0.0/teams/app.py +710 -0
  90. teams_ai-1.0.0/teams/app_error.py +15 -0
  91. teams_ai-1.0.0/teams/app_options.py +79 -0
  92. teams_ai-1.0.0/teams/input_file.py +24 -0
  93. teams_ai-1.0.0/teams/meetings/__init__.py +8 -0
  94. teams_ai-1.0.0/teams/meetings/meetings.py +108 -0
  95. teams_ai-1.0.0/teams/message_extensions/__init__.py +8 -0
  96. teams_ai-1.0.0/teams/message_extensions/message_extensions.py +703 -0
  97. teams_ai-1.0.0/teams/message_reaction_types.py +13 -0
  98. teams_ai-1.0.0/teams/py.typed +0 -0
  99. teams_ai-1.0.0/teams/query.py +18 -0
  100. teams_ai-1.0.0/teams/route.py +31 -0
  101. teams_ai-1.0.0/teams/state/__init__.py +24 -0
  102. teams_ai-1.0.0/teams/state/conversation_state.py +49 -0
  103. teams_ai-1.0.0/teams/state/memory.py +127 -0
  104. teams_ai-1.0.0/teams/state/state.py +174 -0
  105. teams_ai-1.0.0/teams/state/temp_state.py +43 -0
  106. teams_ai-1.0.0/teams/state/todict.py +30 -0
  107. teams_ai-1.0.0/teams/state/turn_state.py +79 -0
  108. teams_ai-1.0.0/teams/state/user_state.py +47 -0
  109. teams_ai-1.0.0/teams/task_modules/__init__.py +9 -0
  110. teams_ai-1.0.0/teams/task_modules/task_modules.py +167 -0
  111. teams_ai-1.0.0/teams/task_modules/task_modules_options.py +18 -0
  112. teams_ai-1.0.0/teams/teams_adapter.py +126 -0
  113. teams_ai-1.0.0/teams/typing.py +47 -0
  114. teams_ai-1.0.0/teams/user_agent.py +14 -0
  115. teams_ai-1.0.0/teams/utils/json/__init__.py +9 -0
  116. teams_ai-1.0.0/teams/utils/json/parse.py +33 -0
  117. teams_ai-1.0.0/teams/utils/json/parse_object.py +82 -0
  118. teams_ai-1.0.0/tests/adaptive_cards/test_adaptive_cards.py +159 -0
  119. teams_ai-1.0.0/tests/ai/augmentations/test_default_augmentation.py +77 -0
  120. teams_ai-1.0.0/tests/ai/augmentations/test_monologue_augmentation.py +171 -0
  121. teams_ai-1.0.0/tests/ai/augmentations/test_sequence_augmentation.py +209 -0
  122. teams_ai-1.0.0/tests/ai/data_sources/test_text_data_source.py +49 -0
  123. teams_ai-1.0.0/tests/ai/embeddings/test_azure_openai_embeddings.py +163 -0
  124. teams_ai-1.0.0/tests/ai/embeddings/test_openai_embeddings.py +143 -0
  125. teams_ai-1.0.0/tests/ai/models/test_openai_model.py +148 -0
  126. teams_ai-1.0.0/tests/ai/moderators/test_azure_content_safety_moderator.py +157 -0
  127. teams_ai-1.0.0/tests/ai/moderators/test_default_moderator.py +30 -0
  128. teams_ai-1.0.0/tests/ai/moderators/test_openai_moderator.py +214 -0
  129. teams_ai-1.0.0/tests/ai/prompts/test_assets/happy_path/actions.json +25 -0
  130. teams_ai-1.0.0/tests/ai/prompts/test_assets/happy_path/config.json +24 -0
  131. teams_ai-1.0.0/tests/ai/prompts/test_assets/happy_path/skprompt.txt +1 -0
  132. teams_ai-1.0.0/tests/ai/prompts/test_assets/include_images/config.json +25 -0
  133. teams_ai-1.0.0/tests/ai/prompts/test_assets/include_images/skprompt.txt +1 -0
  134. teams_ai-1.0.0/tests/ai/prompts/test_assets/migrate_old_schema/config.json +19 -0
  135. teams_ai-1.0.0/tests/ai/prompts/test_assets/migrate_old_schema/skprompt.txt +1 -0
  136. teams_ai-1.0.0/tests/ai/prompts/test_assets/no_config/skprompt.txt +1 -0
  137. teams_ai-1.0.0/tests/ai/prompts/test_assets/no_prompt/config.json +24 -0
  138. teams_ai-1.0.0/tests/ai/prompts/test_assistant_message.py +28 -0
  139. teams_ai-1.0.0/tests/ai/prompts/test_conversation_history.py +155 -0
  140. teams_ai-1.0.0/tests/ai/prompts/test_data_source_section.py +39 -0
  141. teams_ai-1.0.0/tests/ai/prompts/test_function_call_message.py +48 -0
  142. teams_ai-1.0.0/tests/ai/prompts/test_function_response_message.py +49 -0
  143. teams_ai-1.0.0/tests/ai/prompts/test_group_section.py +67 -0
  144. teams_ai-1.0.0/tests/ai/prompts/test_layout_engine.py +174 -0
  145. teams_ai-1.0.0/tests/ai/prompts/test_prompt_manager_v2.py +195 -0
  146. teams_ai-1.0.0/tests/ai/prompts/test_prompt_section_base.py +216 -0
  147. teams_ai-1.0.0/tests/ai/prompts/test_system_message.py +28 -0
  148. teams_ai-1.0.0/tests/ai/prompts/test_template_section.py +200 -0
  149. teams_ai-1.0.0/tests/ai/prompts/test_text_section.py +66 -0
  150. teams_ai-1.0.0/tests/ai/prompts/test_user_input_message.py +163 -0
  151. teams_ai-1.0.0/tests/ai/prompts/test_user_message.py +28 -0
  152. teams_ai-1.0.0/tests/ai/test_utilities.py +46 -0
  153. teams_ai-1.0.0/tests/ai/tokenizers/test_gpt_tokenizer.py +29 -0
  154. teams_ai-1.0.0/tests/ai/validators/test_action_response_validator.py +172 -0
  155. teams_ai-1.0.0/tests/ai/validators/test_default_response_validator.py +28 -0
  156. teams_ai-1.0.0/tests/ai/validators/test_json_response_validator.py +161 -0
  157. teams_ai-1.0.0/tests/state/test_conversation_state.py +115 -0
  158. teams_ai-1.0.0/tests/state/test_custom_turn_state.py +171 -0
  159. teams_ai-1.0.0/tests/state/test_temp_state.py +51 -0
  160. teams_ai-1.0.0/tests/state/test_turn_state.py +178 -0
  161. teams_ai-1.0.0/tests/state/test_user_state.py +99 -0
  162. teams_ai-1.0.0/tests/task_modules/test_task_modules.py +73 -0
  163. teams_ai-1.0.0/tests/test_app.py +752 -0
  164. teams_ai-1.0.0/tests/test_meetings.py +324 -0
  165. teams_ai-1.0.0/tests/test_message_extensions.py +845 -0
  166. teams_ai-1.0.0/tests/utils/__init__.py +7 -0
  167. teams_ai-1.0.0/tests/utils/activity.py +18 -0
  168. teams_ai-1.0.0/tests/utils/adapter.py +36 -0
teams_ai-1.0.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Microsoft Corporation. All rights reserved.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE
@@ -0,0 +1,44 @@
1
+ Metadata-Version: 2.1
2
+ Name: teams-ai
3
+ Version: 1.0.0
4
+ Summary: SDK focused on building AI based applications for Microsoft Teams.
5
+ Home-page: https://github.com/microsoft/teams-ai
6
+ Keywords: microsoft,teams,ai,bot
7
+ Author: Microsoft
8
+ Author-email: teams@microsoft.com
9
+ Requires-Python: >=3.8,<4.0
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.8
12
+ Classifier: Programming Language :: Python :: 3.9
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Requires-Dist: aiohttp (>=3.8.5,<4.0.0)
17
+ Requires-Dist: azure-ai-contentsafety (>=1.0.0,<2.0.0)
18
+ Requires-Dist: botbuilder-core (>=4.14.8,<5.0.0)
19
+ Requires-Dist: botbuilder-integration-aiohttp (>=4.14.8,<5.0.0)
20
+ Requires-Dist: botframework-connector (>=4.14.8,<5.0.0)
21
+ Requires-Dist: dataclasses-json (>=0.6.4,<0.7.0)
22
+ Requires-Dist: jsonschema (>=4.21.1,<5.0.0)
23
+ Requires-Dist: openai (>=1.11.1,<2.0.0)
24
+ Requires-Dist: pyyaml (>=6.0.1,<7.0.0)
25
+ Requires-Dist: tiktoken (>=0.4.0,<0.5.0)
26
+ Requires-Dist: types-pyyaml (>=6.0.12.12,<7.0.0.0)
27
+ Project-URL: Documentation, https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/teams%20conversational%20ai/teams-conversation-ai-overview
28
+ Project-URL: Repository, https://github.com/microsoft/teams-ai
29
+ Description-Content-Type: text/markdown
30
+
31
+ # Teams AI Library
32
+
33
+ Welcome to the Teams AI Library Python package!
34
+
35
+ 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.
36
+
37
+ ## Getting Started
38
+
39
+ To get started, take a look at the [getting started docs](https://github.com/microsoft/teams-ai/blob/main/getting-started/README.md).
40
+
41
+ ## Migration
42
+
43
+ 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).
44
+
@@ -0,0 +1,13 @@
1
+ # Teams AI Library
2
+
3
+ Welcome to the Teams AI Library Python package!
4
+
5
+ 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.
6
+
7
+ ## Getting Started
8
+
9
+ To get started, take a look at the [getting started docs](https://github.com/microsoft/teams-ai/blob/main/getting-started/README.md).
10
+
11
+ ## Migration
12
+
13
+ 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).
@@ -0,0 +1,71 @@
1
+ [tool.poetry]
2
+ name = "teams-ai"
3
+ version = "1.0.0"
4
+ description = "SDK focused on building AI based applications for Microsoft Teams."
5
+ authors = ["Microsoft <teams@microsoft.com>"]
6
+ readme = "README.md"
7
+ repository = "https://github.com/microsoft/teams-ai"
8
+ documentation = "https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/teams%20conversational%20ai/teams-conversation-ai-overview"
9
+ keywords = ["microsoft", "teams", "ai", "bot"]
10
+ packages = [
11
+ { include = "teams" },
12
+ { include = "tests" }
13
+ ]
14
+
15
+ [tool.poetry.dependencies]
16
+ botbuilder-core = "^4.14.8"
17
+ botbuilder-integration-aiohttp = "^4.14.8"
18
+ botframework-connector = "^4.14.8"
19
+ python = ">=3.8,<4.0"
20
+ tiktoken = "^0.4.0"
21
+ aiohttp = "^3.8.5"
22
+ jsonschema = "^4.21.1"
23
+ types-pyyaml = "^6.0.12.12"
24
+ pyyaml = "^6.0.1"
25
+ dataclasses-json = "^0.6.4"
26
+ openai = "^1.11.1"
27
+ azure-ai-contentsafety = "^1.0.0"
28
+
29
+ [tool.poetry.group.dev.dependencies]
30
+ pytest = "^7.4.0"
31
+ pylint = "^2.17.4"
32
+ pytest-cov = "^4.1.0"
33
+ pytest-asyncio = "^0.21.1"
34
+ black = "^23.7.0"
35
+ isort = "^5.12.0"
36
+ mypy = "^1.5.0"
37
+ httpx = "^0.26.0"
38
+
39
+ [tool.poetry.scripts]
40
+ lint = "scripts:lint"
41
+ fmt = "scripts:fmt"
42
+ test = "scripts:test"
43
+ clean = "scripts:clean"
44
+ ci = "scripts:ci"
45
+
46
+ [build-system]
47
+ requires = ["poetry-core"]
48
+ build-backend = "poetry.core.masonry.api"
49
+
50
+ [tool.black]
51
+ line-length = 100
52
+ target-version = ['py38']
53
+
54
+ [tool.isort]
55
+ profile = "black"
56
+
57
+ [tool.pytest.ini_options]
58
+ addopts = "-rx --cov-report html:coverage/html --cov-report lcov:coverage/lcov.info --cov=teams"
59
+ log_cli = true
60
+ log_cli_level = "INFO"
61
+
62
+ [tool.mypy]
63
+ python_version = "3.8"
64
+ ignore_missing_imports = true
65
+ show_error_codes = true
66
+ no_implicit_optional = true
67
+ warn_unused_ignores = true
68
+
69
+ [[tool.mypy.overrides]]
70
+ module = "tests.*"
71
+ disable_error_code = ["var-annotated", "method-assign"]
@@ -0,0 +1,25 @@
1
+ """
2
+ Copyright (c) Microsoft Corporation. All rights reserved.
3
+ Licensed under the MIT License.
4
+ """
5
+
6
+ from .activity_type import ActivityType, ConversationUpdateType
7
+ from .app import Application
8
+ from .app_error import ApplicationError
9
+ from .app_options import ApplicationOptions
10
+ from .input_file import InputFile
11
+ from .message_reaction_types import MessageReactionTypes
12
+ from .query import Query
13
+ from .teams_adapter import TeamsAdapter
14
+
15
+ __all__ = [
16
+ "ActivityType",
17
+ "ConversationUpdateType",
18
+ "Application",
19
+ "ApplicationError",
20
+ "ApplicationOptions",
21
+ "InputFile",
22
+ "Query",
23
+ "TeamsAdapter",
24
+ "MessageReactionTypes",
25
+ ]
@@ -0,0 +1,47 @@
1
+ """
2
+ Copyright (c) Microsoft Corporation. All rights reserved.
3
+ Licensed under the MIT License.
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ from typing import Literal
9
+
10
+ ActivityType = Literal[
11
+ "message",
12
+ "contactRelationUpdate",
13
+ "conversationUpdate",
14
+ "typing",
15
+ "endOfConversation",
16
+ "event",
17
+ "invoke",
18
+ "invokeResponse",
19
+ "deleteUserData",
20
+ "messageUpdate",
21
+ "messageDelete",
22
+ "installationUpdate",
23
+ "messageReaction",
24
+ "suggestion",
25
+ "trace",
26
+ "handoff",
27
+ "command",
28
+ "commandResult",
29
+ ]
30
+
31
+ ConversationUpdateType = Literal[
32
+ "channelCreated",
33
+ "channelRenamed",
34
+ "channelDeleted",
35
+ "channelRestored",
36
+ "membersAdded",
37
+ "membersRemoved",
38
+ "teamRenamed",
39
+ "teamDeleted",
40
+ "teamArchived",
41
+ "teamUnarchived",
42
+ "teamRestored",
43
+ ]
44
+
45
+ MessageReactionType = Literal["reactionsAdded", "reactionsRemoved"]
46
+
47
+ MessageUpdateType = Literal["editMessage", "softDeleteMessage", "undeleteMessage"]
@@ -0,0 +1,9 @@
1
+ """
2
+ Copyright (c) Microsoft Corporation. All rights reserved.
3
+ Licensed under the MIT License.
4
+ """
5
+ from .adaptive_cards_options import AdaptiveCardsOptions
6
+ from .adaptive_cards_search_params import AdaptiveCardsSearchParams
7
+ from .adaptive_cards_search_result import AdaptiveCardsSearchResult
8
+
9
+ __all__ = ["AdaptiveCardsOptions", "AdaptiveCardsSearchParams", "AdaptiveCardsSearchResult"]
@@ -0,0 +1,271 @@
1
+ """
2
+ Copyright (c) Microsoft Corporation. All rights reserved.
3
+ Licensed under the MIT License.
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ import re
9
+ from typing import Awaitable, Callable, Generic, List, Pattern, TypeVar, Union
10
+
11
+ from botbuilder.core import TurnContext
12
+ from botbuilder.schema import (
13
+ Activity,
14
+ ActivityTypes,
15
+ AdaptiveCardInvokeResponse,
16
+ InvokeResponse,
17
+ )
18
+
19
+ from teams.query import Query
20
+ from teams.route import Route
21
+ from teams.state import TurnState
22
+
23
+ from .adaptive_cards_search_params import AdaptiveCardsSearchParams
24
+ from .adaptive_cards_search_result import AdaptiveCardsSearchResult
25
+
26
+ ACTION_INVOKE_NAME = "adaptiveCard/action"
27
+ ACTION_EXECUTE_TYPE = "Action.Execute"
28
+ SEARCH_INVOKE_NAME = "application/search"
29
+
30
+ StateT = TypeVar("StateT", bound=TurnState)
31
+
32
+
33
+ class AdaptiveCards(Generic[StateT]):
34
+ _route_registry: List[Route]
35
+ _action_submit_filter: str
36
+
37
+ def __init__(self, route_registry: List[Route], action_submit_filter: str) -> None:
38
+ self._route_registry = route_registry
39
+ self._action_submit_filter = action_submit_filter
40
+
41
+ def action_execute(
42
+ self, verb: Union[str, Pattern[str], Callable[[TurnContext], bool]]
43
+ ) -> Callable[
44
+ [Callable[[TurnContext, StateT, dict], Awaitable[Union[str, dict]]]],
45
+ Callable[[TurnContext, StateT, dict], Awaitable[Union[str, dict]]],
46
+ ]:
47
+ """
48
+ Adds a route for handling Adaptive Card Action.Execute events.
49
+ This method can be used as either a decorator or a method.
50
+
51
+ ```python
52
+ # Use this method as a decorator
53
+ @app.adaptive_cards.action_execute("do")
54
+ async def execute_do(context: TurnContext, state: TurnState, data: Any):
55
+ print(f"Execute with data: {data}")
56
+ return True
57
+
58
+ # Pass a function to this method
59
+ app.adaptive_cards.action_execute("do")(execute_do)
60
+ ```
61
+
62
+ #### Args:
63
+ - `verb`: a string, regex pattern or a function to match the verb of the action
64
+ """
65
+
66
+ # Create route selector for the handler
67
+ def __selector__(context: TurnContext) -> bool:
68
+ if (
69
+ context.activity.type == ActivityTypes.invoke
70
+ and context.activity.name == ACTION_INVOKE_NAME
71
+ ):
72
+ action = context.activity.value["action"] if context.activity.value else None
73
+ action_type = action["type"] if action else None
74
+ action_verb = action["verb"] if action else None
75
+ if action_type == ACTION_EXECUTE_TYPE:
76
+ # when verb is a function
77
+ if callable(verb):
78
+ return verb(context)
79
+ # when verb is a regex pattern
80
+ if isinstance(verb, Pattern) and isinstance(action_verb, str):
81
+ hits = re.match(verb, action_verb)
82
+ return hits is not None
83
+ # when verb is a string
84
+ return verb == action_verb
85
+
86
+ return False
87
+
88
+ def __call__(
89
+ func: Callable[[TurnContext, StateT, dict], Awaitable[Union[str, dict]]]
90
+ ) -> Callable[[TurnContext, StateT, dict], Awaitable[Union[str, dict]]]:
91
+ async def __handler__(context: TurnContext, state: StateT) -> bool:
92
+ result = await func(context, state, context.activity.value["action"]["data"])
93
+ if context.turn_state.get(ActivityTypes.invoke_response) is None:
94
+ if isinstance(result, str):
95
+ response = AdaptiveCardInvokeResponse(
96
+ status_code=200,
97
+ type="application/vnd.microsoft.activity.message",
98
+ value=result,
99
+ )
100
+ else:
101
+ response = AdaptiveCardInvokeResponse(
102
+ status_code=200,
103
+ type="application/vnd.microsoft.card.adaptive",
104
+ value=result,
105
+ )
106
+ await context.send_activity(
107
+ Activity(
108
+ type="invokeResponse", value=InvokeResponse(status=200, body=response)
109
+ )
110
+ )
111
+ return True
112
+
113
+ self._route_registry.append(Route[StateT](__selector__, __handler__))
114
+ return func
115
+
116
+ return __call__
117
+
118
+ def action_submit(
119
+ self, verb: Union[str, Pattern[str], Callable[[TurnContext], bool]]
120
+ ) -> Callable[
121
+ [Callable[[TurnContext, StateT, dict], Awaitable[None]]],
122
+ Callable[[TurnContext, StateT, dict], Awaitable[None]],
123
+ ]:
124
+ """
125
+ Adds a route for handling Adaptive Card Action.Submit events.
126
+ This method can be used as either a decorator or a method.
127
+
128
+ ```python
129
+ # Use this method as a decorator
130
+ @app.adaptive_cards.action_submit("submit")
131
+ async def execute_submit(context: TurnContext, state: TurnState, data: Any):
132
+ print(f"Execute with data: {data}")
133
+ return True
134
+
135
+ # Pass a function to this method
136
+ app.adaptive_cards.action_submit("submit")(execute_submit)
137
+ ```
138
+
139
+ #### Args:
140
+ - `verb`: a string, regex pattern or a function to match the verb of the action
141
+ """
142
+
143
+ # Create route selector for the handler
144
+ def __selector__(context: TurnContext) -> bool:
145
+ filter = self._action_submit_filter
146
+ if (
147
+ context.activity.type == ActivityTypes.message
148
+ and context.activity.text is None
149
+ and isinstance(context.activity.value, dict)
150
+ ):
151
+ filter_value = context.activity.value.get(filter)
152
+ # when verb is a function
153
+ if callable(verb):
154
+ return verb(context)
155
+ # when verb is a regex pattern
156
+ if isinstance(verb, Pattern) and isinstance(filter_value, str):
157
+ hits = re.match(verb, filter_value)
158
+ return hits is not None
159
+ # when verb is a string
160
+ return verb == filter_value
161
+
162
+ return False
163
+
164
+ def __call__(
165
+ func: Callable[[TurnContext, StateT, dict], Awaitable[None]]
166
+ ) -> Callable[[TurnContext, StateT, dict], Awaitable[None]]:
167
+ async def __handler__(context: TurnContext, state: StateT) -> bool:
168
+ await func(context, state, context.activity.value)
169
+ return True
170
+
171
+ self._route_registry.append(Route[StateT](__selector__, __handler__))
172
+ return func
173
+
174
+ return __call__
175
+
176
+ def search(
177
+ self, dataset: Union[str, Pattern[str], Callable[[TurnContext], bool]]
178
+ ) -> Callable[
179
+ [
180
+ Callable[
181
+ [TurnContext, StateT, Query[AdaptiveCardsSearchParams]],
182
+ Awaitable[List[AdaptiveCardsSearchResult]],
183
+ ]
184
+ ],
185
+ Callable[
186
+ [TurnContext, StateT, Query[AdaptiveCardsSearchParams]],
187
+ Awaitable[List[AdaptiveCardsSearchResult]],
188
+ ],
189
+ ]:
190
+ """
191
+ Adds a route for handling Adaptive Card search events. This method can be used as either
192
+ a decorator or a method.
193
+
194
+ ```python
195
+ # Use this method as a decorator
196
+ @app.adaptive_cards.search("people")
197
+ async def search_people(context: TurnContext, state: TurnState, query: Any):
198
+ print(f"Execute with query: {query}")
199
+ return True
200
+
201
+ # Pass a function to this method
202
+ app.adaptive_cards.search("people")(search_people)
203
+ ```
204
+
205
+ #### Args:
206
+ - `dataset`: a string, regex pattern or a function to match the verb of the action
207
+ """
208
+
209
+ # Create route selector for the handler
210
+ def __selector__(context: TurnContext) -> bool:
211
+ if (
212
+ context.activity.type == ActivityTypes.invoke
213
+ and context.activity.name == SEARCH_INVOKE_NAME
214
+ ):
215
+ activity_dataset = (
216
+ context.activity.value["dataset"] if context.activity.value else None
217
+ )
218
+ # when verb is a function
219
+ if callable(dataset):
220
+ return dataset(context)
221
+ # when verb is a regex pattern
222
+ if isinstance(dataset, Pattern) and isinstance(activity_dataset, str):
223
+ hits = re.match(dataset, activity_dataset)
224
+ return hits is not None
225
+ # when verb is a string
226
+ return dataset == activity_dataset
227
+
228
+ return False
229
+
230
+ def __call__(
231
+ func: Callable[
232
+ [TurnContext, StateT, Query[AdaptiveCardsSearchParams]],
233
+ Awaitable[List[AdaptiveCardsSearchResult]],
234
+ ]
235
+ ) -> Callable[
236
+ [TurnContext, StateT, Query[AdaptiveCardsSearchParams]],
237
+ Awaitable[List[AdaptiveCardsSearchResult]],
238
+ ]:
239
+ async def __handler__(context: TurnContext, state: StateT) -> bool:
240
+ params = context.activity.value
241
+ # Flatten search parameters
242
+ query = Query[AdaptiveCardsSearchParams](
243
+ count=params["queryOptions"]["top"]
244
+ if params and params["queryOptions"] and params["queryOptions"]["top"]
245
+ else 25,
246
+ skip=params["queryOptions"]["skip"]
247
+ if params and params["queryOptions"] and params["queryOptions"]["skip"]
248
+ else 0,
249
+ parameters=AdaptiveCardsSearchParams(
250
+ query_text=params["queryText"] if params and params["queryText"] else "",
251
+ dataset=params["dataset"] if params and params["dataset"] else "",
252
+ ),
253
+ )
254
+ result = await func(context, state, query)
255
+ if context.turn_state.get(ActivityTypes.invoke_response) is None:
256
+ # Format invoke response
257
+ response = {
258
+ "type": "application/vnd.microsoft.search.searchResponse",
259
+ "value": {"results": result},
260
+ }
261
+ await context.send_activity(
262
+ Activity(
263
+ type="invokeResponse", value=InvokeResponse(status=200, body=response)
264
+ )
265
+ )
266
+ return True
267
+
268
+ self._route_registry.append(Route[StateT](__selector__, __handler__))
269
+ return func
270
+
271
+ return __call__
@@ -0,0 +1,18 @@
1
+ """
2
+ Copyright (c) Microsoft Corporation. All rights reserved.
3
+ Licensed under the MIT License.
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ from dataclasses import dataclass
9
+
10
+
11
+ @dataclass
12
+ class AdaptiveCardsOptions:
13
+ action_submit_filer: str = "verb"
14
+ """
15
+ Data field used to identify the Action.Submit handler to trigger.
16
+ When an Action.Submit is triggered, the field name specified here will be used to determine
17
+ the handler to route the request to.
18
+ """
@@ -0,0 +1,14 @@
1
+ """
2
+ Copyright (c) Microsoft Corporation. All rights reserved.
3
+ Licensed under the MIT License.
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ from dataclasses import dataclass
9
+
10
+
11
+ @dataclass
12
+ class AdaptiveCardsSearchParams:
13
+ query_text: str
14
+ dataset: str
@@ -0,0 +1,14 @@
1
+ """
2
+ Copyright (c) Microsoft Corporation. All rights reserved.
3
+ Licensed under the MIT License.
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ from dataclasses import dataclass
9
+
10
+
11
+ @dataclass
12
+ class AdaptiveCardsSearchResult:
13
+ title: str
14
+ value: str
@@ -0,0 +1,9 @@
1
+ """
2
+ Copyright (c) Microsoft Corporation. All rights reserved.
3
+ Licensed under the MIT License.
4
+ """
5
+
6
+ from .ai import AI
7
+ from .ai_options import AIOptions
8
+
9
+ __all__ = ["AI", "AIOptions"]
@@ -0,0 +1,10 @@
1
+ """
2
+ Copyright (c) Microsoft Corporation. All rights reserved.
3
+ Licensed under the MIT License.
4
+ """
5
+
6
+ from .action_entry import ActionEntry, ActionHandler
7
+ from .action_turn_context import ActionTurnContext
8
+ from .action_types import ActionTypes
9
+
10
+ __all__ = ["ActionEntry", "ActionHandler", "ActionTurnContext", "ActionTypes"]
@@ -0,0 +1,38 @@
1
+ """
2
+ Copyright (c) Microsoft Corporation. All rights reserved.
3
+ Licensed under the MIT License.
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ from typing import Any, Awaitable, Callable, Generic, Optional, TypeVar
9
+
10
+ from botbuilder.core import TurnContext
11
+
12
+ from teams.state import TurnState
13
+
14
+ from .action_turn_context import ActionTurnContext
15
+
16
+ StateT = TypeVar("StateT", bound=TurnState)
17
+ ActionHandler = Callable[[ActionTurnContext, StateT], Awaitable[str]]
18
+
19
+
20
+ class ActionEntry(Generic[StateT]):
21
+ name: str
22
+ allow_overrides: bool
23
+ func: ActionHandler[StateT]
24
+
25
+ def __init__(
26
+ self,
27
+ name: str,
28
+ allow_overrides: bool,
29
+ func: ActionHandler,
30
+ ) -> None:
31
+ self.name = name
32
+ self.allow_overrides = allow_overrides
33
+ self.func = func
34
+
35
+ async def invoke(
36
+ self, context: TurnContext, state: StateT, data: Any, name: Optional[str] = None
37
+ ) -> str:
38
+ return await self.func(ActionTurnContext(name or self.name, data, context), state)
@@ -0,0 +1,31 @@
1
+ """
2
+ Copyright (c) Microsoft Corporation. All rights reserved.
3
+ Licensed under the MIT License.
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ from typing import Generic, TypeVar
9
+
10
+ from botbuilder.core import TurnContext
11
+
12
+ DataT = TypeVar("DataT")
13
+
14
+
15
+ class ActionTurnContext(TurnContext, Generic[DataT]):
16
+ name: str
17
+ """
18
+ The action name
19
+ """
20
+
21
+ data: DataT
22
+ """
23
+ Action specific data
24
+ """
25
+
26
+ def __init__(self, name: str, data: DataT, context: TurnContext) -> None:
27
+ super().__init__(context)
28
+ context.copy_to(self)
29
+ self._turn_state = context.turn_state
30
+ self.name = name
31
+ self.data = data
@@ -0,0 +1,19 @@
1
+ """
2
+ Copyright (c) Microsoft Corporation. All rights reserved.
3
+ Licensed under the MIT License.
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ from enum import Enum
9
+
10
+
11
+ class ActionTypes(str, Enum):
12
+ STOP = "STOP"
13
+ UNKNOWN_ACTION = "___UnknownAction___"
14
+ FLAGGED_INPUT = "___FlaggedInput___"
15
+ FLAGGED_OUTPUT = "___FlaggedOutput___"
16
+ HTTP_ERROR = "___HttpError___"
17
+ PLAN_READY = "___PlanReady___"
18
+ DO_COMMAND = "___DO___"
19
+ SAY_COMMAND = "___SAY___"