Skip to content

Commit

Permalink
fix: missing exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
leoguillaumegouv committed Oct 6, 2024
1 parent ee6cf2f commit 5a1ada9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/helpers/_modelclients.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from app.schemas.embeddings import Embeddings
from app.schemas.models import Model, Models
from app.utils.config import LOGGER
from app.utils.exceptions import ContextLengthExceededException, ModelNotFoundException
from app.utils.variables import EMBEDDINGS_MODEL_TYPE, LANGUAGE_MODEL_TYPE
from app.utils.exceptions import ModelNotFoundException


def get_models_list(self, *args, **kwargs):
Expand Down Expand Up @@ -77,7 +77,7 @@ def create_embeddings(self, *args, **kwargs):
return Embeddings(**data)
except Exception as e:
if "`inputs` must have less than" in e.response.text:
raise AssertionError("Max input length exceeded.")
raise ContextLengthExceededException()
raise e


Expand Down
9 changes: 6 additions & 3 deletions app/helpers/parsers/_jsonparser.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import json
import time
from typing import List
import uuid

from fastapi import UploadFile

from app.schemas.data import ParserOutput, ParserOutputMetadata
from app.schemas.files import JsonFile
from fastapi import UploadFile
import time
from app.utils.exceptions import InvalidJSONFormatException

from ._baseparser import BaseParser


Expand All @@ -28,7 +31,7 @@ def parse(self, file: UploadFile) -> List[ParserOutput]:
try:
file = JsonFile(documents=file)
except Exception as e:
raise AssertionError("Invalid JSON file format.")
raise InvalidJSONFormatException()

output = list()
created_at = round(time.time())
Expand Down
6 changes: 6 additions & 0 deletions app/utils/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,9 @@ def __init__(self, detail: str = "Context length exceeded."):
class FileSizeLimitExceededException(HTTPException):
def __init__(self, detail: str = "File size limit exceeded."):
super().__init__(status_code=413, detail=detail)


# 422
class InvalidJSONFormatException(HTTPException):
def __init__(self, detail: str = "Invalid JSON file format."):
super().__init__(status_code=422, detail=detail)

0 comments on commit 5a1ada9

Please sign in to comment.