From f3680b690534687b8d0c2fd86da45cb46b8a747d Mon Sep 17 00:00:00 2001 From: Laurent Paoletti Date: Tue, 23 Dec 2025 16:40:51 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9A=B0=EF=B8=8F(back)=20remove=20dead=20code?= =?UTF-8?q?=20and=20unused=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Laurent Paoletti --- CHANGELOG.md | 1 + package.json | 6 -- ...top_steaming.py => test_stop_streaming.py} | 2 +- src/backend/chat/tools/exceptions.py | 11 ---- src/backend/chat/views.py | 2 +- src/backend/core/api/__init__.py | 14 ----- src/backend/core/api/serializers.py | 20 ------- src/backend/core/authentication/__init__.py | 52 ----------------- src/backend/core/fields.py | 25 -------- src/backend/core/filters.py | 22 ------- .../templates/core/generate_document.html | 14 ----- src/backend/core/templatetags/__init__.py | 0 src/backend/core/templatetags/extra_tags.py | 58 ------------------- 13 files changed, 3 insertions(+), 224 deletions(-) delete mode 100644 package.json rename src/backend/chat/tests/views/chat/conversations/{test_stop_steaming.py => test_stop_streaming.py} (97%) delete mode 100644 src/backend/core/fields.py delete mode 100644 src/backend/core/templates/core/generate_document.html delete mode 100644 src/backend/core/templatetags/__init__.py delete mode 100644 src/backend/core/templatetags/extra_tags.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d53a61..766c900 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to - 🐛(e2e) fix test-e2e-chromium - 🐛(back) fix system prompt compatibility with self-hosted models #200 +- ⚰️(back) remove dead code and unused files ## [0.0.10] - 2025-12-15 diff --git a/package.json b/package.json deleted file mode 100644 index 24afa17..0000000 --- a/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "dependencies": { - "@ai-sdk/react": "^1.2.12", - "@ai-sdk/ui-utils": "^1.2.11" - } -} diff --git a/src/backend/chat/tests/views/chat/conversations/test_stop_steaming.py b/src/backend/chat/tests/views/chat/conversations/test_stop_streaming.py similarity index 97% rename from src/backend/chat/tests/views/chat/conversations/test_stop_steaming.py rename to src/backend/chat/tests/views/chat/conversations/test_stop_streaming.py index d11ee60..8e984cb 100644 --- a/src/backend/chat/tests/views/chat/conversations/test_stop_steaming.py +++ b/src/backend/chat/tests/views/chat/conversations/test_stop_streaming.py @@ -1,4 +1,4 @@ -"""Test the post_stop_steaming view.""" +"""Test the post_stop_streaming view.""" from unittest.mock import patch diff --git a/src/backend/chat/tools/exceptions.py b/src/backend/chat/tools/exceptions.py index fe0dd62..5625b81 100644 --- a/src/backend/chat/tools/exceptions.py +++ b/src/backend/chat/tools/exceptions.py @@ -3,17 +3,6 @@ from pydantic_ai import ModelRetry -class ModelRetryLast(ModelRetry): - """ - Same as ModelRetry but also holds the last retry message to return when all attempts failed. - """ - - def __init__(self, message: str, last_retry_message: str): - """Initialize ModelRetryLast with message and last retry message.""" - self.last_retry_message = last_retry_message - super().__init__(message) - - class ModelCannotRetry(ModelRetry): """ Exception to raise when a tool function cannot be retried. diff --git a/src/backend/chat/views.py b/src/backend/chat/views.py index 0437237..dbff818 100644 --- a/src/backend/chat/views.py +++ b/src/backend/chat/views.py @@ -221,7 +221,7 @@ class ChatViewSet( # pylint: disable=too-many-ancestors, abstract-method url_path="stop-streaming", url_name="stop-streaming", ) - def post_stop_steaming(self, request, pk): # pylint: disable=unused-argument + def post_stop_streaming(self, request, pk): # pylint: disable=unused-argument """Handle POST requests to stop streaming the chat conversation. This action will put a poison pill in the redis cache to stop any ongoing streaming. diff --git a/src/backend/core/api/__init__.py b/src/backend/core/api/__init__.py index c88af71..ea14585 100644 --- a/src/backend/core/api/__init__.py +++ b/src/backend/core/api/__init__.py @@ -1,12 +1,9 @@ """Conversations core API endpoints""" -from django.conf import settings from django.core.exceptions import ValidationError from rest_framework import exceptions as drf_exceptions from rest_framework import views as drf_views -from rest_framework.decorators import api_view -from rest_framework.response import Response def exception_handler(exc, context): @@ -28,14 +25,3 @@ def exception_handler(exc, context): exc = drf_exceptions.ValidationError(detail=detail) return drf_views.exception_handler(exc, context) - - -# pylint: disable=unused-argument -@api_view(["GET"]) -def get_frontend_configuration(request): - """Returns the frontend configuration dict as configured in settings.""" - frontend_configuration = { - "LANGUAGE_CODE": settings.LANGUAGE_CODE, - } - frontend_configuration.update(settings.FRONTEND_CONFIGURATION) - return Response(frontend_configuration) diff --git a/src/backend/core/api/serializers.py b/src/backend/core/api/serializers.py index ba61de4..e05fe24 100644 --- a/src/backend/core/api/serializers.py +++ b/src/backend/core/api/serializers.py @@ -20,23 +20,3 @@ class UserSerializer(serializers.ModelSerializer): "sub", ] read_only_fields = ["id", "email", "full_name", "short_name", "sub"] - - -class UserLightSerializer(UserSerializer): - """Serialize users with limited fields.""" - - id = serializers.SerializerMethodField(read_only=True) - email = serializers.SerializerMethodField(read_only=True) - - def get_id(self, _user): - """Return always None. Here to have the same fields than in UserSerializer.""" - return None - - def get_email(self, _user): - """Return always None. Here to have the same fields than in UserSerializer.""" - return None - - class Meta: - model = models.User - fields = ["id", "email", "full_name", "short_name"] - read_only_fields = ["id", "email", "full_name", "short_name"] diff --git a/src/backend/core/authentication/__init__.py b/src/backend/core/authentication/__init__.py index 977382d..e69de29 100644 --- a/src/backend/core/authentication/__init__.py +++ b/src/backend/core/authentication/__init__.py @@ -1,52 +0,0 @@ -"""Custom authentication classes for the Conversations core app""" - -from django.conf import settings - -from rest_framework.authentication import BaseAuthentication -from rest_framework.exceptions import AuthenticationFailed - - -class ServerToServerAuthentication(BaseAuthentication): - """ - Custom authentication class for server-to-server requests. - Validates the presence and correctness of the Authorization header. - """ - - AUTH_HEADER = "Authorization" - TOKEN_TYPE = "Bearer" # noqa S105 - - def authenticate(self, request): - """ - Authenticate the server-to-server request by validating the Authorization header. - - This method checks if the Authorization header is present in the request, ensures it - contains a valid token with the correct format, and verifies the token against the - list of allowed server-to-server tokens. If the header is missing, improperly formatted, - or contains an invalid token, an AuthenticationFailed exception is raised. - - Returns: - None: If authentication is successful - (no user is authenticated for server-to-server requests). - - Raises: - AuthenticationFailed: If the Authorization header is missing, malformed, - or contains an invalid token. - """ - auth_header = request.headers.get(self.AUTH_HEADER) - if not auth_header: - raise AuthenticationFailed("Authorization header is missing.") - - # Validate token format and existence - auth_parts = auth_header.split(" ") - if len(auth_parts) != 2 or auth_parts[0] != self.TOKEN_TYPE: - raise AuthenticationFailed("Invalid authorization header.") - - token = auth_parts[1] - if token not in settings.SERVER_TO_SERVER_API_TOKENS: - raise AuthenticationFailed("Invalid server-to-server token.") - - # Authentication is successful, but no user is authenticated - - def authenticate_header(self, request): - """Return the WWW-Authenticate header value.""" - return f"{self.TOKEN_TYPE} realm='Create document server to server'" diff --git a/src/backend/core/fields.py b/src/backend/core/fields.py deleted file mode 100644 index 1125622..0000000 --- a/src/backend/core/fields.py +++ /dev/null @@ -1,25 +0,0 @@ -"""A JSONField for DRF to handle serialization/deserialization.""" - -import json - -from rest_framework import serializers - - -class JSONField(serializers.Field): - """ - A custom field for handling JSON data. - """ - - def to_representation(self, value): - """ - Convert the JSON string to a Python dictionary for serialization. - """ - return value - - def to_internal_value(self, data): - """ - Convert the Python dictionary to a JSON string for deserialization. - """ - if data is None: - return None - return json.dumps(data) diff --git a/src/backend/core/filters.py b/src/backend/core/filters.py index bf7ac87..c8ee0a1 100644 --- a/src/backend/core/filters.py +++ b/src/backend/core/filters.py @@ -2,31 +2,9 @@ import unicodedata -import django_filters - def remove_accents(value): """Remove accents from a string (vélo -> velo).""" return "".join( c for c in unicodedata.normalize("NFD", value) if unicodedata.category(c) != "Mn" ) - - -class AccentInsensitiveCharFilter(django_filters.CharFilter): - """ - A custom CharFilter that filters on the accent-insensitive value searched. - """ - - def filter(self, qs, value): - """ - Apply the filter to the queryset using the unaccented version of the field. - - Args: - qs: The queryset to filter. - value: The value to search for in the unaccented field. - Returns: - A filtered queryset. - """ - if value: - value = remove_accents(value) - return super().filter(qs, value) diff --git a/src/backend/core/templates/core/generate_document.html b/src/backend/core/templates/core/generate_document.html deleted file mode 100644 index ac9f291..0000000 --- a/src/backend/core/templates/core/generate_document.html +++ /dev/null @@ -1,14 +0,0 @@ - - - - Generate Document - - -

Generate Document

-
- {% csrf_token %} - {{ form.as_p }} - -
- - diff --git a/src/backend/core/templatetags/__init__.py b/src/backend/core/templatetags/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/backend/core/templatetags/extra_tags.py b/src/backend/core/templatetags/extra_tags.py deleted file mode 100644 index 109bd7b..0000000 --- a/src/backend/core/templatetags/extra_tags.py +++ /dev/null @@ -1,58 +0,0 @@ -"""Custom template tags for the core application of People.""" - -import base64 - -from django import template -from django.contrib.staticfiles import finders - -from PIL import ImageFile as PillowImageFile - -register = template.Library() - - -def image_to_base64(file_or_path, close=False): - """ - Return the src string of the base64 encoding of an image represented by its path - or file opened or not. - - Inspired by Django's "get_image_dimensions" - """ - pil_parser = PillowImageFile.Parser() - if hasattr(file_or_path, "read"): - file = file_or_path - if file.closed and hasattr(file, "open"): - file_or_path.open() - file_pos = file.tell() - file.seek(0) - else: - try: - # pylint: disable=consider-using-with - file = open(file_or_path, "rb") - except OSError: - return "" - close = True - - try: - image_data = file.read() - if not image_data: - return "" - pil_parser.feed(image_data) - if pil_parser.image: - mime_type = pil_parser.image.get_format_mimetype() - encoded_string = base64.b64encode(image_data) - return f"data:{mime_type:s};base64, {encoded_string.decode('utf-8'):s}" - return "" - finally: - if close: - file.close() - else: - file.seek(file_pos) - - -@register.simple_tag -def base64_static(path): - """Return a static file into a base64.""" - full_path = finders.find(path) - if full_path: - return image_to_base64(full_path, True) - return ""