From d2566e36b77713c1522bb2c0f2543ec4d0863ff1 Mon Sep 17 00:00:00 2001 From: Parsa Nazer Date: Fri, 3 Jan 2025 23:31:43 +0330 Subject: [PATCH] update --- backend/chat/views.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/backend/chat/views.py b/backend/chat/views.py index e9b212c..5f9fd9d 100644 --- a/backend/chat/views.py +++ b/backend/chat/views.py @@ -114,8 +114,10 @@ class ProductChatView(APIView): sender = 'user' if message.role == 'user' else 'ai' formatted_messages.append({'sender': sender, 'content': content.text.value, 'id': counter}) counter += 1 - formatted_messages = formatted_messages[-2:] - return Response(formatted_messages, status=status.HTTP_201_CREATED) + + paginator = StructurePagination() + paginated_messages = paginator.paginate_queryset(formatted_messages, request) + return paginator.get_paginated_response(paginated_messages) def post(self, request, pk): """ @@ -155,7 +157,6 @@ class ProductChatView(APIView): if content.type == "text" and 'this is the start of the chat greet the user this chat is about the product with given detail:' not in content.text.value: sender = 'user' if message.role == 'user' else 'ai' formatted_messages.append({'sender': sender, 'content': content.text.value}) - # formatted_messages.reverse() - paginator = StructurePagination() - paginated_messages = paginator.paginate_queryset(formatted_messages, request) - return paginator.get_paginated_response(paginated_messages) \ No newline at end of file + + formatted_messages = formatted_messages[-2:] + return Response(formatted_messages, status=status.HTTP_201_CREATED) \ No newline at end of file