chore: return user request count from logger (#596)

This commit is contained in:
pablohashescobar 2023-03-30 02:04:41 +05:30 committed by GitHub
parent e6055da150
commit 89bb439d62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -28,6 +28,8 @@ class GPTIntegrationEndpoint(BaseAPIView):
status=status.HTTP_400_BAD_REQUEST, status=status.HTTP_400_BAD_REQUEST,
) )
count = 0
# If logger is enabled check for request limit # If logger is enabled check for request limit
if settings.LOGGER_BASE_URL: if settings.LOGGER_BASE_URL:
try: try:
@ -40,6 +42,7 @@ class GPTIntegrationEndpoint(BaseAPIView):
json={"user_id": str(request.user.id)}, json={"user_id": str(request.user.id)},
headers=headers, headers=headers,
) )
count = response.json().get("count", 0)
if not response.json().get("success", False): if not response.json().get("success", False):
return Response( return Response(
{ {
@ -71,11 +74,10 @@ class GPTIntegrationEndpoint(BaseAPIView):
text = response.choices[0].text.strip() text = response.choices[0].text.strip()
text_html = text.replace("\n", "<br/>") text_html = text.replace("\n", "<br/>")
return Response( return Response(
{"response": text, "response_html": text_html}, {"response": text, "response_html": text_html, "count": count},
status=status.HTTP_200_OK, status=status.HTTP_200_OK,
) )
except Exception as e: except Exception as e:
print(e)
capture_exception(e) capture_exception(e)
return Response( return Response(
{"error": "Something went wrong please try again later"}, {"error": "Something went wrong please try again later"},