Skip to content

Commit

Permalink
style: Black up
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramimashkouk committed Sep 13, 2024
1 parent a24c7e3 commit 8fe351a
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 12 deletions.
4 changes: 3 additions & 1 deletion backend/chatsky_ui/api/api_v1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
4 changes: 2 additions & 2 deletions backend/chatsky_ui/clients/chatsky_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)',
}

Expand Down
1 change: 1 addition & 0 deletions backend/chatsky_ui/services/condition_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions backend/chatsky_ui/services/json_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -74,15 +75,14 @@ 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"])

return nodes, script



def _get_condition(nodes: dict, edge: DictConfig) -> Optional[DictConfig]:
"""Get node's condition from `nodes` according to `edge` info."""
return next(
Expand All @@ -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 ""
Expand All @@ -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']}")

Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion backend/chatsky_ui/tests/e2e/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 8fe351a

Please sign in to comment.