Skip to content

Commit

Permalink
feat: Support telegram interface (#91)
Browse files Browse the repository at this point in the history
* feat: Support telegram interface

* fix: Include automatic version in fastapi app
  • Loading branch information
Ramimashkouk authored Oct 1, 2024
1 parent 0a2728b commit 7013d0a
Show file tree
Hide file tree
Showing 5 changed files with 390 additions and 6 deletions.
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)',
"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)",
"All": 'cnd.All([cnd.Regexp("talk"), cnd.Regexp("about.*music")])(ctx)',
}

Expand Down
3 changes: 2 additions & 1 deletion backend/chatsky_ui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import FileResponse, HTMLResponse, RedirectResponse

from chatsky_ui import __version__
from chatsky_ui.api.api_v1.api import api_router
from chatsky_ui.api.deps import get_index
from chatsky_ui.core.config import settings
Expand All @@ -23,7 +24,7 @@ async def lifespan(app: FastAPI):
# settings.temp_conf.unlink(missing_ok=True)


app = FastAPI(title="DF Designer", lifespan=lifespan)
app = FastAPI(title="DF Designer", version=__version__, lifespan=lifespan)


app.add_middleware(
Expand Down
32 changes: 31 additions & 1 deletion backend/chatsky_ui/services/json_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,42 @@ async def update_responses_lines(nodes: dict) -> Tuple[dict, List[str]]:
return nodes, responses_list


def map_interface(interface: DictConfig) -> dict:
"""Map frontend interface to chatsky interface."""
if not isinstance(interface, DictConfig):
raise ValueError(f"Interface must be a dictionary. Got: {type(interface)}")
keys = interface.keys()
if len(keys)!=1:
raise ValueError("There must be only one key in the interface")

key = next(iter(keys))
if key == "telegram":
if "token" not in interface[key]:
raise ValueError("Token keyworkd is not provided for telegram interface")
if not interface[key]["token"]:
raise ValueError("Token is not provided for telegram interface")
return {
"chatsky.messengers.telegram.LongpollingInterface": {
"token": interface[key]["token"]
}
}
if key == "cli":
return {
"chatsky.messengers.console.CLIMessengerInterface": {}
}
else:
raise ValueError(f"Unknown interface: {key}")

async def converter(build_id: int) -> None:
"""Translate frontend flow script into chatsky script."""
frontend_graph_path, script_path, custom_conditions_file, custom_responses_file = _get_db_paths(build_id)

script = {"script": {}}
flow_graph: DictConfig = await read_conf(frontend_graph_path) # type: ignore
script = {
"script": {},
"messenger_interface": map_interface(flow_graph["interface"]),
}
del flow_graph["interface"]

nodes, script = _organize_graph_according_to_nodes(flow_graph, script)

Expand Down
Loading

0 comments on commit 7013d0a

Please sign in to comment.