(backend) use pydantic AI to manage vercel data stream protocol

The frontend application is using Vercel AI SDK and it's data stream
protocol. We decided to use the pydantic AI library to use it's vercel
ai adapter. It will make the payload validation, use AsyncIterator and
deal with vercel specification.
This commit is contained in:
Manuel Raynaud
2026-02-17 11:11:13 +01:00
committed by Anthony LC
parent 050b106a8f
commit 8ce216f6e8
9 changed files with 850 additions and 812 deletions

View File

@@ -833,39 +833,6 @@ class AITranslateSerializer(serializers.Serializer):
return value
class AIProxySerializer(serializers.Serializer):
"""Serializer for AI proxy requests."""
messages = serializers.ListField(
required=True,
child=serializers.DictField(),
allow_empty=False,
)
model = serializers.CharField(required=True)
def validate_messages(self, messages):
"""Validate messages structure."""
# Ensure each message has the required fields
for message in messages:
if (
not isinstance(message, dict)
or "role" not in message
or "content" not in message
):
raise serializers.ValidationError(
"Each message must have 'role' and 'content' fields"
)
return messages
def validate_model(self, value):
"""Validate model value is the same than settings.AI_MODEL"""
if value != settings.AI_MODEL:
raise serializers.ValidationError(f"{value} is not a valid model")
return value
class MoveDocumentSerializer(serializers.Serializer):
"""
Serializer for validating input data to move a document within the tree structure.