diff --git a/backend/chatsky_ui/api/api_v1/api.py b/backend/chatsky_ui/api/api_v1/api.py index 4461812c..215a4fee 100644 --- a/backend/chatsky_ui/api/api_v1/api.py +++ b/backend/chatsky_ui/api/api_v1/api.py @@ -7,5 +7,7 @@ api_router.include_router(config.router, prefix="/".join([settings.API_V1_STR, "config"]), tags=["config"]) api_router.include_router(flows.router, prefix="/".join([settings.API_V1_STR, "flows"]), tags=["flows"]) -api_router.include_router(chatsky_services.router, prefix="/".join([settings.API_V1_STR, "services"]), tags=["services"]) +api_router.include_router( + chatsky_services.router, prefix="/".join([settings.API_V1_STR, "services"]), tags=["services"] +) api_router.include_router(bot.router, prefix="/".join([settings.API_V1_STR, "bot"]), tags=["bot"]) diff --git a/backend/chatsky_ui/clients/chatsky_client.py b/backend/chatsky_ui/clients/chatsky_client.py index 34efc0a6..0822f707 100644 --- a/backend/chatsky_ui/clients/chatsky_client.py +++ b/backend/chatsky_ui/clients/chatsky_client.py @@ -4,9 +4,9 @@ from chatsky.core import script_parsing AUTO_COMPLETION_MAP = { - "ExactMatch": 'await cnd.ExactMatch("hello")(ctx)', # TODO: delete Message as it's redundant in the new version + "ExactMatch": 'await cnd.ExactMatch("hello")(ctx)', # TODO: delete Message as it's redundant in the new version "Regexp": 'await cnd.Regexp("how are you")(ctx)', - "Any": 'cnd.Any([hi_lower_case_condition, cnd.ExactMatch(hello)])(ctx)', # TODO: the same + "Any": "cnd.Any([hi_lower_case_condition, cnd.ExactMatch(hello)])(ctx)", # TODO: the same "All": 'cnd.All([cnd.Regexp("talk"), cnd.Regexp("about.*music")])(ctx)', } diff --git a/backend/chatsky_ui/services/condition_finder.py b/backend/chatsky_ui/services/condition_finder.py index 96371bc7..a60b9980 100644 --- a/backend/chatsky_ui/services/condition_finder.py +++ b/backend/chatsky_ui/services/condition_finder.py @@ -6,6 +6,7 @@ logger = get_logger(__name__) + class ServiceReplacer(NodeTransformer): def __init__(self, new_services: List[str]): self.new_services_classes = self._get_classes_def(new_services) diff --git a/backend/chatsky_ui/services/json_converter.py b/backend/chatsky_ui/services/json_converter.py index f4b1bf78..f487c02e 100644 --- a/backend/chatsky_ui/services/json_converter.py +++ b/backend/chatsky_ui/services/json_converter.py @@ -22,6 +22,7 @@ PRE_TRANSITION = "PRE_TRANSITION" + def _get_db_paths(build_id: int) -> Tuple[Path, Path, Path, Path]: """Get paths to frontend graph, chatsky script, and chatsky custom conditions files.""" frontend_graph_path = settings.frontend_flows_path @@ -74,7 +75,7 @@ def _convert_slots(slots: dict) -> dict: if slot_type != "GroupSlot": group_slot[slot_name].update({f"chatsky.slots.{slot_type}": {k: v for k, v in slot_values.items()}}) else: - group_slot[slot_name] = _convert_slots(slot_values) + group_slot[slot_name] = _convert_slots(slot_values) return dict(group_slot) script["slots"] = _convert_slots(flow_graph["slots"]) @@ -82,7 +83,6 @@ def _convert_slots(slots: dict) -> dict: return nodes, script - def _get_condition(nodes: dict, edge: DictConfig) -> Optional[DictConfig]: """Get node's condition from `nodes` according to `edge` info.""" return next( @@ -93,6 +93,7 @@ def _get_condition(nodes: dict, edge: DictConfig) -> Optional[DictConfig]: def _add_transitions(nodes: dict, edge: DictConfig, condition: DictConfig, slots: DictConfig) -> None: """Add transitions to a node according to `edge` and `condition`.""" + def _get_slot(slots, id_): if not slots: return "" @@ -116,7 +117,7 @@ def _get_slot(slots, id_): slot = _get_slot(slots, id_=condition.data.slot) converted_cnd = {"chatsky.conditions.slots.SlotsExtracted": slot} nodes[edge.source][PRE_TRANSITION].update({slot: {"chatsky.processing.slots.Extract": slot}}) - #TODO: elif condition["type"] == "chatsky": + # TODO: elif condition["type"] == "chatsky": else: raise ValueError(f"Unknown condition type: {condition['type']}") @@ -189,7 +190,7 @@ async def update_responses_lines(nodes: dict) -> Tuple[dict, List[str]]: for message in response.data: if "text" in message: chatsky_responses.append({"chatsky.Message": {"text": message["text"]}}) - else: #TODO: check: are you sure that you can use only "text" type inside a choice? + else: # TODO: check: are you sure that you can use only "text" type inside a choice? raise ValueError("Unknown response type. There must be a 'text' field in each message.") node["info"].data.response = {"chatsky.rsp.choice": chatsky_responses.copy()} else: @@ -215,7 +216,7 @@ async def converter(build_id: int) -> None: replacer = ServiceReplacer(responses_list) replacer.visit(responses_tree) - with open(custom_responses_file, 'w') as file: + with open(custom_responses_file, "w") as file: file.write(ast.unparse(responses_tree)) with open(custom_conditions_file, "r", encoding="UTF-8") as file: @@ -245,10 +246,9 @@ async def converter(build_id: int) -> None: replacer = ServiceReplacer(conditions_list) replacer.visit(conditions_tree) - with open(custom_conditions_file, 'w') as file: + with open(custom_conditions_file, "w") as file: file.write(ast.unparse(conditions_tree)) - _fill_nodes_into_script(nodes, script) await write_conf(script, script_path) diff --git a/backend/chatsky_ui/tests/e2e/test_e2e.py b/backend/chatsky_ui/tests/e2e/test_e2e.py index f24567e8..535c28f9 100644 --- a/backend/chatsky_ui/tests/e2e/test_e2e.py +++ b/backend/chatsky_ui/tests/e2e/test_e2e.py @@ -50,5 +50,5 @@ async def test_all(mocker): await asyncio.sleep(10) assert await process_manager.get_status(run_id) == Status.ALIVE - async with aconnect_ws(f"http://localhost:8000/api/v1/bot/run/connect?run_id={run_id}", client) as ws: + async with aconnect_ws(f"http://localhost:8000/api/v1/bot/run/connect?run_id={run_id}", client): pass diff --git a/backend/chatsky_ui/tests/integration/test_api_integration.py b/backend/chatsky_ui/tests/integration/test_api_integration.py index 0ec8e028..6ab9716a 100644 --- a/backend/chatsky_ui/tests/integration/test_api_integration.py +++ b/backend/chatsky_ui/tests/integration/test_api_integration.py @@ -205,7 +205,7 @@ async def test_connect_to_ws(mocker): assert await process_manager.get_status(run_id) == Status.ALIVE - async with aconnect_ws(f"http://localhost:8000/api/v1/bot/run/connect?run_id={run_id}", client) as ws: + async with aconnect_ws(f"http://localhost:8000/api/v1/bot/run/connect?run_id={run_id}", client): pass