Skip to content
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

Fallback api fix #1056

Merged
merged 14 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 11 additions & 1 deletion kairon/api/app/routers/bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
BulkTrainingDataAddRequest, TrainingDataGeneratorStatusModel, StoryRequest,
SynonymRequest, RegexRequest,
StoryType, ComponentConfig, SlotRequest, DictData, LookupTablesRequest, Forms,
TextDataLowerCase, SlotMappingRequest, EventConfig, MultiFlowStoryRequest
TextDataLowerCase, SlotMappingRequest, EventConfig, MultiFlowStoryRequest, BotSettingsRequest
)
from kairon.events.definitions.data_importer import TrainingDataImporterEvent
from kairon.events.definitions.model_testing import ModelTestingEvent
Expand Down Expand Up @@ -1614,3 +1614,13 @@ async def get_bot_settings(
bot_settings = bot_settings.to_mongo().to_dict()
bot_settings.pop("_id")
return Response(data=bot_settings)


@router.put("/settings", response_model=Response)
async def update_bot_settings(
bot_settings: BotSettingsRequest,
current_user: User = Security(Authentication.get_current_user_and_bot, scopes=ADMIN_ACCESS)
):
"""Updates bot settings"""
MongoProcessor.edit_bot_settings(bot_settings.dict(), current_user.get_bot(), current_user.get_user())
return Response(message='Bot Settings updated')
34 changes: 17 additions & 17 deletions kairon/api/app/routers/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ async def visitor_hit_fallback(
Fetches the number of times the agent hit a fallback (ie. not able to answer) to user queries
"""
Utility.validate_from_date_and_to_date(from_date, to_date)
fallback_action, nlu_fallback_action = DataUtility.load_fallback_actions(current_user.get_bot())
fallback_intent = DataUtility.get_fallback_intent(current_user.get_bot(), current_user.get_user())
return Utility.trigger_history_server_request(
current_user.get_bot(),
f'/api/history/{current_user.get_bot()}/metrics/fallback?from_date={from_date}'
f'&to_date={to_date}&action_fallback={fallback_action}&nlu_fallback={nlu_fallback_action}'
f'/api/history/{current_user.get_bot()}/metrics/fallback?from_date={from_date}&to_date={to_date}'
f'&fallback_intent={fallback_intent}'
)


Expand Down Expand Up @@ -164,11 +164,11 @@ async def complete_conversations(
Fetches the number of successful conversations of the bot, which had no fallback
"""
Utility.validate_from_date_and_to_date(from_date, to_date)
fallback_action, nlu_fallback_action = DataUtility.load_fallback_actions(current_user.get_bot())
fallback_intent = DataUtility.get_fallback_intent(current_user.get_bot(), current_user.get_user())
return Utility.trigger_history_server_request(
current_user.get_bot(),
f'/api/history/{current_user.get_bot()}/metrics/conversation/success?from_date={from_date}'
f'&to_date={to_date}&action_fallback={fallback_action}&nlu_fallback={nlu_fallback_action}'
f'&to_date={to_date}&fallback_intent={fallback_intent}'
)


Expand Down Expand Up @@ -233,11 +233,11 @@ async def complete_conversation_trend(
Fetches the counts of successful conversations of the bot for previous months
"""
Utility.validate_from_date_and_to_date(from_date, to_date)
fallback_action, nlu_fallback_action = DataUtility.load_fallback_actions(current_user.get_bot())
fallback_intent = DataUtility.get_fallback_intent(current_user.get_bot(), current_user.get_user())
return Utility.trigger_history_server_request(
current_user.get_bot(),
f'/api/history/{current_user.get_bot()}/trends/conversations/success?from_date={from_date}&to_date={to_date}'
f'&action_fallback={fallback_action}&nlu_fallback={nlu_fallback_action}'
f'/api/history/{current_user.get_bot()}/trends/conversations/success?from_date={from_date}'
f'&to_date={to_date}&fallback_intent={fallback_intent}'
)


Expand Down Expand Up @@ -267,11 +267,11 @@ async def fallback_trend(
Fetches the fallback count of the bot for previous months
"""
Utility.validate_from_date_and_to_date(from_date, to_date)
fallback_action, nlu_fallback_action = DataUtility.load_fallback_actions(current_user.get_bot())
fallback_intent = DataUtility.get_fallback_intent(current_user.get_bot(), current_user.get_user())
return Utility.trigger_history_server_request(
current_user.get_bot(),
f'/api/history/{current_user.get_bot()}/trends/fallback?from_date={from_date}'
f'&to_date={to_date}&action_fallback={fallback_action}&nlu_fallback={nlu_fallback_action}'
f'/api/history/{current_user.get_bot()}/trends/fallback?from_date={from_date}&to_date={to_date}'
f'&fallback_intent={fallback_intent}'
)


Expand Down Expand Up @@ -437,11 +437,11 @@ async def fallback_dropoff(
Fetches the list of users that dropped off after encountering fallback
"""
Utility.validate_from_date_and_to_date(from_date, to_date)
fallback_action, nlu_fallback_action = DataUtility.load_fallback_actions(current_user.get_bot())
fallback_intent = DataUtility.get_fallback_intent(current_user.get_bot(), current_user.get_user())
return Utility.trigger_history_server_request(
current_user.get_bot(),
f'/api/history/{current_user.get_bot()}/metrics/fallback/dropoff?from_date={from_date}&to_date={to_date}'
f'&action_fallback={fallback_action}&nlu_fallback={nlu_fallback_action}'
f'/api/history/{current_user.get_bot()}/metrics/fallback/dropoff?from_date={from_date}'
f'&to_date={to_date}&fallback_intent={fallback_intent}'
)


Expand Down Expand Up @@ -469,11 +469,11 @@ async def unsuccessful_session_count(
Fetches the count of sessions that encountered a fallback for a particular user.
"""
Utility.validate_from_date_and_to_date(from_date, to_date)
fallback_action, nlu_fallback_action = DataUtility.load_fallback_actions(current_user.get_bot())
fallback_intent = DataUtility.get_fallback_intent(current_user.get_bot(), current_user.get_user())
return Utility.trigger_history_server_request(
current_user.get_bot(),
f'/api/history/{current_user.get_bot()}/metrics/sessions/unsuccessful?from_date={from_date}&to_date={to_date}'
f'&action_fallback={fallback_action}&nlu_fallback={nlu_fallback_action}'
f'/api/history/{current_user.get_bot()}/metrics/sessions/unsuccessful?from_date={from_date}'
f'&to_date={to_date}&fallback_intent={fallback_intent}'
)


Expand Down
16 changes: 16 additions & 0 deletions kairon/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from fastapi.security import OAuth2PasswordRequestForm

from kairon.exceptions import AppException
from rasa.shared.constants import DEFAULT_NLU_FALLBACK_INTENT_NAME
from kairon.shared.data.constant import EVENT_STATUS, SLOT_MAPPING_TYPE, SLOT_TYPE, ACCESS_ROLES, ACTIVITY_STATUS, \
INTEGRATION_STATUS, FALLBACK_MESSAGE, DEFAULT_NLU_FALLBACK_RESPONSE
from ..shared.actions.models import ActionParameterType, EvaluationType, DispatchType, DbQueryValueType, \
Expand Down Expand Up @@ -531,6 +532,21 @@ def validate_request_method(cls, v, values, **kwargs):
return v


class AnalyticsModel(BaseModel):
fallback_intent: str = DEFAULT_NLU_FALLBACK_INTENT_NAME

@validator('fallback_intent')
def validate_fallback_intent(cls, v, values, **kwargs):
from kairon.shared.utils import Utility
if Utility.check_empty_string(v):
raise ValueError("fallback_intent field cannot be empty")
return v


class BotSettingsRequest(BaseModel):
analytics: AnalyticsModel = AnalyticsModel()


class FeedbackRequest(BaseModel):
rating: float
scale: float = 5
Expand Down
Loading