-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into fix/sync-with-backend
- Loading branch information
1 parent
dc29529
commit 3fd9580
Showing
38 changed files
with
829 additions
and
253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
from chatsky_ui.services.process_manager import BuildManager, RunManager | ||
|
||
|
||
build_manager = BuildManager() | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
backend/chatsky_ui/services/json_converter/base_converter.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from abc import ABC, abstractmethod | ||
|
||
|
||
class BaseConverter(ABC): | ||
def __call__(self, *args, **kwargs): | ||
return self._convert() | ||
|
||
@abstractmethod | ||
def _convert(self): | ||
raise NotImplementedError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
RESPONSES_FILE = "responses" | ||
CONDITIONS_FILE = "conditions" | ||
CUSTOM_FILE = "custom" |
72 changes: 72 additions & 0 deletions
72
backend/chatsky_ui/services/json_converter/flow_converter.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from typing import Any, Dict, List, Tuple | ||
|
||
from ...schemas.front_graph_components.flow import Flow | ||
from .base_converter import BaseConverter | ||
from .node_converter import InfoNodeConverter, LinkNodeConverter | ||
|
||
|
||
class FlowConverter(BaseConverter): | ||
NODE_CONVERTERS = { | ||
"default_node": InfoNodeConverter, | ||
"link_node": LinkNodeConverter, | ||
} | ||
|
||
def __init__(self, flow: Dict[str, Any]): | ||
self._validate_flow(flow) | ||
self.flow = Flow( | ||
name=flow["name"], | ||
nodes=flow["data"]["nodes"], | ||
edges=flow["data"]["edges"], | ||
) | ||
|
||
def __call__(self, *args, **kwargs): | ||
self.mapped_flows = kwargs["mapped_flows"] | ||
self.slots_conf = kwargs["slots_conf"] | ||
self._integrate_edges_into_nodes() | ||
return super().__call__(*args, **kwargs) | ||
|
||
def _validate_flow(self, flow: Dict[str, Any]): | ||
if "data" not in flow or "nodes" not in flow["data"] or "edges" not in flow["data"]: | ||
raise ValueError("Invalid flow structure") | ||
|
||
def _integrate_edges_into_nodes(self): | ||
def _insert_dst_into_condition( | ||
node: Dict[str, Any], condition_id: str, target_node: Tuple[str, str] | ||
) -> Dict[str, Any]: | ||
for condition in node["data"]["conditions"]: | ||
if condition["id"] == condition_id: | ||
condition["dst"] = target_node | ||
return node | ||
|
||
maped_edges = self._map_edges() | ||
nodes = self.flow.nodes.copy() | ||
for edge in maped_edges: | ||
for idx, node in enumerate(nodes): | ||
if node["id"] == edge["source"]: | ||
nodes[idx] = _insert_dst_into_condition(node, edge["sourceHandle"], edge["target"]) | ||
self.flow.nodes = nodes | ||
|
||
def _map_edges(self) -> List[Dict[str, Any]]: | ||
def _get_flow_and_node_names(target_node): | ||
node_type = target_node["type"] | ||
if node_type == "link_node": # TODO: WHY CONVERTING HERE? | ||
return LinkNodeConverter(target_node)(mapped_flows=self.mapped_flows) | ||
elif node_type == "default_node": | ||
return [self.flow.name, target_node["data"]["name"]] | ||
|
||
edges = self.flow.edges.copy() | ||
for edge in edges: | ||
target_id = edge["target"] | ||
target_node = self.mapped_flows[self.flow.name].get(target_id) | ||
if target_node: | ||
edge["target"] = _get_flow_and_node_names(target_node) | ||
return edges | ||
|
||
def _convert(self) -> Dict[str, Any]: | ||
converted_flow = {self.flow.name: {}} | ||
for node in self.flow.nodes: | ||
if node["type"] == "default_node": | ||
converted_flow[self.flow.name].update( | ||
{node["data"]["name"]: InfoNodeConverter(node)(slots_conf=self.slots_conf)} | ||
) | ||
return converted_flow |
15 changes: 15 additions & 0 deletions
15
backend/chatsky_ui/services/json_converter/interface_converter.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from chatsky_ui.core.config import settings | ||
|
||
from ...schemas.front_graph_components.interface import Interface | ||
from .base_converter import BaseConverter | ||
|
||
|
||
class InterfaceConverter(BaseConverter): | ||
def __init__(self, interface: dict): | ||
self.interface = Interface(**interface) | ||
|
||
def _convert(self): | ||
if self.interface.http is not None: | ||
return {"chatsky.messengers.HTTPMessengerInterface": {"port": settings.chatsky_port}} | ||
elif self.interface.telegram is not None: | ||
return {"chatsky.messengers.TelegramInterface": {"token": {"external:os.getenv": "TG_BOT_TOKEN"}}} |
Oops, something went wrong.