Skip to content

Commit

Permalink
refactor: Add chatsky 0.9.0.dev1
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramimashkouk committed Dec 16, 2024
1 parent 9c94392 commit 22e016a
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 43 deletions.
6 changes: 3 additions & 3 deletions backend/chatsky_ui/api/api_v1/endpoints/bot.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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

from chatsky_ui.api import deps
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()

Expand Down Expand Up @@ -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
4 changes: 3 additions & 1 deletion backend/chatsky_ui/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=".",
Expand All @@ -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)

Expand Down Expand Up @@ -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,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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"}}}
21 changes: 0 additions & 21 deletions backend/chatsky_ui/services/json_converter/node_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# }
5 changes: 2 additions & 3 deletions backend/chatsky_ui/services/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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}"
)

Expand Down
22 changes: 9 additions & 13 deletions backend/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 22e016a

Please sign in to comment.