Romani Mind, v1.1
Posted on

Web service for a handling of a business logic of conversations.
Process conversations concurrently, support an own .env config for a handler class and simplify an implementation of the latter.
Change Log
- Support empty global variables in the stuff for the Postman tool.
- Handler:
- Concurrent handling:
- Process conversations concurrently.
- Support a logging in the concurrent handler.
- Working with a directory containing a handler class:
- Load an additional
.envconfig from it:- reload it on each request.
- Make paths to sent photos absolute:
- treat relative paths relatively to it.
- Load an additional
- Improve the abstract class of a handler:
- Add a method for an access to environment variables.
- Move the prefix of paths to photos to a class constant.
- Make it visible from the general package.
- Concurrent handling:
Features
- working mode:
- run as a web service;
- control via the RESTful API;
- handle a conversation by the specified outer handler class (see below for details);
- commands:
- handle a part of a history of a thread with an user:
- request data:
- list of messages;
- user info;
- arbitrary auxiliary data;
- response data:
- list of messages;
- probably updated arbitrary auxiliary data;
- request data:
- handle a part of a history of a thread with an user:
- handler:
- load the handler class (see below for details) from the specified file:
- support a loading from any place;
- reload the handler class on each request;
- split a request handling to a start of a conversation and a processing of new messages;
- receive a default arbitrary auxiliary data from the handler class (see below for details);
- request:
- pass a request to the handler by top level parts (an user info, an arbitrary auxiliary data and a list of messages);
- reverse an order of messages in a request;
- response:
- combine a response from top level parts returned by the handler (an arbitrary auxiliary data and a list of messages);
- automatically detect types of messages based on their content;
- make paths to sent photos absolute:
- treat relative paths relatively to a directory containing the handler class (see below for details).
- load the handler class (see below for details) from the specified file:
Architecture
UML component diagram in the PlantUML language:
@startuml
skinparam componentStyle uml2
[Thinker Class]
package "Romani Mind" {
package "Child Process" {
[History Handler] .down.> [Thinker Class] : get_default_state()
[History Handler] .down.> [Thinker Class] : on_start()
[History Handler] .down.> [Thinker Class] : on_new_messages()
}
package "Main Process" {
[Web Server] -up- API
[Web Server] .down.> [Process Pool] : history
[Process Pool] .down.> [History Handler] : history
}
}
[Romani Core] .down.> API : POST /history
@enduml
Rendered UML component diagram:
Abstract Class for a Handler
User = NewType('User', NamedTuple)
JSON = Union[None, bool, int, float, str, Sequence['JSON'], Mapping[str, 'JSON']]
State = JSON
Message = NewType('Message', NamedTuple)
History = Sequence[Message]
Response = Tuple[State, Sequence[str]]
class Thinker(ABC):
PHOTO_PATH_PREFIX: ClassVar[str]
logger: Logger
def __init__(self, logger_queue: Queue) -> None:
...
def get_env(self, name: str, default: str = '') -> str:
...
def get_default_state(self) -> State:
return None
@abstractmethod
def on_start(self, user: User, state: State) -> Response:
pass
@abstractmethod
def on_new_messages(self, user: User, state: State, history: History) -> Response:
pass