-
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 pull request #94 from deeppavlov/dev
release: v0.3.0
- Loading branch information
Showing
90 changed files
with
3,684 additions
and
841 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
from fastapi import APIRouter | ||
|
||
from chatsky_ui.api.api_v1.endpoints import bot, config, dff_services, flows | ||
from chatsky_ui.api.api_v1.endpoints import bot, chatsky_services, config, flows | ||
from chatsky_ui.core.config import settings | ||
|
||
api_router = APIRouter() | ||
|
||
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(dff_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"]) |
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
24 changes: 12 additions & 12 deletions
24
backend/chatsky_ui/clients/dff_client.py → backend/chatsky_ui/clients/chatsky_client.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
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import ast | ||
from ast import NodeTransformer | ||
from typing import Dict, List | ||
|
||
from chatsky_ui.core.logger_config import get_logger | ||
|
||
logger = get_logger(__name__) | ||
|
||
|
||
class ServiceReplacer(NodeTransformer): | ||
def __init__(self, new_services: List[str]): | ||
self.new_services_classes = self._get_classes_def(new_services) | ||
|
||
def _get_classes_def(self, services_code: List[str]) -> Dict[str, ast.ClassDef]: | ||
parsed_codes = [ast.parse(service_code) for service_code in services_code] | ||
result_nodes = {} | ||
for idx, parsed_code in enumerate(parsed_codes): | ||
self._extract_class_defs(parsed_code, result_nodes, services_code[idx]) | ||
return result_nodes | ||
|
||
def _extract_class_defs(self, parsed_code: ast.Module, result_nodes: Dict[str, ast.ClassDef], service_code: str): | ||
for node in parsed_code.body: | ||
if isinstance(node, ast.ClassDef): | ||
result_nodes[node.name] = node | ||
else: | ||
logger.error("No class definition found in new_service: %s", service_code) | ||
|
||
def visit_ClassDef(self, node: ast.ClassDef) -> ast.ClassDef: | ||
logger.debug("Visiting class '%s' and comparing with: %s", node.name, self.new_services_classes.keys()) | ||
if node.name in self.new_services_classes: | ||
return self._get_class_def(node) | ||
return node | ||
|
||
def _get_class_def(self, node: ast.ClassDef) -> ast.ClassDef: | ||
service = self.new_services_classes[node.name] | ||
del self.new_services_classes[node.name] | ||
return service | ||
|
||
def generic_visit(self, node: ast.AST): | ||
super().generic_visit(node) | ||
if isinstance(node, ast.Module) and self.new_services_classes: | ||
self._append_new_services(node) | ||
return node | ||
|
||
def _append_new_services(self, node: ast.Module): | ||
logger.info("Services not found, appending new services: %s", list(self.new_services_classes.keys())) | ||
for _, service in self.new_services_classes.items(): | ||
node.body.append(service) |
Oops, something went wrong.