dream

Форк
0
58 строк · 2.5 Кб
1
import requests
2
import json
3
from copy import deepcopy
4

5

6
def get_input_json(fname):
7
    with open(fname, "r") as f:
8
        res = json.load(f)
9
    return {"dialogs": res}
10

11

12
def slice_(input_data, i):
13
    tmp_data = deepcopy(input_data)
14
    tmp_data["dialogs"][0]["utterances"] = input_data["dialogs"][0]["utterances"][:i]
15
    tmp_data["dialogs"][0]["human_utterances"] = []
16
    tmp_data["dialogs"][0]["bot_utterances"] = []
17

18
    for uttr in tmp_data["dialogs"][0]["utterances"]:
19
        if uttr["user"]["user_type"] == "human":
20
            tmp_data["dialogs"][0]["human_utterances"].append(deepcopy(uttr))
21
        else:
22
            tmp_data["dialogs"][0]["bot_utterances"].append(deepcopy(uttr))
23

24
    return tmp_data
25

26

27
def main_test():
28
    url = "http://0.0.0.0:8052/respond"
29
    input_data = get_input_json("test_dialog.json")
30
    sliced_data = [slice_(input_data, i) for i in range(3, 21, 2)]
31
    responses = [requests.post(url, json=tmp).json()[0][0] for tmp in sliced_data]
32
    gold_phrases = [
33
        "i mainly like marvel. apparently they published a generic comic book so they could trade mark "
34
        "super-hero and super-villian.",
35
        "i know right, it's strange that was even an option. dc actually stands for detective comics. "
36
        "i didn't know that.",
37
        "they said to make the name redundant. so weird. " "i thought stan lee was an amazing human, did you like him?",
38
        "i would have liked to as well. "
39
        "i never thought about when the marvel cinematic universe took place,"
40
        " it takes place in earth-199999. not sure what that means "
41
        "but it's a multiverse and different from the original earth-616.",
42
        "oh that makes sense. have you ever been to the michigan state library? "
43
        "it has the largest comic book collection in the world.",
44
        "wow, that is cool! i wonder how many actually exist.",
45
        "i never really got into the batman comics but i do love the movies.",
46
        "i enjoyed the animated series as well as some of the new ones, " "my kids and i enjoy teen titans go!",
47
        "i heard about titans not streaming on dc universe's streaming service but haven't watched it. "
48
        "have you seen it yet?",
49
        "oh well, maybe it'll be good, if not kids still have teen titans! haha, well it was nice talking "
50
        "to you, i've gotta run now, bye!",
51
    ]
52

53
    for response, gold_phrase in zip(responses, gold_phrases):
54
        assert response == gold_phrase, print(f"Expect: {gold_phrase}. Got: {response}.")
55

56

57
if __name__ == "__main__":
58
    main_test()
59

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.