8000 Feature parity with C# and JS by Zerryth · Pull Request #148 · microsoft/botbuilder-python · GitHub
[go: up one dir, main page]

Skip to content

Feature parity with C# and JS #148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 87 commits into from
Apr 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
78c6751
adding base of activity handler, addition to a sample pending
axelsrz Apr 12, 2019
818e811
initial file structure (empty class files)
Apr 14, 2019
aa3a072
SAFEKEEPING Checkin to unblock congysu
daveta Apr 15, 2019
03f5a75
port for dialog instance
congysu Apr 15, 2019
4a5afc2
Add unittest test, fix setup.py, misc stubs to get initial test running
daveta Apr 16, 2019
58c9468
Merge branch 'work-in-progress' of https://github.com/Microsoft/botbu…
daveta Apr 16, 2019
f30ec6d
Make dialog_set test work
daveta Apr 16, 2019
e83a392
Add PropertyManager
daveta Apr 16, 2019
1420622
Port channel for choices and channels for connector
congysu Apr 16, 2019
814cbf9
Add WaterfallDialog initial checkin
daveta Apr 17, 2019
478c4ed
Base prompt stuff
daveta Apr 17, 2019
cb434bd
Miss a few files
daveta Apr 17, 2019
3d01cb1
fix package spelling!
daveta Apr 17, 2019
aa43ad2
Target Python 3.6 - remove reference to PEP which does not exist
daveta Apr 17, 2019
20571b0
Add aiounittest as formal dependency (in setup.py)
daveta Apr 17, 2019
bb78153
Port ChoiceFactoryOptions
congysu Apr 17, 2019
6229bdb
Fix 3.6-specific issues
daveta Apr 17, 2019
918cb37
Add Choice
congysu Apr 17, 2019 8000
4e732cc
Confirm prompt safe keeping
daveta Apr 18, 2019
e40da60
Initial DateTimePrompt
daveta Apr 18, 2019
6a85978
First Number Prompt test, fix a bunch of issues
daveta Apr 18, 2019
798b616
Add ChoiceFactory
congysu Apr 18, 2019
c522b72
add unittest for choice factory
congysu Apr 19, 2019
b88f8a9
Add component_dialog, fix tons of things
daveta Apr 19, 2019
71eb546
Fix memory_storage, remove tons of semicolons, other cleanup
daveta Apr 21, 2019
384c873
Move pytest to unittest (or aiounittest as the case may be)
daveta Apr 22, 2019
61b56de
Small fixes
daveta Apr 22, 2019
bd8344d
few tests for bot state
Apr 23, 2019
7cc45e2
Safekeeping checkin
daveta Apr 23, 2019
0d0d14b
Forgot a few files
daveta Apr 23, 2019
200b155
fixes in bot sate, several tests still pending
Apr 23, 2019
6d5ca5c
disable failing test
daveta Apr 23, 2019
b66ef86
solving merge conflicts
Apr 23, 2019
2abe98b
subtest for channel
congysu Apr 19, 2019
9f06cea
Initial Testflow test
daveta Apr 23, 2019
bbecf1d
Merge branch 'work-in-progress' into axsuarez/bot-state-tests-revamp
Apr 23, 2019
b7246cb
More tests for app insights
daveta Apr 23, 2019
24b9cef
Basic bot state tests completed, pending to review default int proper…
Apr 23, 2019
1761c28
Merge branch 'axsuarez/bot-state-tests-revamp' into work-in-progress
Apr 23, 2019
257a947
add LuisApplication
congysu Apr 23, 2019
be41dc0
dialog classes for core bot (last details pending)
axelsrz Apr 24, 2019
81ab00b
add luis prediction options
congysu Apr 24, 2019
ad1a1a8
add luis telemetry constants
congysu Apr 24, 2019
f5a20e9
add recognizer result etc.
congysu Apr 24, 2019
41b009a
dialogs of core bot done, luis_helper and main.py pending
axelsrz Apr 25, 2019
2c77834
merging luis changes
axelsrz Apr 25, 2019
0c00c3f
dialogs and helpers done, main.py and config pending
axelsrz Apr 25, 2019
588a72c
add luis recognizer etc.
congysu Apr 25, 2019
d96c3b3
created QnAMaker class
Zerryth Apr 26, 2019
ade02a8
sample done, yaml configand testing missing
axelsrz Apr 26, 2019
d882913
Merge branch 'work-in-progress' of https://github.com/Microsoft/botbu…
Zerryth Apr 26, 2019
a4f3966
merge of core bot sample
axelsrz Apr 26, 2019
52619ae
qna w/basic functionality in 1 file
Zerryth Apr 26, 2019
a26906a
Merge branch 'work-in-progress' of https://github.com/Microsoft/botbu…
Zerryth Apr 26, 2019
1ebd1e0
removed ACTIVITY constant I had for testing
Zerryth Apr 26, 2019
170029b
reorganized qna classes into separate files
Zerryth Apr 26, 2019
c470336
removed test case
Zerryth Apr 26, 2019
2b1510b
add luis recognizer init test
congysu Apr 26, 2019
387cfd4
qna telemetry
Zerryth Apr 26, 2019
8875d1b
Merge branch 'work-in-progress' of https://github.com/Microsoft/botbu…
Zerryth Apr 26, 2019
328c745
add test with mock and patch
congysu Apr 26, 2019
9371679
Now raises errors and added docstrings
Zerryth Apr 26, 2019
d57665a
Merge branch 'work-in-progress' of https://github.com/Microsoft/botbu…
Zerryth Apr 26, 2019
60adb55
update to azure-cognitiveservices-language.* 0.2
congysu Apr 27, 2019
027f8cd
add test for multi-intents etc.
congysu Apr 27, 2019
f621b93
tests for list entity etc
congysu Apr 27, 2019
1526bad
test for composite entity
congysu Apr 27, 2019
396691a
add test for datetime entity
congysu Apr 28, 2019
80fe1f0
add test for top intent
congysu Apr 28, 2019
a56b55f
Support and sample for flask/django
daveta Apr 28, 2019
e581ebd
fixed spacing in files
Zerryth Apr 28, 2019
4271921
Merge branch 'work-in-progress' of https://github.com/Microsoft/botbu…
Zerryth Apr 28, 2019
395f95b
add user agent
congysu Apr 28, 2019
f3cac96
add connection timeout
congysu Apr 29, 2019
00d0bd2
ctor tests
Zerryth Apr 29, 2019
158eac7
Merge branch 'work-in-progress' of https://github.com/Microsoft/botbu…
Zerryth Apr 29, 2019
59b5cbc
added mocks to test QnAMaker.get_answers()
Zerryth Apr 29, 2019
19762ce
test: returns answer w/o options
Zerryth Apr 29, 2019
39cd559
update comments for luis prediction options
congysu Apr 29, 2019
1a448d8
build fixing, sync with appinsights needed
axelsrz Apr 29, 2019
5a6e3fe
Merge branch 'work-in-progress' of https://github.com/Microsoft/botbu…
axelsrz Apr 29, 2019
be23f75
skipping tests with pending class
axelsrz Apr 29, 2019
99a15a1
remove unnecessary ()
axelsrz Apr 29, 2019
94289ba
add trace activity
congysu Apr 29, 2019
6ae4f25
fixed package versioning requirements for botbuilder azure
axelsrz Apr 29, 2019
48b2311
Merge branch 'work-in-progress' of https://github.com/Microsoft/botbu…
axelsrz Apr 29, 2019
e76ada4
fixed typo in requirement installs
axelsrz Apr 29, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions libraries/botbuilder-ai/botbuilder/ai/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

from .about import __title__, __version__

__all__ = ["__title__", "__version__"]
12 changes: 12 additions & 0 deletions libraries/botbuilder-ai/botbuilder/ai/about.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import os

__title__ = 'botbuilder-ai'
__version__ = os.environ["packageVersion"] if "packageVersion" in os.environ else "4.0.0.a6"
__uri__ = 'https://www.github.com/Microsoft/botbuilder-python'
__author__ = 'Microsoft'
__description__ = 'Microsoft Bot Framework Bot Builder'
__summary__ = 'Microsoft Bot Framework Bot Builder SDK for Python.'
__license__ = 'MIT'
19 changes: 19 additions & 0 deletions libraries/botbuilder-ai/botbuilder/ai/luis/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

from .intent_score import IntentScore
from .luis_application import LuisApplication
from .luis_prediction_options import LuisPredictionOptions
from .luis_telemetry_constants import LuisTelemetryConstants
from .recognizer_result import RecognizerResult, TopIntent
from .luis_recognizer import LuisRecognizer

__all__ = [
"IntentScore",
"LuisApplication",
"LuisPredictionOptions",
"LuisRecognizer",
"LuisTelemetryConstants",
"RecognizerResult",
"TopIntent",
]
69 changes: 69 additions & 0 deletions libraries/botbuilder-ai/botbuilder/ai/luis/activity_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

from datetime import datetime

from botbuilder.schema import (
Activity,
ActivityTypes,
ChannelAccount,
ConversationAccount,
)


class ActivityUtil(object):
@staticmethod
def create_trace(
turn_activity: Activity,
name: str,
value: object = None,
value_type: str = None,
label: str = None,
) -> Activity:
"""Creates a trace activity based on this activity.

:param turn_activity:
:type turn_activity: Activity
:param name: The value to assign to the trace activity's <see cref="Activity.name"/> property.
:type name: str
:param value: The value to assign to the trace activity's <see cref="Activity.value"/> property., defaults to None
:param value: object, optional
:param value_type: The value to assign to the trace activity's <see cref="Activity.value_type"/> property, defaults to None
:param value_type: str, optional
:param label: The value to assign to the trace activity's <see cref="Activity.label"/> property, defaults to None
:param label: str, optional
:return: The created trace activity.
:rtype: Activity
"""

from_property = (
ChannelAccount(
id=turn_activity.recipient.id, name=turn_activity.recipient.name
)
if turn_activity.recipient is not None
else ChannelAccount()
)
if value_type is None and value is not None:
value_type = type(value).__name__

reply = Activity(
type=ActivityTypes.trace,
timestamp=datetime.utcnow(),
from_property=from_property,
recipient=ChannelAccount(
id=turn_activity.from_property.id, name=turn_activity.from_property.name
),
reply_to_id=turn_activity.id,
service_url=turn_activity.service_url,
channel_id=turn_activity.channel_id,
conversation=ConversationAccount(
is_group=turn_activity.conversation.is_group,
id=turn_activity.conversation.id,
name=turn_activity.conversation.name,
),
name=name,
label=label,
value_type=value_type,
value=value,
)
return reply
58 changes: 58 additions & 0 deletions libraries/botbuilder-ai/botbuilder/ai/luis/intent_score.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

from typing import Dict


class IntentScore(object):
"""
Score plus any extra information about an intent.
"""

def __init__(self, score: float = None, properties: Dict[str, object] = {}):
self._score: float = score
self._properties: Dict[str, object] = properties

@property
def score(self) -> float:
"""Gets confidence in an intent.

:return: Confidence in an intent.
:rtype: float
"""

return self._score

@score.setter
def score(self, value: float) -> None:
"""Sets confidence in an intent.

:param value: Confidence in an intent.
:type value: float
:return:
:rtype: None
"""

self._score = value

@property
def properties(self) -> Dict[str, object]:
"""Gets any extra properties to include in the results.

:return: Any extra properties to include in the results.
:rtype: Dict[str, object]
"""

return self._properties

@properties.setter
def properties(self, value: Dict[str, object]) -> None:
"""Sets any extra properties to include in the results.

:param value: Any extra properties to include in the results.
:type value: Dict[str, object]
:return:
:rtype: None
"""

self._properties = value
160 changes: 160 additions & 0 deletions libraries/botbuilder-ai/botbuilder/ai/luis/luis_application.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license.

from pathlib import PurePosixPath
from typing import Tuple
from urllib.parse import ParseResult, parse_qs, unquote, urlparse, urlunparse
from uuid import UUID, uuid4


class LuisApplication(object):
"""
Data describing a LUIS application.
"""

def __init__(self, application_id: str, endpoint_key: str, endpoint: str):
"""Initializes a new instance of the <see cref="LuisApplication"/> class.

:param application_id: LUIS application ID.
:type application_id: str
:param endpoint_key: LUIS subscription or endpoint key.
:type endpoint_key: str
:param endpoint: LUIS endpoint to use like https://westus.api.cognitive.microsoft.com.
:type endpoint: str
:raises ValueError:
:raises ValueError:
:raises ValueError:
"""

_, valid = LuisApplication._try_parse_uuid4(application_id)
if not valid:
raise ValueError(f'"{application_id}" is not a valid LUIS application id.')

_, valid = LuisApplication._try_parse_uuid4(endpoint_key)
if not valid:
raise ValueError(f'"{endpoint_key}" is not a valid LUIS subscription key.')

if not endpoint or endpoint.isspace():
endpoint = "https://westus.api.cognitive.microsoft.com"

_, valid = LuisApplication._try_parse_url(endpoint)
if not valid:
raise ValueError(f'"{endpoint}" is not a valid LUIS endpoint.')

self._application_id = application_id
self._endpoint_key = endpoint_key
self._endpoint = endpoint

@classmethod
def from_application_endpoint(cls, application_endpoint: str):
"""Initializes a new instance of the <see cref="LuisApplication"/> class.

:param application_endpoint: LUIS application endpoint.
:type application_endpoint: str
:return:
:rtype: LuisApplication
"""
(application_id, endpoint_key, endpoint) = LuisApplication._parse(
application_endpoint
)
return cls(application_id, endpoint_key, endpoint)

@property
def application_id(self) -> str:
"""Gets LUIS application ID.

:return: LUIS application ID.
:rtype: str
"""

return self._application_id

@application_id.setter
def application_id(self, value: str) -> None:
"""Sets LUIS application ID.

:param value: LUIS application ID.
:type value: str
:return:
:rtype: None
"""

self._application_id = value

@property
def endpoint_key(self) -> str:
"""Gets LUIS subscription or endpoint key.

:return: LUIS subscription or endpoint key.
:rtype: str
"""

return self._endpoint_key

@endpoint_key.setter
def endpoint_key(self, value: str) -> None:
"""Sets LUIS subscription or endpoint key.

:param value: LUIS subscription or endpoint key.
:type value: str
:return:
:rtype: None
"""

self._endpoint_key = value

@property
def endpoint(self) -> str:
"""Gets LUIS endpoint like https://westus.api.cognitive.microsoft.com.

:return: LUIS endpoint where application is hosted.
:rtype: str
"""

return self._endpoint

@endpoint.setter
def endpoint(self, value: str) -> None:
"""Sets LUIS endpoint like https://westus.api.cognitive.microsoft.com.

:param value: LUIS endpoint where application is hosted.
:type value: str
:return:
:rtype: None
"""

self._endpoint = value

@staticmethod
def _parse(application_endpoint: str) -> Tuple[str, str, str]:
url, valid = LuisApplication._try_parse_url(application_endpoint)
if not valid:
raise ValueError(
f"{application_endpoint} is not a valid LUIS application endpoint."
)

segments = PurePosixPath(unquote(url.path)).parts
application_id = segments[-1] if segments else None
qs_parsed_result = parse_qs(url.query)
endpoint_key = qs_parsed_result.get("subscription-key", [None])[0]

parts_for_base_url = url.scheme, url.netloc, "", None, None, None
endpoint = urlunparse(parts_for_base_url)
return (application_id, endpoint_key, endpoint)

@staticmethod
def _try_parse_uuid4(uuid_string: str) -> Tuple[uuid4, bool]:
try:
uuid = UUID(uuid_string, version=4)
except (TypeError, ValueError):
return None, False

return uuid, True

@staticmethod
def _try_parse_url(url: str) -> Tuple[ParseResult, bool]:
try:
result = urlparse(url)
return result, True
except ValueError:
return None, False
Loading
0