sending only the last 2 messages in post of chat
This commit is contained in:
+2
-20
@@ -73,22 +73,6 @@ class StructurePagination(LimitOffsetPagination):
|
|||||||
post=extend_schema(
|
post=extend_schema(
|
||||||
summary="Send a new message in the product chat",
|
summary="Send a new message in the product chat",
|
||||||
request=NewMessageSerializer,
|
request=NewMessageSerializer,
|
||||||
parameters=[
|
|
||||||
OpenApiParameter(
|
|
||||||
name="limit",
|
|
||||||
description="Number of results to return per page.",
|
|
||||||
required=False,
|
|
||||||
type=int,
|
|
||||||
default=10,
|
|
||||||
),
|
|
||||||
OpenApiParameter(
|
|
||||||
name="offset",
|
|
||||||
description="The starting position of the results.",
|
|
||||||
required=False,
|
|
||||||
type=int,
|
|
||||||
default=0,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
responses={
|
responses={
|
||||||
200: OpenApiExample(
|
200: OpenApiExample(
|
||||||
"Message sent successfully",
|
"Message sent successfully",
|
||||||
@@ -130,10 +114,8 @@ class ProductChatView(APIView):
|
|||||||
sender = 'user' if message.role == 'user' else 'ai'
|
sender = 'user' if message.role == 'user' else 'ai'
|
||||||
formatted_messages.append({'sender': sender, 'content': content.text.value, 'id': counter})
|
formatted_messages.append({'sender': sender, 'content': content.text.value, 'id': counter})
|
||||||
counter += 1
|
counter += 1
|
||||||
|
formatted_messages = formatted_messages[-2:]
|
||||||
paginator = StructurePagination()
|
return Response(formatted_messages, status=status.HTTP_201_CREATED)
|
||||||
paginated_messages = paginator.paginate_queryset(formatted_messages, request)
|
|
||||||
return paginator.get_paginated_response(paginated_messages)
|
|
||||||
|
|
||||||
def post(self, request, pk):
|
def post(self, request, pk):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user