dream

Форк
0
57 строк · 1.9 Кб
1
import logging
2
from typing import Callable
3

4
from scenario.condition import get_current_user_id, graph
5
from df_engine.core import Context, Actor
6

7
logger = logging.getLogger(__name__)
8
# ....
9

10

11
def execute_response(
12
    ctx: Context,
13
    actor: Actor,
14
) -> Context:
15
    """Execute the callable response preemptively,
16
    so that slots can be filled"""
17
    processed_node = ctx.a_s.get("processed_node", ctx.a_s["next_node"])
18
    if callable(processed_node.response):
19
        processed_node.response = processed_node.response(ctx, actor)
20
    ctx.a_s["processed_node"] = processed_node
21

22
    return ctx
23

24

25
def set_flag(label: str, value: bool = True) -> Callable:
26
    """Sets a flag, modified coronavirus skill"""
27

28
    def set_flag_handler(ctx: Context, actor: Actor) -> Context:
29
        ctx.misc["flags"] = ctx.misc.get("flags", {})
30
        ctx.misc["flags"].update({label: value})
31
        return ctx
32

33
    return set_flag_handler
34

35

36
def fill_responses_by_slots_from_graph():
37
    def fill_responses_by_slots_processing(
38
        ctx: Context,
39
        actor: Actor,
40
        *args,
41
        **kwargs,
42
    ) -> Context:
43
        processed_node = ctx.a_s.get("processed_node", ctx.a_s["next_node"])
44
        user_id = get_current_user_id(ctx, actor)
45
        current_user_id = "User/" + user_id
46
        user_existing_entities = graph.get_properties_of_entity(entity_id=current_user_id)
47
        entity = "LIKE FOOD"
48
        entity_type = entity + "/Food"
49
        entity_with_id = user_existing_entities[entity_type][-1]
50
        logger.info(f"entity_with_id -- {entity_with_id}")
51
        slot_value = graph.get_properties_of_entity(entity_with_id)["substr"]
52
        logger.info(f"slot_value -- {slot_value}")
53
        processed_node.response = processed_node.response.replace("{" f"{entity}" "}", slot_value)
54
        ctx.a_s["processed_node"] = processed_node
55
        return ctx
56

57
    return fill_responses_by_slots_processing
58

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

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

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

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