Skip to content

Commit

Permalink
Fix flake8 linting
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasvallejosdev committed Jun 9, 2024
1 parent 1250935 commit f5d9246
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ exclude =
venv

ignore =
E501
E501
W291
4 changes: 2 additions & 2 deletions ai_api/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from django.contrib import admin
# from django.contrib import admin

# Register your models here.
# # Register your models here.
4 changes: 2 additions & 2 deletions ai_api/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from django.db import models
# from django.db import models

# Create your models here.
# # Create your models here.
6 changes: 4 additions & 2 deletions ai_api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

class AutocompleteTaskSerializer(serializers.Serializer):
text = serializers.CharField()

# check if the status is completed, then the text should not be empty
def validate(self, data):
if not data["text"]:
raise serializers.ValidationError("Text is required when status is completed")
raise serializers.ValidationError(
"Text is required when status is completed"
)
return data
9 changes: 7 additions & 2 deletions ai_api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def get(self, request, *args, **kwargs):
title = request.query_params.get("title", "")
list_tasks = request.query_params.get("list_tasks", "")
list_tasks = list_tasks.split(",") if list_tasks else []
print(list_tasks, input_text, title)

if not input_text or not title:
return Response(
Expand All @@ -46,6 +47,7 @@ def get(self, request, *args, **kwargs):
],
)
except Exception as e:
print(e)
return Response(
{"error": "Internal server error"},
status=status.HTTP_500_INTERNAL_SERVER_ERROR,
Expand All @@ -56,18 +58,21 @@ def get(self, request, *args, **kwargs):
print(completion)
if "status" not in completion:
return Response(
{"error": "There is an error building completion"}, status=status.HTTP_400_BAD_REQUEST
{"error": "There is an error building completion"},
status=status.HTTP_400_BAD_REQUEST,
)
completion_json = json.loads(completion)
except (KeyError, json.JSONDecodeError) as e:
print(e)
return Response(
{"error": "Invalid response from chat completion"},
status=status.HTTP_500_INTERNAL_SERVER_ERROR,
)

if completion_json.get("status") == "error":
return Response(
{"error": completion_json["message"]}, status=status.HTTP_400_BAD_REQUEST
{"error": completion_json["message"]},
status=status.HTTP_400_BAD_REQUEST,
)

text = completion_json.get("text", "")
Expand Down
1 change: 0 additions & 1 deletion tests/ai_api/test_ai_autocomplete.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest
import re
from rest_framework import status
from django.urls import reverse

Expand Down

0 comments on commit f5d9246

Please sign in to comment.