Skip to content

Commit

Permalink
Merge pull request #35 from etalab-ia/feat/debug-command
Browse files Browse the repository at this point in the history
feat: add debug command
  • Loading branch information
bolinocroustibat authored May 24, 2024
2 parents b930afe + 2420b3f commit 38034ec
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 21 additions & 1 deletion app/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -171,6 +172,25 @@ async def albert_conversation(ep: EventParser, matrix_client: MatrixClient):
await matrix_client.send_text_message(ep.room.room_id, 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,
Expand Down
15 changes: 9 additions & 6 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = [
{ name = "Etalab", email = "[email protected]" },
]

requires-python = ">= 3.10"
requires-python = ">= 3.11"
readme = "README.md"
license = { text = "MIT" }
dependencies = [
Expand Down

0 comments on commit 38034ec

Please sign in to comment.