Skip to content

Commit

Permalink
Merge pull request #591 from deeppavlov/dev
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
dilyararimovna committed Nov 11, 2023
2 parents 0015ded + c04af70 commit 3b8f2b7
Show file tree
Hide file tree
Showing 161 changed files with 3,149 additions and 695 deletions.
2 changes: 1 addition & 1 deletion annotators/IntentCatcherTransformers/test.sh
@@ -1,3 +1,3 @@
#!/bin/bash

python test.py
python tests/test.py
46 changes: 46 additions & 0 deletions annotators/IntentCatcherTransformers/tests/conftest.py
@@ -0,0 +1,46 @@
import json

import pytest

from os import getenv

INTENT_PHRASES_PATH = getenv("INTENT_PHRASES_PATH")


def pytest_addoption(parser):
parser.addoption("--uri", action="store", default="http://0.0.0.0")
parser.addoption("--port", action="store", default="8014")
parser.addoption("--handle", action="store", default="detect")


@pytest.fixture
def uri(request) -> str:
return request.config.getoption("--uri")


@pytest.fixture
def port(request) -> str:
return request.config.getoption("--port")


@pytest.fixture
def handle(request) -> str:
return request.config.getoption("--handle")


@pytest.fixture
def url(uri, port, handle) -> str:
return f"{uri}:{port}/{handle}"


@pytest.fixture
def tests():
if "RU" in INTENT_PHRASES_PATH and "commands" in INTENT_PHRASES_PATH:
tests = json.load(open("tests_commands_RU.json"))
elif "RU" in INTENT_PHRASES_PATH:
tests = json.load(open("tests_RU.json"))
elif "commands" in INTENT_PHRASES_PATH:
tests = json.load(open("tests_commands.json"))
else:
tests = json.load(open("tests.json"))
return tests
Expand Up @@ -2,23 +2,9 @@

import requests
import json
from os import getenv

INTENT_PHRASES_PATH = getenv("INTENT_PHRASES_PATH")
SERVICE_PORT = getenv("SERVICE_PORT")


def main_test():
url = f"http://0.0.0.0:{SERVICE_PORT}/detect"
if "RU" in INTENT_PHRASES_PATH and "commands" in INTENT_PHRASES_PATH:
tests = json.load(open("tests_commands_RU.json"))
elif "RU" in INTENT_PHRASES_PATH:
tests = json.load(open("tests_RU.json"))
elif "commands" in INTENT_PHRASES_PATH:
tests = json.load(open("tests_commands.json"))
else:
tests = json.load(open("tests.json"))

def test_intent_catcher(url: str, tests: dict):
for test in tests:
r = requests.post(url=url, json={"sentences": [[test["sentence"]]]})
assert r.ok
Expand All @@ -30,8 +16,3 @@ def main_test():
), print(f"TEST FAILED!\nTest: {test}\nResult:{json.dumps(data, indent=2)}")
else:
assert all([intent["detected"] == 0 for intent in data.values()]), f"test: {test}\nprediction: {data}"
print("Success")


if __name__ == "__main__":
main_test()
27 changes: 27 additions & 0 deletions annotators/NER/tests/conftest.py
@@ -0,0 +1,27 @@
import pytest


def pytest_addoption(parser):
parser.addoption("--uri", action="store", default="http://proxy.deeppavlov.ai")
parser.addoption("--port", action="store", default=8021)
parser.addoption("--handle", action="store", default="/ner")


@pytest.fixture
def uri(request) -> str:
return request.config.getoption("--uri")


@pytest.fixture
def port(request) -> int:
return request.config.getoption("--port")


@pytest.fixture
def handle(request) -> str:
return request.config.getoption("--handle")


@pytest.fixture
def url(uri, port, handle) -> str:
return f"{uri}:{port}/{handle}"
41 changes: 41 additions & 0 deletions annotators/NER/tests/test_ner.py
@@ -0,0 +1,41 @@
import json

import pytest

import sys
from os import path

import requests

PARENT_DIR = path.dirname(path.dirname(path.abspath(__file__)))
sys.path.append(PARENT_DIR)


@pytest.mark.parametrize(
"sentences, gold_result",
[
(
{
"last_utterances": [
["john peterson is my brother.", "he lives in New York."],
["my laptop was broken.", "could you show me the nearest store in Moscow where i can fix it."],
]
},
[
[
[{"confidence": 1, "end_pos": 2, "start_pos": 0, "text": "john peterson", "type": "PER"}],
[{"confidence": 1, "end_pos": 5, "start_pos": 3, "text": "New York", "type": "LOC"}],
],
[
[],
[{"confidence": 1, "end_pos": 9, "start_pos": 8, "text": "Moscow", "type": "LOC"}],
],
],
)
],
)
def test_ner(url: str, sentences: dict, gold_result: list):
response = requests.post(url, json=sentences, headers={"Content-Type": "application/json"})
result = json.loads(response.text)
assert response.status_code == 200
assert result == gold_result
20 changes: 20 additions & 0 deletions annotators/NER_deeppavlov/Dockerfile-test
@@ -0,0 +1,20 @@
FROM deeppavlov/deeppavlov:1.2.0-gpu

ARG CONFIG
ARG SERVICE_PORT
ARG SRC_DIR
ARG SED_ARG=" | "

ENV CONFIG=$CONFIG
ENV SERVICE_PORT=$SERVICE_PORT

COPY ./annotators/NER_deeppavlov/tests/requirements.txt /src/requirements.txt

RUN pip install --upgrade pip && \
pip install -r /src/requirements.txt

COPY $SRC_DIR /src

WORKDIR /src

CMD gunicorn --workers=1 --timeout 800 server:app -b 0.0.0.0:8021
2 changes: 1 addition & 1 deletion annotators/NER_deeppavlov/test.sh
@@ -1,4 +1,4 @@
#!/bin/bash


python test_server.py
python -m pytest tests/test_server.py
52 changes: 0 additions & 52 deletions annotators/NER_deeppavlov/test_server.py

This file was deleted.

27 changes: 27 additions & 0 deletions annotators/NER_deeppavlov/tests/conftest.py
@@ -0,0 +1,27 @@
import pytest


def pytest_addoption(parser):
parser.addoption("--uri", action="store", default="http://0.0.0.0")
parser.addoption("--port", action="store", default=8021)
parser.addoption("--handle", action="store", default="/ner")


@pytest.fixture
def uri(request) -> str:
return request.config.getoption("--uri")


@pytest.fixture
def port(request) -> int:
return request.config.getoption("--port")


@pytest.fixture
def handle(request) -> str:
return request.config.getoption("--handle")


@pytest.fixture
def url(uri, port, handle) -> str:
return f"{uri}:{port}/{handle}"
11 changes: 11 additions & 0 deletions annotators/NER_deeppavlov/tests/requirements.txt
@@ -0,0 +1,11 @@
sentry-sdk[flask]==0.14.1
flask==1.1.1
gunicorn==19.9.0
itsdangerous==2.0.1
jinja2<=3.0.3
Werkzeug<=2.0.3
transformers==4.6.0
datasets==1.11.0
huggingface-hub==0.0.8
pytest==7.4.2
allure-pytest==2.13.2
56 changes: 56 additions & 0 deletions annotators/NER_deeppavlov/tests/test_server.py
@@ -0,0 +1,56 @@
import allure
import pytest
import requests


@allure.description("""Test NER""")
@pytest.mark.parametrize(
"request_data, gold_results",
[
(
{
"last_utterances": [
["я видела ивана в москве"],
["Я видела Ивана в Москве"],
["i have heard about justin. he is in sahara desert"],
["I have heard about Justin. He is in Sahara Desert"],
[
"can john smith move forward for 15 meters, then for \
fifteen meters, and get back to las vegas then"
],
["я бы проехала на 30 метров вперед, а потом повернула на сорок пять градусов по часовой стрелке"],
[""],
]
},
[
[[]],
[[]],
[
[
{"start_pos": 4, "end_pos": 5, "type": "PER", "text": "justin", "confidence": 1},
{"start_pos": 9, "end_pos": 11, "type": "LOC", "text": "sahara desert", "confidence": 1},
]
],
[
[
{"start_pos": 4, "end_pos": 5, "type": "PER", "text": "Justin", "confidence": 1},
{"start_pos": 9, "end_pos": 11, "type": "LOC", "text": "Sahara Desert", "confidence": 1},
]
],
[
[
{"start_pos": 1, "end_pos": 3, "type": "PER", "text": "john smith", "confidence": 1},
{"start_pos": 6, "end_pos": 8, "type": "QUANTITY", "text": "15 meters", "confidence": 1},
{"start_pos": 11, "end_pos": 13, "type": "QUANTITY", "text": "fifteen meters", "confidence": 1},
{"start_pos": 18, "end_pos": 20, "type": "LOC", "text": "las vegas", "confidence": 1},
]
],
[[]],
[[]],
],
)
],
)
def test_ner(url: str, request_data: dict, gold_results: list):
result = requests.post(url, json=request_data).json()
assert result == gold_results
28 changes: 28 additions & 0 deletions annotators/SentSeg/Dockerfile-test
@@ -0,0 +1,28 @@
FROM python:3.7-slim

ARG DATA_URL=files.deeppavlov.ai/alexaprize_data/sentseg/elmo2.tar.gz
ARG MODEL_META_URL=files.deeppavlov.ai/alexaprize_data/sentseg/model.meta
ARG MODEL_DATA_URL=files.deeppavlov.ai/alexaprize_data/sentseg/model.data-00000-of-00001

WORKDIR /src
RUN mkdir /data /elmo2 tfhub_cache_dir

RUN apt-get update && \
apt-get install -y curl && \
curl -L $DATA_URL --output /tmp/elmo2.tar.gz && \
tar -xf /tmp/elmo2.tar.gz -C /elmo2 && \
rm /tmp/elmo2.tar.gz && \
curl -L $MODEL_META_URL --output /data/model.meta && \
curl -L $MODEL_DATA_URL --output /data/model.data-00000-of-00001

ENV TFHUB_CACHE_DIR tfhub_cache_dir

COPY tests/requirements.txt .
RUN pip install --upgrade pip && \
pip install -r requirements.txt && \
python -c "import nltk; nltk.download('punkt')"

COPY . .
COPY model.index /data/

CMD gunicorn --workers=1 server:app
11 changes: 0 additions & 11 deletions annotators/SentSeg/test.py

This file was deleted.

2 changes: 1 addition & 1 deletion annotators/SentSeg/test.sh
@@ -1,3 +1,3 @@
#!/bin/bash

python test.py
python -m pytest tests/test.py

0 comments on commit 3b8f2b7

Please sign in to comment.