From 2420b3fa37644e4dfb9e08b23611b96b00fc3bfd Mon Sep 17 00:00:00 2001 From: Adrien Carpentier Date: Fri, 24 May 2024 13:59:04 +0200 Subject: [PATCH] feat: add debug command --- Dockerfile | 1 + app/commands.py | 22 +++++++++++++++++++++- app/config.py | 15 +++++++++------ pyproject.toml | 2 +- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index b2cdfdd..6fb4064 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,5 +4,6 @@ WORKDIR /code ADD ./pyproject.toml ./pyproject.toml RUN pip install --upgrade pip && pip install --no-cache-dir . ADD ./app ./app +ADD ./pyproject.toml ./app/pyproject.toml WORKDIR /code/app diff --git a/app/commands.py b/app/commands.py index 1305d6e..0e9cfe2 100755 --- a/app/commands.py +++ b/app/commands.py @@ -5,8 +5,9 @@ from collections import defaultdict from dataclasses import dataclass +from doctest import debug -from config import COMMAND_PREFIX, Config +from config import APP_VERSION, COMMAND_PREFIX, Config from matrix_bot.client import MatrixClient from matrix_bot.config import logger from matrix_bot.eventparser import EventNotConcerned, EventParser @@ -170,6 +171,25 @@ async def albert_conversation(ep: EventParser, matrix_client: MatrixClient): await matrix_client.send_text_message(ep.room.room_id, reset_message) +@register_feature( + group="albert_debug", + onEvent=RoomMessageText, + command="debug", + help=f"**{COMMAND_PREFIX}debug** : affiche des informations sur la configuration actuelle", +) +async def albert_debug(ep: EventParser, matrix_client: MatrixClient): + config = user_configs[ep.sender] + await matrix_client.room_typing(ep.room.room_id) + debug_message = f"Configuration actuelle :\n\n" + debug_message += f"- Version: {APP_VERSION}\n" + debug_message += f"- Model: {config.albert_model_name}\n" + debug_message += f"- Mode: {config.albert_mode}\n" + debug_message += f"- With history: {config.albert_with_history}\n" + debug_message += f"- Chat ID: {config.albert_chat_id}\n" + debug_message += f"- Stream ID: {config.albert_stream_id}\n" + await matrix_client.send_text_message(ep.room.room_id, debug_message) + + @register_feature( group="albert_debug", onEvent=RoomMessageText, diff --git a/app/config.py b/app/config.py index bd2e87b..10758c8 100755 --- a/app/config.py +++ b/app/config.py @@ -4,19 +4,22 @@ # SPDX-License-Identifier: MIT import logging +import tomllib from pathlib import Path from pydantic import Field from pydantic_settings import BaseSettings, SettingsConfigDict -PACKAGE_PATH = Path(__file__).resolve().parent -SRC_PATH = PACKAGE_PATH.parent -_ROOT_PATH = PACKAGE_PATH.parent.parent # Accessible from clone of the project, not from package -DOCUMENTATION_DIR = _ROOT_PATH / "docs" -README_PATH = _ROOT_PATH / "README.md" - COMMAND_PREFIX = "!" +APP_VERSION = "unknown" +try: + with open("pyproject.toml", "rb") as f: + pyproject: dict = tomllib.load(f) + APP_VERSION = pyproject["project"]["version"] +except Exception as e: + logging.warning(f"Error while reading pyproject.toml: {e}") + class BaseConfig(BaseSettings): # allows us to clean up the imports into multiple parts diff --git a/pyproject.toml b/pyproject.toml index 99ff4be..c27ea50 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ authors = [ { name = "Etalab", email = "etalab@modernisation.gouv.fr" }, ] -requires-python = ">= 3.10" +requires-python = ">= 3.11" readme = "README.md" license = { text = "MIT" } dependencies = [