Skip to content
Snippets Groups Projects
Commit 5744911f authored by Wojciech Jaworski's avatar Wojciech Jaworski
Browse files

Uporządkowanie katalogów

parent a320ad03
Branches
No related tags found
No related merge requests found
Showing
with 3702 additions and 4346 deletions
Uczenie modelu:
```
rasa train
```
Uruchamianie:
w jednym terminalu:
```
rasa run actions
```
w drugim terminalu:
```
export MAX_NUMBER_OF_PREDICTIONS=30
rasa shell
```
from typing import Any, Text, Dict, List, Union
import random
from rasa_sdk import Action, Tracker
from rasa_sdk.events import SlotSet
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.forms import FormValidationAction
def is_male_pesel(pesel: str) -> bool:
if len(pesel) < 2:
return False
else:
x = pesel[len(pesel)-2]
if x == '1' or x == '3' or x == '5' or x == '7' or x == '9':
return True
else:
return False
def is_female_pesel(pesel: str) -> bool:
if len(pesel) < 2:
return False
else:
x = pesel[len(pesel)-2]
if x == '0' or x == '2' or x == '4' or x == '6' or x == '8':
return True
else:
return False
class ActionFun(Action):
def name(self) -> Text:
return "action_Fun"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
return []
class ActionGetSexPeselClientSex(Action):
def name(self) -> Text:
return "action_get_sex_pesel_client_sex"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
if is_male_pesel(str(tracker.get_slot("pesel"))):
return [SlotSet("client_sex", "male")]
else:
if is_female_pesel(str(tracker.get_slot("pesel"))):
return [SlotSet("client_sex", "female")]
else:
return []
class ActionIsFeeCollectedCorrectlyIsFeeCollectedCorrectly(Action):
def name(self) -> Text:
return "action_is_fee_collected_correctly_is_fee_collected_correctly"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
if 0.5 >= random.uniform(0, 1):
return [SlotSet("is_fee_collected_correctly", "true")]
else:
return [SlotSet("is_fee_collected_correctly", "false")]
class ActionIsIdentificationSuccesfullIssue(Action):
def name(self) -> Text:
return "action_is_identification_succesfull_issue"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
if 0.857 >= random.uniform(0, 1):
return []
else:
return [SlotSet("issue", "verification_failure")]
class ActionIsPersonalIdValidIssue(Action):
def name(self) -> Text:
return "action_is_personal_id_valid_issue"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
if 0.833 >= random.uniform(0, 1):
return []
else:
return [SlotSet("issue", "expired_identity_document")]
class ActionSetExitNull(Action):
def name(self) -> Text:
return "action_set_exit-null"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
return [SlotSet("exit", None)]
class ActionSetStateAnswerToQuestionAboutBlockedAccount(Action):
def name(self) -> Text:
return "action_set_state-answer_to_question_about_blocked_account"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
return [SlotSet("state", "answer_to_question_about_blocked_account")]
class ActionSetStateAnswerToQuestionAboutFactors(Action):
def name(self) -> Text:
return "action_set_state-answer_to_question_about_factors"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
return [SlotSet("state", "answer_to_question_about_factors")]
class ActionSetStateAnswerToQuestionAboutFactors2(Action):
def name(self) -> Text:
return "action_set_state-answer_to_question_about_factors2"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
return [SlotSet("state", "answer_to_question_about_factors2")]
class ActionSetStateAnswerToQuestionAboutIssue(Action):
def name(self) -> Text:
return "action_set_state-answer_to_question_about_issue"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
return [SlotSet("state", "answer_to_question_about_issue")]
class ActionSetStateAnswerToQuestionAboutMessage(Action):
def name(self) -> Text:
return "action_set_state-answer_to_question_about_message"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
return [SlotSet("state", "answer_to_question_about_message")]
class ActionSetStateAnswerToQuestionAboutSpecifyingIssue(Action):
def name(self) -> Text:
return "action_set_state-answer_to_question_about_specifying_issue"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
return [SlotSet("state", "answer_to_question_about_specifying_issue")]
class ActionSetStateFinishWaiting(Action):
def name(self) -> Text:
return "action_set_state-finish_waiting"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
return [SlotSet("state", "finish_waiting")]
class ActionSetStateInitGoodbye(Action):
def name(self) -> Text:
return "action_set_state-init_goodbye"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
return [SlotSet("state", "init_goodbye")]
class ActionSetStateNull(Action):
def name(self) -> Text:
return "action_set_state-null"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
return [SlotSet("state", None)]
recipe: default.v1
language: pl
pipeline:
- name: WhitespaceTokenizer
- name: RegexFeaturizer
- name: LexicalSyntacticFeaturizer
- name: CountVectorsFeaturizer
- name: CountVectorsFeaturizer
analyzer: char_wb
min_ngram: 1
max_ngram: 4
- name: DIETClassifier
epochs: 100
constrain_similarities: true
- name: EntitySynonymMapper
- name: ResponseSelector
epochs: 100
constrain_similarities: true
- name: FallbackClassifier
threshold: 0.3
ambiguity_threshold: 0.1
policies:
- name: RulePolicy
This diff is collapsed.
This diff is collapsed.
version: "3.0"
stories:
This diff is collapsed.
# This files contains your custom actions which can be used to run
# custom Python code.
#
# See this guide on how to implement these action:
# https://rasa.com/docs/rasa/custom-actions
# This is a simple example for a custom action which utters "Hello World!"
from typing import Any, Text, Dict, List, Union
import random
from rasa_sdk import Action, Tracker
from rasa_sdk.events import SlotSet
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.forms import FormValidationAction
PESEL_CONTROL_WEIGHTS = [1, 3, 7, 9, 1, 3, 7, 9, 1, 3]
def calculate_control_digit(value: str) -> int:
return 10 - (sum([int(value[it]) * PESEL_CONTROL_WEIGHTS[it] for it in range(10)]) % 10)
def check_pesel(value: str) -> bool:
if len(value) != 11:
def is_male_pesel(pesel: str) -> bool:
if len(pesel) < 2:
return False
elif not value.isdigit():
else:
x = pesel[len(pesel)-2]
if x == '1' or x == '3' or x == '5' or x == '7' or x == '9':
return True
else:
return False
def is_female_pesel(pesel: str) -> bool:
if len(pesel) < 2:
return False
else:
#Poniższe sprawdzenie jest wyłączone na czas testowania systemu, aby nie trzeba było podawać prawdziwych numerów PESEL
# return calculate_control_digit(value) == int(value[10])
x = pesel[len(pesel)-2]
if x == '0' or x == '2' or x == '4' or x == '6' or x == '8':
return True
else:
return False
class ActionFun(Action):
def name(self) -> Text:
return "action_Fun"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
return []
class ActionGetSexPeselClientSex(Action):
def name(self) -> Text:
return "action_get_sex_pesel_client_sex"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
if is_male_pesel(str(tracker.get_slot("pesel"))):
return [SlotSet("client_sex", "male")]
else:
if is_female_pesel(str(tracker.get_slot("pesel"))):
return [SlotSet("client_sex", "female")]
else:
return []
def get_sex(pesel: str) -> str:
return 'female' if int(pesel[9]) % 2 == 0 else 'male'
class ActionIsFeeCollectedCorrectlyIsFeeCollectedCorrectly(Action):
def name(self) -> Text:
return "action_is_fee_collected_correctly_is_fee_collected_correctly"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
if 0.5 >= random.uniform(0, 1):
return [SlotSet("is_fee_collected_correctly", "true")]
else:
return [SlotSet("is_fee_collected_correctly", "false")]
class ValidateIdentityForm(FormValidationAction):
class ActionIsIdentificationSuccesfullIssue(Action):
def name(self) -> Text:
return "validate_identity_form"
return "action_is_identification_succesfull_issue"
def validate_client_pesel(
self,
pesel_value: Text,
dispatcher: CollectingDispatcher,
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any],
) -> Dict[Text, Any]:
"""Validate client_pesel value."""
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
if 0.857 >= random.uniform(0, 1):
return []
else:
return [SlotSet("issue", "verification_failure")]
class ActionIsPersonalIdValidIssue(Action):
def name(self) -> Text:
return "action_is_personal_id_valid_issue"
pesel_correct = check_pesel(pesel_value)
if pesel_correct:
return {"client_pesel": pesel_value, "is_client_pesel_correct": True, "client_sex": get_sex(pesel_value)}
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
if 0.833 >= random.uniform(0, 1):
return []
else:
# dispatcher.utter_message(response="utter_wrong_client_pesel")
return {"client_pesel": None, "is_client_pesel_correct": False}
# def run(self, dispatcher: CollectingDispatcher,
# tracker: Tracker,
# domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
# pesel_value = tracker.get_slot("client_pesel")
# pesel_correct = check_pesel(pesel_value)
# if pesel_correct:
# return [SlotSet("client_pesel_correct", True), SlotSet("client_sex", get_sex(pesel_value))]
# else:
# return [SlotSet("client_pesel_correct", False)]
return [SlotSet("issue", "expired_identity_document")]
class ActionSetExitNull(Action):
def name(self) -> Text:
return "action_set_exit-null"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
return [SlotSet("exit", None)]
class ActionSetStateAnswerToQuestionAboutBlockedAccount(Action):
def name(self) -> Text:
return "action_set_state-answer_to_question_about_blocked_account"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
return [SlotSet("state", "answer_to_question_about_blocked_account")]
class ActionSetStateAnswerToQuestionAboutFactors(Action):
def name(self) -> Text:
return "action_set_state-answer_to_question_about_factors"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
return [SlotSet("state", "answer_to_question_about_factors")]
class ActionSetStateAnswerToQuestionAboutFactors2(Action):
def name(self) -> Text:
return "action_set_state-answer_to_question_about_factors2"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
return [SlotSet("state", "answer_to_question_about_factors2")]
class ActionSetStateAnswerToQuestionAboutIssue(Action):
def name(self) -> Text:
return "action_set_state-answer_to_question_about_issue"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
return [SlotSet("state", "answer_to_question_about_issue")]
class ActionSetStateAnswerToQuestionAboutMessage(Action):
def name(self) -> Text:
return "action_set_state-answer_to_question_about_message"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
return [SlotSet("state", "answer_to_question_about_message")]
class ActionSetStateAnswerToQuestionAboutSpecifyingIssue(Action):
def name(self) -> Text:
return "action_set_state-answer_to_question_about_specifying_issue"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
return [SlotSet("state", "answer_to_question_about_specifying_issue")]
class ActionSetStateFinishWaiting(Action):
def name(self) -> Text:
return "action_set_state-finish_waiting"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
return [SlotSet("state", "finish_waiting")]
class ActionSetStateInitGoodbye(Action):
def name(self) -> Text:
return "action_set_state-init_goodbye"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
return [SlotSet("state", "init_goodbye")]
class ActionSetStateNull(Action):
def name(self) -> Text:
return "action_set_state-null"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
return [SlotSet("state", None)]
# The config recipe.
# https://rasa.com/docs/rasa/model-configuration/
recipe: default.v1
# Configuration for Rasa NLU.
# https://rasa.com/docs/rasa/nlu/components/
language: pl
pipeline:
# No configuration for the NLU pipeline was provided. The following default pipeline was used to train your model.
# If you'd like to customize it, uncomment and adjust the pipeline.
# See https://rasa.com/docs/rasa/tuning-your-model for more information.
- name: WhitespaceTokenizer
- name: RegexFeaturizer
- name: LexicalSyntacticFeaturizer
- name: CountVectorsFeaturizer
# - name: custom_components.herbert_featurizer.HerbertFeaturizer
# - name: custom_components.remote_component.RemoteComponent
# component_url: http://localhost:5000/process_component
# component_auth_token: test1234
- name: CountVectorsFeaturizer
analyzer: char_wb
min_ngram: 1
......@@ -32,19 +19,5 @@ pipeline:
- name: FallbackClassifier
threshold: 0.3
ambiguity_threshold: 0.1
# Configuration for Rasa Core.
# https://rasa.com/docs/rasa/core/policies/
policies:
# # No configuration for policies was provided. The following default policies were used to train your model.
# # If you'd like to customize them, uncomment and adjust the policies.
# # See https://rasa.com/docs/rasa/policies for more information.
# - name: MemoizationPolicy
# - name: RulePolicy
# - name: UnexpecTEDIntentPolicy
# max_history: 5
# epochs: 100
# - name: TEDPolicy
# max_history: 5
# epochs: 100
# constrain_similarities: true
- name: RulePolicy
This diff is collapsed.
This diff is collapsed.
version: "3.0"
stories:
#- story: simple_path
# steps:
# - intent: greet
# - action: utter_greet
# - story: stop form + continue
# steps:
# - intent: request_restaurant
# - action: restaurant_form
# - active_loop: restaurant_form
# - intent: stop
# - action: utter_ask_continue
# - intent: affirm
# - action: restaurant_form
# - active_loop: null
# - action: utter_submit
# - action: utter_slot_values
#
# - story: stop form + stop
# steps:
# - intent: request_restaurant
# - action: restaurant_form
# - active_loop: restaurant_form
# - intent: stop
# - action: utter_ask_continue
# - intent: deny
# - action: action_deactivate_loop
# - active_loop: null
This diff is collapsed.
File moved
# This files contains your custom actions which can be used to run
# custom Python code.
#
# See this guide on how to implement these action:
# https://rasa.com/docs/rasa/custom-actions
# This is a simple example for a custom action which utters "Hello World!"
from typing import Any, Text, Dict, List, Union
from rasa_sdk import Action, Tracker
from rasa_sdk.events import SlotSet
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.forms import FormValidationAction
PESEL_CONTROL_WEIGHTS = [1, 3, 7, 9, 1, 3, 7, 9, 1, 3]
def calculate_control_digit(value: str) -> int:
return 10 - (sum([int(value[it]) * PESEL_CONTROL_WEIGHTS[it] for it in range(10)]) % 10)
def check_pesel(value: str) -> bool:
if len(value) != 11:
return False
elif not value.isdigit():
return False
else:
#Poniższe sprawdzenie jest wyłączone na czas testowania systemu, aby nie trzeba było podawać prawdziwych numerów PESEL
# return calculate_control_digit(value) == int(value[10])
return True
def get_sex(pesel: str) -> str:
return 'female' if int(pesel[9]) % 2 == 0 else 'male'
class ValidateIdentityForm(FormValidationAction):
def name(self) -> Text:
return "validate_identity_form"
def validate_client_pesel(
self,
pesel_value: Text,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any],
) -> Dict[Text, Any]:
"""Validate client_pesel value."""
pesel_correct = check_pesel(pesel_value)
if pesel_correct:
return {"client_pesel": pesel_value, "is_client_pesel_correct": True, "client_sex": get_sex(pesel_value)}
else:
# dispatcher.utter_message(response="utter_wrong_client_pesel")
return {"client_pesel": None, "is_client_pesel_correct": False}
# def run(self, dispatcher: CollectingDispatcher,
# tracker: Tracker,
# domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
# pesel_value = tracker.get_slot("client_pesel")
# pesel_correct = check_pesel(pesel_value)
# if pesel_correct:
# return [SlotSet("client_pesel_correct", True), SlotSet("client_sex", get_sex(pesel_value))]
# else:
# return [SlotSet("client_pesel_correct", False)]
# The config recipe.
# https://rasa.com/docs/rasa/model-configuration/
recipe: default.v1
# Configuration for Rasa NLU.
# https://rasa.com/docs/rasa/nlu/components/
language: pl
pipeline:
# No configuration for the NLU pipeline was provided. The following default pipeline was used to train your model.
# If you'd like to customize it, uncomment and adjust the pipeline.
# See https://rasa.com/docs/rasa/tuning-your-model for more information.
- name: WhitespaceTokenizer
- name: RegexFeaturizer
- name: LexicalSyntacticFeaturizer
- name: CountVectorsFeaturizer
# - name: custom_components.herbert_featurizer.HerbertFeaturizer
# - name: custom_components.remote_component.RemoteComponent
# component_url: http://localhost:5000/process_component
# component_auth_token: test1234
- name: CountVectorsFeaturizer
analyzer: char_wb
min_ngram: 1
max_ngram: 4
- name: DIETClassifier
epochs: 100
constrain_similarities: true
- name: EntitySynonymMapper
- name: ResponseSelector
epochs: 100
constrain_similarities: true
- name: FallbackClassifier
threshold: 0.3
ambiguity_threshold: 0.1
# Configuration for Rasa Core.
# https://rasa.com/docs/rasa/core/policies/
policies:
# # No configuration for policies was provided. The following default policies were used to train your model.
# # If you'd like to customize them, uncomment and adjust the policies.
# # See https://rasa.com/docs/rasa/policies for more information.
# - name: MemoizationPolicy
# - name: RulePolicy
# - name: UnexpecTEDIntentPolicy
# max_history: 5
# epochs: 100
# - name: TEDPolicy
# max_history: 5
# epochs: 100
# constrain_similarities: true
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment