-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add spam detection endpoints:
api/spam/get-latest-batch/
and …
…`api/spam/update`. A SpamModeration record with status `SCHEDULED_FOR_CHECK` is stored on every Job, Event, Codebase submission. A decoupled external service will query for these objects to check them for spam.
- Loading branch information
Showing
10 changed files
with
464 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from rest_framework.authentication import BaseAuthentication | ||
from rest_framework.exceptions import AuthenticationFailed, NotAuthenticated | ||
from django.conf import settings | ||
from rest_framework.permissions import BasePermission | ||
|
||
|
||
class APIKeyAuthentication(BaseAuthentication): | ||
def authenticate_header(self, request): | ||
return "X-API-Key" | ||
|
||
def authenticate(self, request): | ||
api_key = request.META.get("HTTP_X_API_KEY") | ||
|
||
if not api_key: | ||
raise AuthenticationFailed("No API key") | ||
|
||
if api_key != settings.LLM_SPAM_CHECK_API_KEY: | ||
raise AuthenticationFailed("Invalid API key") | ||
|
||
return (None, None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
from rest_framework import serializers | ||
from core.models import SpamModeration | ||
from django.contrib.contenttypes.models import ContentType | ||
from rest_framework import serializers | ||
from core.models import Event, Job, SpamModeration | ||
from django.contrib.contenttypes.models import ContentType | ||
|
||
from library.models import Codebase | ||
|
||
|
||
class SpamModerationSerializer(serializers.ModelSerializer): | ||
content_type = serializers.CharField(source="content_type.model") | ||
|
||
class Meta: | ||
model = SpamModeration | ||
fields = [ | ||
"id", | ||
# "status", | ||
"content_type", | ||
"object_id", | ||
# "date_created", | ||
# "last_modified", | ||
# "notes", | ||
# "detection_method", | ||
# "detection_details", | ||
] | ||
|
||
|
||
class MinimalJobSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Job | ||
fields = [ | ||
"id", | ||
"title", | ||
"summary", | ||
"description", | ||
"external_url", | ||
] | ||
|
||
|
||
class MinimalEventSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Event | ||
fields = [ | ||
"id", | ||
"title", | ||
"summary", | ||
"description", | ||
"external_url", | ||
] | ||
|
||
|
||
class MinimalCodebaseSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Codebase | ||
fields = [ | ||
"id", | ||
"title", | ||
"description", | ||
] | ||
|
||
|
||
class SpamUpdateSerializer(serializers.Serializer): | ||
object_id = serializers.IntegerField() | ||
is_spam = serializers.BooleanField() | ||
spam_indicators = serializers.ListField( | ||
child=serializers.CharField(), required=False | ||
) | ||
reasoning = serializers.CharField(required=False) | ||
confidence = serializers.FloatField(required=False) |
Oops, something went wrong.