async def get_conversation_tracker_impl(request: Request, conversation_id: Text, user: Dict[Text, Any] = None): event_service = _event_service(request) if not _has_access_to_conversation(event_service, conversation_id, user): return rasa_x_utils.error(HTTPStatus.UNAUTHORIZED, "NoPermission", "Access denied") until_time = rasa_x_utils.float_arg(request, "until", None) since_time = rasa_x_utils.float_arg(request, "since", None) rasa_environment_query = rasa_x_utils.default_arg( request, "rasa_environment", DEFAULT_RASA_ENVIRONMENT) event_verbosity = _event_verbosity_from_request(request) exclude_leading_action_session_start = rasa_x_utils.bool_arg( request, "exclude_leading_action_session_start", False) tracker = event_service.get_tracker_with_message_flags( conversation_id, until_time, since_time, event_verbosity, rasa_environment_query, exclude_leading_action_session_start, ) if not tracker: return rasa_x_utils.error( HTTPStatus.NOT_FOUND, "ClientNotFound", f"Client for conversation_id '{conversation_id}' could not be found", ) requested_format = request.headers.get("Accept") if requested_format == "application/json": dispo = f"attachment;filename={conversation_id}-dump.json" return response.json( tracker, content_type="application/json", headers={"Content-Disposition": dispo}, ) elif requested_format == "text/markdown": _events = events.deserialise_events(tracker["events"]) story = Story.from_events(_events) exported = story.as_story_string(flat=True) return response.text( exported, content_type="text/markdown", headers={ "Content-Disposition": f"attachment;filename={conversation_id}-story.md" }, ) else: return response.json(tracker, headers={"Content-Disposition": "inline"})
async def get_intents(request, project_id): include_temporary_intents = utils.bool_arg(request, "is_temporary", True) included_fields = utils.fields_arg(request, { INTENT_SUGGESTIONS_KEY, INTENT_USER_GOAL_KEY, INTENT_EXAMPLES_KEY }) intents = _intent_service(request).get_intents( project_id, include_temporary_intents, included_fields) return response.json(intents, headers={"X-Total-Count": len(intents)})
async def update_domain(request: Request, user: Dict) -> HTTPResponse: rasa_x_utils.handle_deprecated_request_parameters( request, "store_templates", "store_responses") store_responses = utils.bool_arg(request, "store_responses", False) domain_yaml = rasa_core_utils.convert_bytes_to_string(request.body) try: updated_domain = DomainService(request[REQUEST_DB_SESSION_KEY] ).validate_and_store_domain_yaml( domain_yaml, store_responses=store_responses, username=user["username"]) except InvalidDomain as e: return rasa_x_utils.error(400, "InvalidDomainError", "Could not update domain.", e) return response.text(updated_domain)
async def get_stories(request): from rasa.core.domain import Domain text_query = rasa_x_utils.default_arg(request, "q", None) fields = rasa_x_utils.fields_arg(request, {"name", "annotation.user", "id"}) id_query = rasa_x_utils.list_arg(request, "id") distinct = rasa_x_utils.bool_arg(request, "distinct", True) stories = _story_service(request).fetch_stories(text_query, fields, id_query=id_query, distinct=distinct) content_type = request.headers.get("Accept") if content_type == "text/vnd.graphviz": project_id = rasa_x_utils.default_arg(request, "project_id", config.project_name) domain_dict = _domain_service(request).get_or_create_domain( project_id) domain = Domain.from_dict(domain_dict) visualization = await _story_service(request).visualize_stories( stories, domain) if visualization: return response.text(visualization) else: return rasa_x_utils.error( HTTPStatus.NOT_ACCEPTABLE, "VisualizationNotAvailable", "Cannot produce a visualization for the requested stories", ) elif content_type == "text/markdown": markdown = _story_service(request).get_stories_markdown(stories) return response.text( markdown, content_type="text/markdown", headers={ "Content-Disposition": "attachment;filename=stories.md" }, ) else: return response.json(stories, headers={"X-Total-Count": len(stories)})
async def checkout_branch(request: Request, project_id: Text, repository_id: int, branch_name: Text) -> HTTPResponse: """Change the current branch of the repository.""" git_service = _git(request, project_id, repository_id) discard_any_changes = utils.bool_arg(request, "force", False) try: git_service.checkout_branch(branch_name, force=discard_any_changes) return response.text("", 204) except ValueError as e: logger.debug(e) return error( 404, "RepositoryNotFound", f"Branch '{branch_name}' for repository with ID '{repository_id}' could not be found.", details=e, )
async def get_telemetry_config(request: Request) -> HTTPResponse: """Read the current telemetry configuration. Args: request: Received HTTP request. Returns: HTTP 200 response with telemetry and server information. """ user_groups = None if utils.bool_arg(request, "include_user_groups", False): user_groups = await telemetry.get_user_groups() user_id = telemetry.get_telemetry_id() return response.json({ "telemetry_enabled": telemetry.is_telemetry_enabled(), "user_groups": user_groups, "user_id": user_id, })
def _event_verbosity_from_request(request): if rasa_x_utils.bool_arg(request, "history", default=True): return EventVerbosity.ALL else: return EventVerbosity.AFTER_RESTART
def _get_clients(request: Request, user: Dict[Text, Any]) -> rasa_x_utils.QueryResult: role_service = _role_service(request) event_service = _event_service(request) sort_by_latest_event_time = rasa_x_utils.bool_arg( request, "sort_by_latest_event_time", True) sort_by_confidence = rasa_x_utils.bool_arg(request, "sort_by_confidence", True) in_training_data = rasa_x_utils.default_arg(request, "in_training_data", None) if in_training_data is not None: in_training_data = in_training_data.lower() == "true" include_interactive = rasa_x_utils.bool_arg(request, "interactive", True) start = rasa_x_utils.time_arg(request, "start", None) until = rasa_x_utils.time_arg(request, "until", None) minimum_confidence = rasa_x_utils.float_arg(request, "minimumConfidence") maximum_confidence = rasa_x_utils.float_arg(request, "maximumConfidence") minimum_nlu_confidence = rasa_x_utils.float_arg( request, "minimumNluConfidence") maximum_nlu_confidence = rasa_x_utils.float_arg( request, "maximumNluConfidence") minimum_user_messages = rasa_x_utils.int_arg(request, "minimumUserMessages") policies = rasa_x_utils.default_arg(request, "policies", None) intent_query = rasa_x_utils.default_arg(request, "intent", None) entity_query = rasa_x_utils.default_arg(request, "entity", None) text_query = rasa_x_utils.default_arg(request, "text", None) rasa_environment_query = rasa_x_utils.default_arg( request, "rasa_environment", DEFAULT_RASA_ENVIRONMENT) action_query = rasa_x_utils.default_arg(request, "action", None) flag_query = rasa_x_utils.bool_arg(request, "is_flagged", False) limit = rasa_x_utils.int_arg(request, "limit") offset = rasa_x_utils.int_arg(request, "offset", 0) slots = rasa_x_utils.list_arg(request, "slots") input_channels = rasa_x_utils.list_arg(request, "input_channels") conversations_tags_filter_any = rasa_x_utils.list_arg( request, TAGS_ANY_REQUEST_PARAMETER) exclude = ([user[USERNAME_KEY]] if rasa_x_utils.bool_arg( request, "exclude_self", False) else None) filter_created_by = None if not role_service.is_user_allowed_to_view_all_conversations(user): filter_created_by = user[USERNAME_KEY] return event_service.get_conversation_metadata_for_all_clients( start=start, until=until, minimum_confidence=minimum_confidence, maximum_confidence=maximum_confidence, minimum_nlu_confidence=minimum_nlu_confidence, maximum_nlu_confidence=maximum_nlu_confidence, minimum_user_messages=minimum_user_messages, policies=policies, in_training_data=in_training_data, intent_query=intent_query, entity_query=entity_query, action_query=action_query, sort_by_date=sort_by_latest_event_time, sort_by_confidence=sort_by_confidence, text_query=text_query, rasa_environment_query=rasa_environment_query, only_flagged=flag_query, include_interactive=include_interactive, exclude=exclude, limit=limit, offset=offset, conversations_tags_filter_any=conversations_tags_filter_any, slots=slots, input_channels=input_channels, created_by=filter_created_by, )