Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/pip/tests/functional-tests/pip-ae…
Browse files Browse the repository at this point in the history
…d9f6bbcd
  • Loading branch information
tracyboehrer authored May 23, 2024
2 parents f46e0ae + 3521ce3 commit 50b25cc
Show file tree
Hide file tree
Showing 30 changed files with 148 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,11 @@ def payload_to_activity(payload: SlackPayload) -> Activity:
channel_id="slack",
conversation=ConversationAccount(id=payload.channel["id"], properties={}),
from_property=ChannelAccount(
id=payload.message.bot_id
if payload.message.bot_id
else payload.user["id"]
id=(
payload.message.bot_id
if payload.message.bot_id
else payload.user["id"]
)
),
recipient=ChannelAccount(),
channel_data=payload,
Expand Down
6 changes: 3 additions & 3 deletions libraries/botbuilder-ai/botbuilder/ai/luis/luis_recognizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,9 @@ def fill_luis_event_properties(

# Use the LogPersonalInformation flag to toggle logging PII data, text is a common example
if self.log_personal_information and turn_context.activity.text:
properties[
LuisTelemetryConstants.question_property
] = turn_context.activity.text
properties[LuisTelemetryConstants.question_property] = (
turn_context.activity.text
)

# Additional Properties can override "stock" properties.
if telemetry_properties is not None:
Expand Down
16 changes: 10 additions & 6 deletions libraries/botbuilder-ai/botbuilder/ai/luis/luis_recognizer_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ async def recognizer_internal(self, turn_context: TurnContext):
staging=self.luis_recognizer_options_v2.staging,
spell_check=self.luis_recognizer_options_v2.spell_check,
bing_spell_check_subscription_key=self.luis_recognizer_options_v2.bing_spell_check_subscription_key,
log=self.luis_recognizer_options_v2.log
if self.luis_recognizer_options_v2.log is not None
else True,
log=(
self.luis_recognizer_options_v2.log
if self.luis_recognizer_options_v2.log is not None
else True
),
)

recognizer_result: RecognizerResult = RecognizerResult(
Expand All @@ -65,9 +67,11 @@ async def recognizer_internal(self, turn_context: TurnContext):
entities=LuisUtil.extract_entities_and_metadata(
luis_result.entities,
luis_result.composite_entities,
self.luis_recognizer_options_v2.include_instance_data
if self.luis_recognizer_options_v2.include_instance_data is not None
else True,
(
self.luis_recognizer_options_v2.include_instance_data
if self.luis_recognizer_options_v2.include_instance_data is not None
else True
),
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,11 @@ def _build_url(self):
uri += "/slots/%s/predict" % (self.luis_recognizer_options_v3.slot)

params = "?verbose=%s&show-all-intents=%s&log=%s" % (
"true"
if self.luis_recognizer_options_v3.include_instance_data
else "false",
(
"true"
if self.luis_recognizer_options_v3.include_instance_data
else "false"
),
"true" if self.luis_recognizer_options_v3.include_all_intents else "false",
"true" if self.luis_recognizer_options_v3.log else "false",
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,9 @@ async def __call_generate_answer(self, step_context: WaterfallStepContext):
dialog_options.options.context = QnARequestContext()

# Storing the context info
step_context.values[
QnAMakerDialog.PROPERTY_CURRENT_QUERY
] = step_context.context.activity.text
step_context.values[QnAMakerDialog.PROPERTY_CURRENT_QUERY] = (
step_context.context.activity.text
)

# -Check if previous context is present, if yes then put it with the query
# -Check for id if query is present in reverse index.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@


class RankerTypes:

"""Default Ranker Behaviour. i.e. Ranking based on Questions and Answer."""

DEFAULT = "Default"
Expand Down
6 changes: 3 additions & 3 deletions libraries/botbuilder-ai/botbuilder/ai/qna/qnamaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ async def fill_qna_event(
properties: Dict[str, str] = dict()
metrics: Dict[str, float] = dict()

properties[
QnATelemetryConstants.knowledge_base_id_property
] = self._endpoint.knowledge_base_id
properties[QnATelemetryConstants.knowledge_base_id_property] = (
self._endpoint.knowledge_base_id
)

text: str = turn_context.activity.text
user_name: str = turn_context.activity.from_property.name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ async def call_train(self, feedback_records: List[FeedbackRecord]):
await self._query_train(feedback_records)

async def _query_train(self, feedback_records: List[FeedbackRecord]):
url: str = f"{ self._endpoint.host }/knowledgebases/{ self._endpoint.knowledge_base_id }/train"
url: str = (
f"{ self._endpoint.host }/knowledgebases/{ self._endpoint.knowledge_base_id }/train"
)
payload_body = TrainRequestBody(feedback_records=feedback_records)
http_request_helper = HttpRequestUtils(self._http_client)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,11 @@ async def create_conversation(
name=ActivityEventNames.create_conversation,
channel_id=channel_id,
service_url=service_url,
id=resource_response.activity_id
if resource_response.activity_id
else str(uuid.uuid4()),
id=(
resource_response.activity_id
if resource_response.activity_id
else str(uuid.uuid4())
),
conversation=ConversationAccount(
id=resource_response.id,
tenant_id=parameters.tenant_id,
Expand Down
12 changes: 11 additions & 1 deletion libraries/botbuilder-core/botbuilder/core/cloud_adapter_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ async def continue_conversation( # pylint: disable=arguments-differ
self,
reference: ConversationReference,
callback: Callable,
bot_app_id: str,
bot_app_id: str = None, # pylint: disable=unused-argument
claims_identity: ClaimsIdentity = None, # pylint: disable=unused-argument
audience: str = None, # pylint: disable=unused-argument
):
"""
Sends a proactive message to a conversation.
Expand All @@ -166,6 +168,14 @@ async def continue_conversation( # pylint: disable=arguments-differ
and is generally found in the `MicrosoftAppId` parameter in `config.py`.
:type bot_app_id: :class:`typing.str`
"""
if claims_identity:
return await self.continue_conversation_with_claims(
claims_identity=claims_identity,
reference=reference,
audience=audience,
logic=callback,
)

return await self.process_proactive(
self.create_claims_identity(bot_app_id),
get_continuation_activity(reference),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ async def _trace_state(self, context: TurnContext) -> Any:
)

if self.conversation_state:
bot_state[
"conversation_state"
] = InspectionMiddleware._get_serialized_context(
self.conversation_state, context
bot_state["conversation_state"] = (
InspectionMiddleware._get_serialized_context(
self.conversation_state, context
)
)

await self._invoke_send(context, session, from_state(bot_state))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ async def on_delete_activity(
)

async def callback(turn_context: TurnContext):
turn_context.turn_state[
self.SKILL_CONVERSATION_REFERENCE_KEY
] = skill_conversation_reference
turn_context.turn_state[self.SKILL_CONVERSATION_REFERENCE_KEY] = (
skill_conversation_reference
)
await turn_context.delete_activity(activity_id)

await self._adapter.continue_conversation(
Expand All @@ -160,9 +160,9 @@ async def on_update_activity(

async def callback(turn_context: TurnContext):
nonlocal resource_response
turn_context.turn_state[
self.SKILL_CONVERSATION_REFERENCE_KEY
] = skill_conversation_reference
turn_context.turn_state[self.SKILL_CONVERSATION_REFERENCE_KEY] = (
skill_conversation_reference
)
activity.apply_conversation_reference(
skill_conversation_reference.conversation_reference
)
Expand Down Expand Up @@ -217,9 +217,9 @@ async def _process_activity(

async def callback(context: TurnContext):
nonlocal resource_response
context.turn_state[
SkillHandler.SKILL_CONVERSATION_REFERENCE_KEY
] = skill_conversation_reference
context.turn_state[SkillHandler.SKILL_CONVERSATION_REFERENCE_KEY] = (
skill_conversation_reference
)

TurnContext.apply_conversation_reference(
activity, skill_conversation_reference.conversation_reference
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ async def fill_receive_event_properties(
BotTelemetryClient.track_event method for the BotMessageReceived event.
"""
properties = {
TelemetryConstants.FROM_ID_PROPERTY: activity.from_property.id
if activity.from_property
else None,
TelemetryConstants.FROM_ID_PROPERTY: (
activity.from_property.id if activity.from_property else None
),
TelemetryConstants.CONVERSATION_NAME_PROPERTY: activity.conversation.name,
TelemetryConstants.LOCALE_PROPERTY: activity.locale,
TelemetryConstants.RECIPIENT_ID_PROPERTY: activity.recipient.id,
Expand All @@ -179,9 +179,9 @@ async def fill_receive_event_properties(
and activity.from_property.name
and activity.from_property.name.strip()
):
properties[
TelemetryConstants.FROM_NAME_PROPERTY
] = activity.from_property.name
properties[TelemetryConstants.FROM_NAME_PROPERTY] = (
activity.from_property.name
)
if activity.text and activity.text.strip():
properties[TelemetryConstants.TEXT_PROPERTY] = activity.text
if activity.speak and activity.speak.strip():
Expand Down Expand Up @@ -224,9 +224,9 @@ async def fill_send_event_properties(
activity.attachments
)
if activity.from_property.name and activity.from_property.name.strip():
properties[
TelemetryConstants.FROM_NAME_PROPERTY
] = activity.from_property.name
properties[TelemetryConstants.FROM_NAME_PROPERTY] = (
activity.from_property.name
)
if activity.text and activity.text.strip():
properties[TelemetryConstants.TEXT_PROPERTY] = activity.text
if activity.speak and activity.speak.strip():
Expand Down
9 changes: 8 additions & 1 deletion libraries/botbuilder-core/botbuilder/core/turn_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from copy import copy, deepcopy
from datetime import datetime
from typing import List, Callable, Union, Dict
from botframework.connector import Channels
from botbuilder.schema import (
Activity,
ActivityTypes,
Expand Down Expand Up @@ -328,7 +329,13 @@ def get_conversation_reference(activity: Activity) -> ConversationReference:
:return:
"""
return ConversationReference(
activity_id=activity.id,
activity_id=(
activity.id
if activity.type != ActivityTypes.conversation_update
and activity.channel_id != Channels.direct_line
and activity.channel_id != Channels.webchat
else None
),
user=copy(activity.from_property),
bot=copy(activity.recipient),
conversation=copy(activity.conversation),
Expand Down
6 changes: 3 additions & 3 deletions libraries/botbuilder-core/tests/skills/test_skill_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ def setUpClass(cls):

cls._claims_identity.claims[AuthenticationConstants.AUDIENCE_CLAIM] = cls.bot_id
cls._claims_identity.claims[AuthenticationConstants.APP_ID_CLAIM] = cls.skill_id
cls._claims_identity.claims[
AuthenticationConstants.SERVICE_URL_CLAIM
] = "http://testbot.com/api/messages"
cls._claims_identity.claims[AuthenticationConstants.SERVICE_URL_CLAIM] = (
"http://testbot.com/api/messages"
)
cls._conversation_reference = ConversationReference(
conversation=ConversationAccount(id=str(uuid4())),
service_url="http://testbot.com/api/messages",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -595,9 +595,9 @@ async def test_on_teams_members_added_activity(self):
mock_connector_client = await SimpleAdapter.create_connector_client(
self, turn_context.activity.service_url
)
turn_context.turn_state[
BotAdapter.BOT_CONNECTOR_CLIENT_KEY
] = mock_connector_client
turn_context.turn_state[BotAdapter.BOT_CONNECTOR_CLIENT_KEY] = (
mock_connector_client
)

# Act
bot = TestingTeamsActivityHandler()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ async def get_sign_in_resource(
turn_context,
settings.oath_app_credentials,
settings.connection_name,
turn_context.activity.from_property.id
if turn_context.activity and turn_context.activity.from_property
else None,
(
turn_context.activity.from_property.id
if turn_context.activity and turn_context.activity.from_property
else None
),
)

raise TypeError("OAuthPrompt is not supported by the current adapter")
Expand All @@ -78,9 +80,11 @@ async def sign_out_user(turn_context: TurnContext, settings: OAuthPromptSettings
return await turn_context.adapter.sign_out_user(
turn_context,
settings.connection_name,
turn_context.activity.from_property.id
if turn_context.activity and turn_context.activity.from_property
else None,
(
turn_context.activity.from_property.id
if turn_context.activity and turn_context.activity.from_property
else None
),
settings.oath_app_credentials,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,9 @@ def __set_exception_context_data(self, exception: Exception):
current_dc = current_dc.parent

exception.data[type(self).__name__] = {
"active_dialog": None
if self.active_dialog is None
else self.active_dialog.id,
"active_dialog": (
None if self.active_dialog is None else self.active_dialog.id
),
"parent": None if self.parent is None else self.parent.active_dialog.id,
"stack": self.stack,
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ async def _internal_run(
# get the DialogStateManager configuration
dialog_state_manager = DialogStateManager(dialog_context)
await dialog_state_manager.load_all_scopes()
dialog_context.context.turn_state[
dialog_state_manager.__class__.__name__
] = dialog_state_manager
dialog_context.context.turn_state[dialog_state_manager.__class__.__name__] = (
dialog_state_manager
)

# Loop as long as we are getting valid OnError handled we should continue executing the actions for the turn.

Expand Down Expand Up @@ -130,9 +130,11 @@ async def __inner_run(
type=ActivityTypes.end_of_conversation,
value=result.result,
locale=turn_context.activity.locale,
code=EndOfConversationCodes.completed_successfully
if result.status == DialogTurnStatus.Complete
else EndOfConversationCodes.user_cancelled,
code=(
EndOfConversationCodes.completed_successfully
if result.status == DialogTurnStatus.Complete
else EndOfConversationCodes.user_cancelled
),
)
await turn_context.send_activity(activity)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,11 @@ async def handle_skill_on_turn(
type=ActivityTypes.end_of_conversation,
value=turn_result.result,
locale=turn_context.activity.locale,
code=EndOfConversationCodes.completed_successfully
if turn_result.status == DialogTurnStatus.Complete
else EndOfConversationCodes.user_cancelled,
code=(
EndOfConversationCodes.completed_successfully
if turn_result.status == DialogTurnStatus.Complete
else EndOfConversationCodes.user_cancelled
),
)
await turn_context.send_activity(activity)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ def __init__(
self._configuration.path_resolvers.append(path_resolver)

# cache for any other new dialog_state_manager instances in this turn.
dialog_context.context.turn_state[
self._configuration.__class__.__name__
] = self._configuration
dialog_context.context.turn_state[self._configuration.__class__.__name__] = (
self._configuration
)

def __len__(self) -> int:
"""
Expand Down
Loading

0 comments on commit 50b25cc

Please sign in to comment.