MCPcopy
hub / github.com/1Panel-dev/MaxKB / is_valid

Method is_valid

apps/chat/serializers/chat.py:57–71  ·  view source on GitHub ↗
(self, *, raise_exception=False)

Source from the content-addressed store, hash-verified

55 messages = serializers.ListSerializer(child=ChatMessagesSerializers(), required=True, label=_("Chat context"))
56
57 def is_valid(self, *, raise_exception=False):
58 super().is_valid(raise_exception=True)
59 messages = self.data.get("messages")
60
61 if len(messages) > 30:
62 raise AppApiException(400, _("Too many messages"))
63
64 for index in range(len(messages)):
65 role = messages[index].get('role')
66 if role == 'ai' and index % 2 != 1:
67 raise AppApiException(400, _("Authentication failed. Please verify that the parameters are correct."))
68 if role == 'user' and index % 2 != 0:
69 raise AppApiException(400, _("Authentication failed. Please verify that the parameters are correct."))
70 if role not in ['user', 'ai']:
71 raise AppApiException(400, _("Authentication failed. Please verify that the parameters are correct."))
72
73
74class ChatMessageSerializers(serializers.Serializer):

Callers

nothing calls this directly

Calls 3

AppApiExceptionClass · 0.90
is_validMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected