Skip to content

Commit

Permalink
Feat/ru friendship skill (#120)
Browse files Browse the repository at this point in the history
* feat: add language parameters

* fix: black codestyle

* fix: codestyle

* fix: dff friendship ru

* fix: dff friendship ru

* fix: dff friendship ru

* fix: dff friendship ru уокротила реплики

* fix: dff friendship tests

* fix: dff friendship tests

* fix: languAGE FOR WIKI

* fix: language default value

* fix: language default value

* fix: language env var

* fix: use templates by language

* fix: ru templates

* fix: no lang env var in common

* fix: lang to ackn

* fizx: codestyle

* feat: default lang value

* fix: dummy for russian

* fix: no en acks

* fix: how are you ru

* fix: logs for response functions

* fix: logs for condition functions

* fix: ru version if what to talk about

* feat: ru tests

* fix: codestyle

* fix: ru condition to resp selector

* fix: ru condition to resp selector

* fix: logging level and configuration

* fix:  ascii in tests
  • Loading branch information
dilyararimovna committed Jun 28, 2022
1 parent 1da2d6d commit 986d5ce
Show file tree
Hide file tree
Showing 45 changed files with 1,611 additions and 234 deletions.
2 changes: 1 addition & 1 deletion annotators/BadlistedWordsDetector/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RUN pip install -r /src/requirements.txt
RUN spacy download en_core_web_sm
RUN spacy download ru_core_news_sm

ARG LANGUAGE
ARG LANGUAGE=EN
ENV LANGUAGE ${LANGUAGE}

COPY . /src/
Expand Down
4 changes: 2 additions & 2 deletions annotators/BadlistedWordsDetector/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


sentry_sdk.init(getenv("SENTRY_DSN"))
LANGUAGE = getenv("LANGUAGE", "ENGLISH")
LANGUAGE = getenv("LANGUAGE", "EN")

logging.basicConfig(format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO)
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -144,7 +144,7 @@ def collect_ngrams(utterance: Doc, max_ngram: int):
return all_ngrams


if LANGUAGE == "RUSSIAN":
if LANGUAGE == "RU":
nlp_pipeline = spacy.load("ru_core_news_sm", exclude=["senter", "ner"])
badlists_dir = Path("./badlists")
badlists_files = [f for f in badlists_dir.iterdir() if f.is_file() and "_ru" in f.name]
Expand Down
4 changes: 2 additions & 2 deletions annotators/BadlistedWordsDetector/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
def main():
url = "http://0.0.0.0:8018/badlisted_words"

LANGUAGE = getenv("LANGUAGE", "ENGLISH")
if LANGUAGE == "RUSSIAN":
LANGUAGE = getenv("LANGUAGE", "EN")
if LANGUAGE == "RU":
request_data = {
"sentences": ["пизда настала", "застрахуйте уже его", "пошел нахер!"],
}
Expand Down
2 changes: 1 addition & 1 deletion annotators/wiki_parser/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ARG CONFIG
ARG COMMIT
ARG PORT
ARG SRC_DIR
ARG LANGUAGE
ARG LANGUAGE=EN

ENV CONFIG=$CONFIG
ENV PORT=$PORT
Expand Down
2 changes: 1 addition & 1 deletion assistant_dists/dream/docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ services:
args:
SERVICE_PORT: 8008
SERVICE_NAME: dff_program_y_skill
LANGUAGE: ENGLISH
LANGUAGE: EN
context: .
dockerfile: ./skills/dff_program_y_skill/Dockerfile
command: gunicorn --workers=1 server:app -b 0.0.0.0:8008 --reload
Expand Down
8 changes: 6 additions & 2 deletions assistant_dists/dream_russian/docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:
args:
SERVICE_PORT: 8008
SERVICE_NAME: dff_program_y_skill
LANGUAGE: RUSSIAN
LANGUAGE: RU
context: .
dockerfile: ./skills/dff_program_y_skill/Dockerfile
command: gunicorn --workers=1 server:app -b 0.0.0.0:8008 --reload
Expand All @@ -32,6 +32,8 @@ services:
build:
context: .
dockerfile: ./response_selectors/convers_evaluation_based_selector/Dockerfile
args:
LANGUAGE: RU
command: flask run -h 0.0.0.0 -p 8009
environment:
- FLASK_APP=server
Expand Down Expand Up @@ -82,7 +84,7 @@ services:
env_file: [.env]
build:
args:
LANGUAGE: RUSSIAN
LANGUAGE: RU
context: annotators/BadlistedWordsDetector/
command: flask run -h 0.0.0.0 -p 8018
environment:
Expand Down Expand Up @@ -219,6 +221,7 @@ services:
args:
SERVICE_PORT: 8086
SERVICE_NAME: dff_friendship_skill # has to be the same with skill dir name
LANGUAGE: RU
context: .
dockerfile: ./skills/dff_friendship_skill/Dockerfile
command: gunicorn --workers=1 server:app -b 0.0.0.0:8086
Expand All @@ -239,6 +242,7 @@ services:
SERVICE_PORT: 8111
SERVICE_NAME: dff_wiki_skill
COMMIT: 5b99ac3392e8e178e2bb4f9b218d4ddb2ec2e242
LANGUAGE: RU
context: ./
dockerfile: ./skills/dff_wiki_skill/Dockerfile
command: gunicorn --workers=1 server:app -b 0.0.0.0:8111
Expand Down
13 changes: 10 additions & 3 deletions common/acknowledgements.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
GENERAL_ACKNOWLEDGEMENTS = {
"positive": ["Sounds cool! ", "Great! ", "Wonderful! ", "Cool!", "Nice!"],
"neutral": ["Okay. ", "Oh. ", "Huh. ", "Well. ", "Gotcha. ", "Aha. "],
"negative": ["Hmm... ", "I see.", "That's okay.", "Okay."],
"EN": {
"positive": ["Sounds cool! ", "Great! ", "Wonderful! ", "Cool!", "Nice!"],
"neutral": ["Okay. ", "Oh. ", "Huh. ", "Well. ", "Gotcha. ", "Aha. "],
"negative": ["Hmm... ", "I see.", "That's okay.", "Okay."],
},
"RU": {
"positive": ["Звучит круто! ", "Классно! ", "Великолепно! ", "Отлично!", "Замечательно!"],
"neutral": ["Окей. ", "Хм. ", "Ага. ", "Что ж. ", "Понятно. "],
"negative": ["Хмм... ", "Понимаю.", "Окей.", "Понятно."],
},
}
4 changes: 2 additions & 2 deletions common/dff/integration/condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def is_passive_user(ctx: Context, actor: Actor, history_len=2) -> bool:
return False


def get_not_used_and_save_sentiment_acknowledgement(ctx: Context, actor: Actor, sentiment=None):
def get_not_used_and_save_sentiment_acknowledgement(ctx: Context, actor: Actor, sentiment=None, lang="EN"):
if sentiment is None:
sentiment = int_ctx.get_human_sentiment(ctx, actor)
if is_yes_vars(ctx, actor) or is_no_vars(ctx, actor):
Expand All @@ -247,7 +247,7 @@ def get_not_used_and_save_sentiment_acknowledgement(ctx: Context, actor: Actor,
last_acknowledgements = shared_memory.get("last_acknowledgements", [])

ack = common_utils.get_not_used_template(
used_templates=last_acknowledgements, all_templates=GENERAL_ACKNOWLEDGEMENTS[sentiment]
used_templates=last_acknowledgements, all_templates=GENERAL_ACKNOWLEDGEMENTS[lang][sentiment]
)

used_acks = last_acknowledgements + [ack]
Expand Down
4 changes: 2 additions & 2 deletions common/dialogflow_framework/utils/condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def is_passive_user(vars, history_len=2):
return False


def get_not_used_and_save_sentiment_acknowledgement(vars):
def get_not_used_and_save_sentiment_acknowledgement(vars, lang="EN"):
sentiment = state_utils.get_human_sentiment(vars)
if is_yes_vars(vars) or is_no_vars(vars):
sentiment = "neutral"
Expand All @@ -259,7 +259,7 @@ def get_not_used_and_save_sentiment_acknowledgement(vars):
last_acknowledgements = shared_memory.get("last_acknowledgements", [])

ack = common_utils.get_not_used_template(
used_templates=last_acknowledgements, all_templates=GENERAL_ACKNOWLEDGEMENTS[sentiment]
used_templates=last_acknowledgements, all_templates=GENERAL_ACKNOWLEDGEMENTS[lang][sentiment]
)

used_acks = last_acknowledgements + [ack]
Expand Down
8 changes: 5 additions & 3 deletions common/emotion.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import re

from common.greeting import HOW_ARE_YOU_RESPONSES
from common.utils import get_emotions
from common.universal_templates import if_chat_about_particular_topic


POSITIVE_EMOTIONS = set(
[
"interest",
Expand Down Expand Up @@ -117,7 +119,7 @@
NOT_LONELINESS_TEMPLATE = re.compile(rf"{NOT_PATTERN} {ALONE_PATTERN}", re.IGNORECASE)
SAD_TEMPLATE = re.compile(rf"({SAD_PATTERN}|{POOR_ASR_PATTERN})", re.IGNORECASE)
NOT_SAD_TEMPLATE = re.compile(rf"{NOT_PATTERN} {SAD_PATTERN}", re.IGNORECASE)
BORING_TEMPLATE = re.compile(rf"(boring|bored)", re.IGNORECASE)
BORING_TEMPLATE = re.compile(r"(boring|bored)", re.IGNORECASE)
NOT_BORING_TEMPLATE = re.compile(rf"{NOT_PATTERN} (boring|bored)", re.IGNORECASE)
JOKE_REQUEST_TEMPLATE = re.compile(rf"{JOKE_PATTERN}", re.IGNORECASE)
NOT_JOKE_REQUEST_TEMPLATE = re.compile(rf"{NOT_PATTERN} {JOKE_PATTERN}", re.IGNORECASE)
Expand Down Expand Up @@ -179,7 +181,7 @@ def emo_advice_requested(uttr):


def skill_trigger_phrases():
return [HOW_DO_YOU_FEEL] + HOW_ARE_YOU_RESPONSES
return [HOW_DO_YOU_FEEL] + sum([HOW_ARE_YOU_RESPONSES[lang] for lang in ["RU", "EN"]], [])


def emotion_from_feel_answer(prev_bot_uttr, user_uttr):
Expand Down Expand Up @@ -207,7 +209,7 @@ def if_turn_on_emotion(user_utt, bot_uttr):
how_are_you = any(
[
how_are_you_response.lower() in bot_uttr.get("text", "").lower()
for how_are_you_response in HOW_ARE_YOU_RESPONSES
for how_are_you_response in sum([HOW_ARE_YOU_RESPONSES[lang] for lang in ["RU", "EN"]], [])
]
)
joke_request_detected = is_joke_requested(user_utt)
Expand Down
Loading

0 comments on commit 986d5ce

Please sign in to comment.