-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #554 from deeppavlov/dev
Release v1.10.0
- Loading branch information
Showing
94 changed files
with
3,212 additions
and
428 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM python:3.7.4 | ||
|
||
ARG SUMMARIZATION_REQUEST_TIMEOUT | ||
ENV SUMMARIZATION_REQUEST_TIMEOUT ${SUMMARIZATION_REQUEST_TIMEOUT} | ||
|
||
COPY ${WORK_DIR}/requirements.txt /src/requirements.txt | ||
RUN pip install -r /src/requirements.txt | ||
COPY ${WORK_DIR} /src | ||
WORKDIR /src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
sentry-sdk[flask]==0.14.1 | ||
flask==1.1.1 | ||
itsdangerous==2.0.1 | ||
gunicorn==19.9.0 | ||
requests==2.22.0 | ||
jinja2<=3.0.3 | ||
Werkzeug<=2.0.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import logging | ||
import time | ||
from os import getenv | ||
|
||
import sentry_sdk | ||
import requests | ||
from flask import Flask, jsonify, request | ||
|
||
|
||
sentry_sdk.init(getenv("SENTRY_DSN")) | ||
logging.basicConfig(format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO) | ||
logger = logging.getLogger(__name__) | ||
app = Flask(__name__) | ||
|
||
SUMMARIZATION_REQUEST_TIMEOUT = int(getenv("SUMMARIZATION_REQUEST_TIMEOUT")) | ||
SUMMARIZATION_SERVICE_URL = getenv("SUMMARIZATION_SERVICE_URL") | ||
logger.info(f"summarization-annotator considered summarizer: {SUMMARIZATION_SERVICE_URL}") | ||
|
||
|
||
def get_summary(dialog): | ||
summary = "" | ||
if len(dialog) != 11: | ||
logger.debug( | ||
f"summarization-annotator is not ready to summarize dialog as the length of unsummarized dialog is " | ||
f"{len(dialog)} != 11" | ||
) | ||
return summary | ||
|
||
logger.debug("summarization-annotator is ready to summarize dialog as the length of unsummarized dialog is 11") | ||
dialog = dialog[:6] | ||
for i in range(len(dialog)): | ||
if i % 2 == 0: | ||
dialog[i] = "User: " + dialog[i] | ||
else: | ||
dialog[i] = "Bot: " + dialog[i] | ||
dialog = ["\n".join(dialog)] | ||
logger.debug(f"summarization-annotator will summarize this: {dialog}") | ||
|
||
try: | ||
summary = requests.post( | ||
SUMMARIZATION_SERVICE_URL, | ||
json={"sentences": dialog}, | ||
timeout=SUMMARIZATION_REQUEST_TIMEOUT, | ||
).json()[0]["batch"][0] | ||
except Exception as exc: | ||
logger.exception(exc) | ||
sentry_sdk.capture_exception(exc) | ||
|
||
return summary | ||
|
||
|
||
@app.route("/respond", methods=["POST"]) | ||
def respond(): | ||
start_time = time.time() | ||
dialogs_batch = request.json.get("dialogs", []) | ||
summaries_batch = request.json.get("previous_summaries", []) | ||
summarization_attribute = [] | ||
|
||
for dialog, prev_summary in zip(dialogs_batch, summaries_batch): | ||
logger.debug(f"summarization-annotator received dialog: {dialog}") | ||
logger.debug(f"summarization-annotator received previous summary: {[prev_summary]}") | ||
result = prev_summary | ||
new_summary = get_summary(dialog) | ||
if new_summary: | ||
result = f"{result} {new_summary}".strip() | ||
summarization_attribute.append({"bot_attributes": {"summarized_dialog": result}}) | ||
logger.info(f"summarization-annotator output: {summarization_attribute}") | ||
|
||
total_time = time.time() - start_time | ||
logger.info(f"summarization-annotator exec time: {total_time:.2f}s") | ||
return jsonify(summarization_attribute) | ||
|
||
|
||
if __name__ == "__main__": | ||
app.run(debug=False, host="0.0.0.0", port=8058) |
4 changes: 4 additions & 0 deletions
4
annotators/summarization_annotator/service_configs/summarization-annotator/environment.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
SERVICE_PORT: 8058 | ||
SERVICE_NAME: summarization_annotator | ||
SUMMARIZATION_REQUEST_TIMEOUT: 10 | ||
FLASK_APP: server |
26 changes: 26 additions & 0 deletions
26
annotators/summarization_annotator/service_configs/summarization-annotator/service.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: summarization-annotator | ||
endpoints: | ||
- respond | ||
compose: | ||
env_file: | ||
- .env | ||
build: | ||
args: | ||
SERVICE_PORT: 8058 | ||
SERVICE_NAME: summarization_annotator | ||
SUMMARIZATION_REQUEST_TIMEOUT: 10 | ||
context: ./annotators/summarization_annotator/ | ||
command: flask run -h 0.0.0.0 -p 8058 | ||
environment: | ||
- FLASK_APP=server | ||
deploy: | ||
resources: | ||
limits: | ||
memory: 256M | ||
reservations: | ||
memory: 256M | ||
volumes: | ||
- ./annotators/summarization_annotator:/src | ||
ports: | ||
- 8058:8058 | ||
proxy: null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import requests | ||
from os import getenv | ||
|
||
|
||
SUMMARIZATION_SERVICE_URL = getenv("SUMMARIZATION_SERVICE_URL") | ||
|
||
|
||
def test_skill(): | ||
url = "http://0.0.0.0:8058/respond" | ||
|
||
if SUMMARIZATION_SERVICE_URL == "http://dialog-summarizer:8059/respond_batch": | ||
input_data = { | ||
"dialogs": [ | ||
[ | ||
"Hi, my name is Mark!", | ||
"Good morning, Mark! How can I assist you today?", | ||
"Let's talk about cooking.", | ||
"Sure! What is your favourite type of cuisine to cook or experiment with in the " "kitchen?", | ||
"I like a wide range of cooking styles, such as Italian, Chinese, French and many " "more.", | ||
"May I recommend you any Italian dish?", | ||
"No. Better tell me what do you have in mind?", | ||
"I've recently found a couple easy and healthy meals. How about cooking quinoa with " | ||
"turkey and broccoli?", | ||
"That sounds like a healthy and tasty meal! Quinoa is a great source of protein, and " | ||
"when paired with lean turkey and broccoli, it's a well-rounded and balanced meal.", | ||
"I am glad for you! I listened to my favorite music all day. " | ||
"Such a great thing you know! Has anything extraordinary happened today?", | ||
"I can tell you more about what made your day great or we can just chat?" "I'm happy to listen!", | ||
] | ||
], | ||
"previous_summaries": [""], | ||
} | ||
|
||
desired_output = [ | ||
"Bot wants to know what is Mark's favorite type of cuisine to cook. Mark likes Italian, " | ||
"Chinese, French and many other cooking styles." | ||
] | ||
else: | ||
input_data = { | ||
"dialogs": [ | ||
[ | ||
"Привет! У тебя есть хобби?", | ||
"Мое хобби — кулинария.", | ||
"Здорово! А ты любишь готовить?", | ||
"Ага, я могу отлично приготовить разные блюда.", | ||
"Ты собираешь кулинарные рецепты?", | ||
"Да, уже есть большая коллекция.", | ||
"А какая национальная кухня тебе нравится?", | ||
"Конечно, русская.", | ||
"Русские блюда очень оригинальные, вкусные и полезные.", | ||
"А что ты любишь готовить больше всего?", | ||
"Я люблю готовить мясные блюда. Так что приглашаю в гости!", | ||
] | ||
], | ||
"previous_summaries": [""], | ||
} | ||
|
||
desired_output = [ | ||
"У тебя есть хобби — кулинария, а у тебя есть большая коллекция кулинарных рецептов. Bot: Я " | ||
"собираю кулинарные рецепты, собираю кулинарные рецепты, собираю кулинарные рецепты." | ||
] | ||
|
||
result = requests.post(url, json=input_data).json() | ||
|
||
assert result == [{"bot_attributes": {"summarized_dialog": desired_output[0]}}] | ||
print("SUCCESS!") | ||
|
||
|
||
if __name__ == "__main__": | ||
test_skill() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
python test.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
version: '3.7' | ||
services: | ||
combined-classification: | ||
environment: | ||
DEVICE: cpu | ||
CUDA_VISIBLE_DEVICES: "" | ||
sentence-ranker: | ||
environment: | ||
DEVICE: cpu | ||
CUDA_VISIBLE_DEVICES: "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"host": "DB_HOST", | ||
"port": "DB_PORT", | ||
"name": "DB_NAME", | ||
"env": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# С такими volumes удобно дебажить, не нужно пересобирать контейнер каждый раз при изменении кода | ||
services: | ||
agent: | ||
volumes: | ||
- ".:/dp-agent" | ||
ports: | ||
- 4242:4242 | ||
sentseg: | ||
volumes: | ||
- "./annotators/SentSeg:/src" | ||
ports: | ||
- 8011:8011 | ||
ranking-based-response-selector: | ||
volumes: | ||
- "./response_selectors/ranking_based_response_selector:/src" | ||
- "./common:/src/common" | ||
ports: | ||
- 8002:8002 | ||
combined-classification: | ||
volumes: | ||
- "./common:/src/common" | ||
- "./annotators/combined_classification:/src" | ||
ports: | ||
- 8087:8087 | ||
sentence-ranker: | ||
volumes: | ||
- "./services/sentence_ranker:/src" | ||
- "~/.deeppavlov/cache:/root/.cache" | ||
ports: | ||
- 8128:8128 | ||
prompt-selector: | ||
volumes: | ||
- "./annotators/prompt_selector:/src" | ||
- "./common:/src/common" | ||
ports: | ||
- 8135:8135 | ||
openai-api-chatgpt: | ||
volumes: | ||
- "./services/openai_api_lm:/src" | ||
- "./common:/src/common" | ||
ports: | ||
- 8145:8145 | ||
dff-robot-prompted-skill: | ||
volumes: | ||
- "./skills/dff_template_prompted_skill:/src" | ||
- "./common:/src/common" | ||
ports: | ||
- 8179:8179 | ||
|
||
version: "3.7" |
Oops, something went wrong.