This commit is contained in:
Parsa Nazer
2025-01-03 23:31:43 +03:30
parent 91b74cf05b
commit d2566e36b7
+7 -6
View File
@@ -114,8 +114,10 @@ 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:]
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): 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: 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' sender = 'user' if message.role == 'user' else 'ai'
formatted_messages.append({'sender': sender, 'content': content.text.value}) formatted_messages.append({'sender': sender, 'content': content.text.value})
# formatted_messages.reverse()
paginator = StructurePagination() formatted_messages = formatted_messages[-2:]
paginated_messages = paginator.paginate_queryset(formatted_messages, request) return Response(formatted_messages, status=status.HTTP_201_CREATED)
return paginator.get_paginated_response(paginated_messages)