Skip to content

Commit e645215

Browse files
committed
🔥(project) remove previous AI feature
We replace the previous AI feature with a new one that uses the BlockNote AI service. We can remove the dead codes.
1 parent 82da180 commit e645215

File tree

9 files changed

+1
-1345
lines changed

9 files changed

+1
-1345
lines changed

src/backend/core/api/serializers.py

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -673,36 +673,6 @@ class VersionFilterSerializer(serializers.Serializer):
673673
)
674674

675675

676-
class AITransformSerializer(serializers.Serializer):
677-
"""Serializer for AI transform requests."""
678-
679-
action = serializers.ChoiceField(choices=AI_ACTIONS, required=True)
680-
text = serializers.CharField(required=True)
681-
682-
def validate_text(self, value):
683-
"""Ensure the text field is not empty."""
684-
685-
if len(value.strip()) == 0:
686-
raise serializers.ValidationError("Text field cannot be empty.")
687-
return value
688-
689-
690-
class AITranslateSerializer(serializers.Serializer):
691-
"""Serializer for AI translate requests."""
692-
693-
language = serializers.ChoiceField(
694-
choices=tuple(enums.ALL_LANGUAGES.items()), required=True
695-
)
696-
text = serializers.CharField(required=True)
697-
698-
def validate_text(self, value):
699-
"""Ensure the text field is not empty."""
700-
701-
if len(value.strip()) == 0:
702-
raise serializers.ValidationError("Text field cannot be empty.")
703-
return value
704-
705-
706676
class AIProxySerializer(serializers.Serializer):
707677
"""Serializer for AI proxy requests."""
708678

src/backend/core/api/viewsets.py

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,6 @@ class DocumentViewSet(
435435
]
436436
queryset = models.Document.objects.all()
437437
serializer_class = serializers.DocumentSerializer
438-
ai_translate_serializer_class = serializers.AITranslateSerializer
439438
children_serializer_class = serializers.ListDocumentSerializer
440439
descendants_serializer_class = serializers.ListDocumentSerializer
441440
list_serializer_class = serializers.ListDocumentSerializer
@@ -1372,62 +1371,6 @@ def ai_proxy(self, request, *args, **kwargs):
13721371
response = AIService().proxy(request.data)
13731372
return drf.response.Response(response, status=drf.status.HTTP_200_OK)
13741373

1375-
@drf.decorators.action(
1376-
detail=True,
1377-
methods=["post"],
1378-
name="Apply a transformation action on a piece of text with AI",
1379-
url_path="ai-transform",
1380-
throttle_classes=[utils.AIDocumentRateThrottle, utils.AIUserRateThrottle],
1381-
)
1382-
def ai_transform(self, request, *args, **kwargs):
1383-
"""
1384-
POST /api/v1.0/documents/<resource_id>/ai-transform
1385-
with expected data:
1386-
- text: str
1387-
- action: str [prompt, correct, rephrase, summarize]
1388-
Return JSON response with the processed text.
1389-
"""
1390-
# Check permissions first
1391-
self.get_object()
1392-
1393-
serializer = serializers.AITransformSerializer(data=request.data)
1394-
serializer.is_valid(raise_exception=True)
1395-
1396-
text = serializer.validated_data["text"]
1397-
action = serializer.validated_data["action"]
1398-
1399-
response = AIService().transform(text, action)
1400-
1401-
return drf.response.Response(response, status=drf.status.HTTP_200_OK)
1402-
1403-
@drf.decorators.action(
1404-
detail=True,
1405-
methods=["post"],
1406-
name="Translate a piece of text with AI",
1407-
url_path="ai-translate",
1408-
throttle_classes=[utils.AIDocumentRateThrottle, utils.AIUserRateThrottle],
1409-
)
1410-
def ai_translate(self, request, *args, **kwargs):
1411-
"""
1412-
POST /api/v1.0/documents/<resource_id>/ai-translate
1413-
with expected data:
1414-
- text: str
1415-
- language: str [settings.LANGUAGES]
1416-
Return JSON response with the translated text.
1417-
"""
1418-
# Check permissions first
1419-
self.get_object()
1420-
1421-
serializer = self.get_serializer(data=request.data)
1422-
serializer.is_valid(raise_exception=True)
1423-
1424-
text = serializer.validated_data["text"]
1425-
language = serializer.validated_data["language"]
1426-
1427-
response = AIService().translate(text, language)
1428-
1429-
return drf.response.Response(response, status=drf.status.HTTP_200_OK)
1430-
14311374
@drf.decorators.action(
14321375
detail=True,
14331376
methods=["get"],

src/backend/core/services/ai_services.py

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -9,49 +9,6 @@
99

1010
log = logging.getLogger(__name__)
1111

12-
AI_ACTIONS = {
13-
"prompt": (
14-
"Answer the prompt in markdown format. "
15-
"Preserve the language and markdown formatting. "
16-
"Do not provide any other information. "
17-
"Preserve the language."
18-
),
19-
"correct": (
20-
"Correct grammar and spelling of the markdown text, "
21-
"preserving language and markdown formatting. "
22-
"Do not provide any other information. "
23-
"Preserve the language."
24-
),
25-
"rephrase": (
26-
"Rephrase the given markdown text, "
27-
"preserving language and markdown formatting. "
28-
"Do not provide any other information. "
29-
"Preserve the language."
30-
),
31-
"summarize": (
32-
"Summarize the markdown text, preserving language and markdown formatting. "
33-
"Do not provide any other information. "
34-
"Preserve the language."
35-
),
36-
"beautify": (
37-
"Add formatting to the text to make it more readable. "
38-
"Do not provide any other information. "
39-
"Preserve the language."
40-
),
41-
"emojify": (
42-
"Add emojis to the important parts of the text. "
43-
"Do not provide any other information. "
44-
"Preserve the language."
45-
),
46-
}
47-
48-
AI_TRANSLATE = (
49-
"Keep the same html structure and formatting. "
50-
"Translate the content in the html to the specified language {language:s}. "
51-
"Check the translation for accuracy and make any necessary corrections. "
52-
"Do not provide any other information."
53-
)
54-
5512

5613
class AIService:
5714
"""Service class for AI-related operations."""
@@ -82,17 +39,6 @@ def call_ai_api(self, system_content, text):
8239
raise RuntimeError("AI response does not contain an answer")
8340

8441
return {"answer": content}
85-
86-
def transform(self, text, action):
87-
"""Transform text based on specified action."""
88-
system_content = AI_ACTIONS[action]
89-
return self.call_ai_api(system_content, text)
90-
91-
def translate(self, text, language):
92-
"""Translate text to a specified language."""
93-
language_display = enums.ALL_LANGUAGES.get(language, language)
94-
system_content = AI_TRANSLATE.format(language=language_display)
95-
return self.call_ai_api(system_content, text)
9642

9743
def proxy(self, data:dict) -> dict:
9844
"""Proxy AI API requests to the configured AI provider."""

0 commit comments

Comments
 (0)