dream
57 строк · 1.9 Кб
1import logging
2from typing import Callable
3
4from scenario.condition import get_current_user_id, graph
5from df_engine.core import Context, Actor
6
7logger = logging.getLogger(__name__)
8# ....
9
10
11def execute_response(
12ctx: Context,
13actor: Actor,
14) -> Context:
15"""Execute the callable response preemptively,
16so that slots can be filled"""
17processed_node = ctx.a_s.get("processed_node", ctx.a_s["next_node"])
18if callable(processed_node.response):
19processed_node.response = processed_node.response(ctx, actor)
20ctx.a_s["processed_node"] = processed_node
21
22return ctx
23
24
25def set_flag(label: str, value: bool = True) -> Callable:
26"""Sets a flag, modified coronavirus skill"""
27
28def set_flag_handler(ctx: Context, actor: Actor) -> Context:
29ctx.misc["flags"] = ctx.misc.get("flags", {})
30ctx.misc["flags"].update({label: value})
31return ctx
32
33return set_flag_handler
34
35
36def fill_responses_by_slots_from_graph():
37def fill_responses_by_slots_processing(
38ctx: Context,
39actor: Actor,
40*args,
41**kwargs,
42) -> Context:
43processed_node = ctx.a_s.get("processed_node", ctx.a_s["next_node"])
44user_id = get_current_user_id(ctx, actor)
45current_user_id = "User/" + user_id
46user_existing_entities = graph.get_properties_of_entity(entity_id=current_user_id)
47entity = "LIKE FOOD"
48entity_type = entity + "/Food"
49entity_with_id = user_existing_entities[entity_type][-1]
50logger.info(f"entity_with_id -- {entity_with_id}")
51slot_value = graph.get_properties_of_entity(entity_with_id)["substr"]
52logger.info(f"slot_value -- {slot_value}")
53processed_node.response = processed_node.response.replace("{" f"{entity}" "}", slot_value)
54ctx.a_s["processed_node"] = processed_node
55return ctx
56
57return fill_responses_by_slots_processing
58