From 22e016aaafff54ef1cb2370527ff6d482f83e943 Mon Sep 17 00:00:00 2001 From: Ramimashkouk Date: Mon, 16 Dec 2024 15:55:03 +0800 Subject: [PATCH] refactor: Add chatsky 0.9.0.dev1 --- .../chatsky_ui/api/api_v1/endpoints/bot.py | 6 ++--- backend/chatsky_ui/core/config.py | 4 +++- .../json_converter/interface_converter.py | 3 ++- .../services/json_converter/node_converter.py | 21 ------------------ backend/chatsky_ui/services/process.py | 5 ++--- backend/poetry.lock | 22 ++++++++----------- backend/pyproject.toml | 2 +- 7 files changed, 20 insertions(+), 43 deletions(-) diff --git a/backend/chatsky_ui/api/api_v1/endpoints/bot.py b/backend/chatsky_ui/api/api_v1/endpoints/bot.py index 4ff5487..9ff9284 100644 --- a/backend/chatsky_ui/api/api_v1/endpoints/bot.py +++ b/backend/chatsky_ui/api/api_v1/endpoints/bot.py @@ -1,7 +1,6 @@ import asyncio from typing import Any, Dict, List, Optional, Union -from chatsky.messengers.http_interface import HTTP_INTERFACE_PORT from fastapi import APIRouter, BackgroundTasks, Depends, HTTPException, status from httpx import AsyncClient @@ -9,6 +8,7 @@ from chatsky_ui.schemas.pagination import Pagination from chatsky_ui.schemas.preset import Preset from chatsky_ui.services.process_manager import BuildManager, ProcessManager, RunManager +from chatsky_ui.core.config import settings router = APIRouter() @@ -242,12 +242,12 @@ async def respond( async with AsyncClient() as client: try: response = await client.post( - f"http://localhost:{HTTP_INTERFACE_PORT}/chat", + f"http://localhost:{settings.chatsky_port}/chat", params={"user_id": user_id, "user_message": user_message}, ) return response.json() except Exception as e: raise HTTPException( status_code=status.HTTP_503_SERVICE_UNAVAILABLE, - detail=f"Please check that service's up and running on the port '{HTTP_INTERFACE_PORT}'.", + detail=f"Please check that service's up and running on the port '{settings.chatsky_port}'.", ) from e diff --git a/backend/chatsky_ui/core/config.py b/backend/chatsky_ui/core/config.py index fec01d1..a7450f2 100644 --- a/backend/chatsky_ui/core/config.py +++ b/backend/chatsky_ui/core/config.py @@ -33,6 +33,7 @@ def __init__(self): self.set_config( host=os.getenv("HOST", "0.0.0.0"), port=os.getenv("PORT", "8000"), + chatsky_port=os.getenv("CHATSKY_PORT", "8020"), log_level=os.getenv("LOG_LEVEL", "info"), conf_reload=os.getenv("CONF_RELOAD", "false"), work_directory=".", @@ -44,7 +45,7 @@ def set_config(self, **kwargs): value = Path(value) elif key == "conf_reload": value = str(value).lower() in ["true", "yes", "t", "y", "1"] - elif key == "port": + elif key in ["port", "CHATSKY_PORT"]: value = int(value) setattr(self, key, value) @@ -74,6 +75,7 @@ def save_config(self): "work_directory": str(self.work_directory), "host": self.host, "port": self.port, + "chatsky_port": self.chatsky_port, "log_level": self.log_level, "conf_reload": self.conf_reload, } diff --git a/backend/chatsky_ui/services/json_converter/interface_converter.py b/backend/chatsky_ui/services/json_converter/interface_converter.py index 984ac45..0a45143 100644 --- a/backend/chatsky_ui/services/json_converter/interface_converter.py +++ b/backend/chatsky_ui/services/json_converter/interface_converter.py @@ -1,5 +1,6 @@ from ...schemas.front_graph_components.interface import Interface from .base_converter import BaseConverter +from chatsky_ui.core.config import settings class InterfaceConverter(BaseConverter): @@ -8,6 +9,6 @@ def __init__(self, interface: dict): def _convert(self): if self.interface.http is not None: - return {"chatsky.messengers.HTTPMessengerInterface": {}} + 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"}}} diff --git a/backend/chatsky_ui/services/json_converter/node_converter.py b/backend/chatsky_ui/services/json_converter/node_converter.py index da4ffa6..9656479 100644 --- a/backend/chatsky_ui/services/json_converter/node_converter.py +++ b/backend/chatsky_ui/services/json_converter/node_converter.py @@ -82,24 +82,3 @@ def _convert(self): self.node.target_flow_name, self.mapped_flows[self.node.target_flow_name][self.node.target_node_id]["data"]["name"], ] - - -# class ConfNodeConverter(NodeConverter): -# def __init__(self, config: dict): -# super().__init__(config) - - -# def _convert(self): -# return { -# # node.name: node._convert() for node in self.nodes -# } - - -# class SlotsNodeConverter(ConfNodeConverter): -# def __init__(self, config: List[dict]): -# self.slots = config - -# def _convert(self): -# return { -# # node.name: node._convert() for node in self.nodes -# } diff --git a/backend/chatsky_ui/services/process.py b/backend/chatsky_ui/services/process.py index a01f2f3..f5b18dd 100644 --- a/backend/chatsky_ui/services/process.py +++ b/backend/chatsky_ui/services/process.py @@ -13,7 +13,6 @@ from pathlib import Path from typing import Any, Dict, List, Optional -from chatsky.messengers.http_interface import HTTP_INTERFACE_PORT from dotenv import load_dotenv from httpx import AsyncClient @@ -233,12 +232,12 @@ async def check_telegram_readiness(stream, name): async with AsyncClient() as client: try: response = await client.get( - f"http://localhost:{HTTP_INTERFACE_PORT}/health", + f"http://localhost:{settings.chatsky_port}/health", ) return response.json()["status"] == "ok" except Exception as e: self.logger.info( - f"Process '{self.id}' isn't alive on port '{HTTP_INTERFACE_PORT}' yet. " + f"Process '{self.id}' isn't alive on port '{settings.chatsky_port}' yet. " f"Ignore this if you're not connecting via HTTPInterface. Exception caught: {e}" ) diff --git a/backend/poetry.lock b/backend/poetry.lock index 1591af1..47016d9 100644 --- a/backend/poetry.lock +++ b/backend/poetry.lock @@ -413,20 +413,22 @@ files = [ [[package]] name = "chatsky" -version = "0.9.0" +version = "0.9.0.dev1" description = "Chatsky is a free and open-source software stack for creating chatbots, released under the terms of Apache License 2.0." optional = false -python-versions = "^3.9,!=3.9.7" -files = [] -develop = false +python-versions = "!=2.7.*,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,!=3.7.*,!=3.8.*,>=3.9" +files = [ + {file = "chatsky-0.9.0.dev1-py3-none-any.whl", hash = "sha256:b49acf9abaf5e12fcdd1f03fd47d8f1b9dc373a4fa2e8ece19961be03152b2e2"}, + {file = "chatsky-0.9.0.dev1.tar.gz", hash = "sha256:a5f7ac9e810095d34788f39f35825799da2857c7698caad1cd12a1c70ef7061c"}, +] [package.dependencies] colorama = "*" eval_type_backport = "*" nest-asyncio = "*" pydantic = ">=2.0" -python-telegram-bot = {version = "~=21.3", extras = ["all"], optional = true} -pyyaml = {version = "*", optional = true} +python-telegram-bot = {version = ">=21.3,<22.0", extras = ["all"], optional = true, markers = "extra == \"telegram\""} +pyyaml = {version = "*", optional = true, markers = "extra == \"yaml\""} typing-extensions = "*" wrapt = "*" @@ -445,12 +447,6 @@ web-api = ["fastapi", "uvicorn"] yaml = ["pyyaml"] ydb = ["six", "ydb"] -[package.source] -type = "git" -url = "https://github.com/deeppavlov/chatsky.git" -reference = "feat/add-docker-image" -resolved_reference = "7e8f2615337d2308b71e256f469fc58ce52f6156" - [[package]] name = "click" version = "8.1.7" @@ -2393,4 +2389,4 @@ type = ["pytest-mypy"] [metadata] lock-version = "2.0" python-versions = "^3.9,!=3.9.7" -content-hash = "8539df9b57bdf437aebcc0ea06e63d3da12180a44a64282f95a5f903e7d0ab54" +content-hash = "a676df6948689fe5ff0e011484f12ecdde34add2dd2dfca1d290f1d8f8203674" diff --git a/backend/pyproject.toml b/backend/pyproject.toml index 31d1f14..a089a25 100644 --- a/backend/pyproject.toml +++ b/backend/pyproject.toml @@ -20,7 +20,7 @@ typer = "^0.9.0" pydantic-settings = "^2.2.1" aiofiles = "^23.2.1" cookiecutter = "^2.6.0" -chatsky = {extras = ["yaml", "telegram"], git = "https://github.com/deeppavlov/chatsky.git", branch = "feat/add-docker-image"} +chatsky = {extras = ["yaml", "telegram"], version = "==0.9.0.dev1"} omegaconf = "^2.3.0" httpx = "^0.27.0" httpx-ws = "^0.6.0"