diff --git a/app/api/question_router.py b/app/api/question_router.py index e214974..b7a99f5 100644 --- a/app/api/question_router.py +++ b/app/api/question_router.py @@ -17,7 +17,6 @@ class UserRequest(BaseModel): router = APIRouter(prefix="/api/v1/question", tags=["response"]) - @router.post("/ask") async def ask(request: UserRequest): question = request.message @@ -25,9 +24,15 @@ async def ask(request: UserRequest): language = request.language if not question or not classification: raise HTTPException(status_code=400, detail="No question or classification provided") + + if len(question) > config.MAX_MESSAGE_LENGTH: + raise HTTPException( + status_code=400, + detail=f"Question length exceeds the allowed limit of {config.MAX_MESSAGE_LENGTH} characters" + ) logging.info(f"Received question: {question} with classification: {classification}") - + if config.TEST_MODE: answer, used_tokens, general_context, specific_context = request_handler.handle_question_test_mode(question, classification, @@ -44,6 +49,14 @@ async def chat(request: UserChat): messages = request.messages if not messages: raise HTTPException(status_code=400, detail="No messages have been provided") + + last_message = messages[-1].message + if len(last_message) > config.MAX_MESSAGE_LENGTH: + raise HTTPException( + status_code=400, + detail=f"Message length exceeds the allowed limit of {config.MAX_MESSAGE_LENGTH} characters" + ) + logging.info(f"Received messages.") answer = request_handler.handle_chat(messages, study_program=request.study_program) return {"answer": answer} diff --git a/app/utils/environment.py b/app/utils/environment.py index 54b8e02..6b26b25 100644 --- a/app/utils/environment.py +++ b/app/utils/environment.py @@ -7,6 +7,7 @@ class Config: + MAX_MESSAGE_LENGTH = 3000 # Weaviate Database WEAVIATE_URL = os.getenv("WEAVIATE_URL", "localhost") WEAVIATE_PORT = os.getenv("WEAVIATE_PORT", "8001") diff --git a/knowledge/sample-correspondences/Advanced Practical Course Free Subject_de.json b/knowledge/sample-correspondences/Advanced Practical Course Free Subject_de.json index a5c0e97..1f00bcb 100644 --- a/knowledge/sample-correspondences/Advanced Practical Course Free Subject_de.json +++ b/knowledge/sample-correspondences/Advanced Practical Course Free Subject_de.json @@ -10,7 +10,7 @@ { "orderKey": 1, "sender": "AA", - "message": "Bitte wenden Sie sich hierfür an die Sekretärin Ihres Prüfungsausschusses." + "message": "Bitte wenden Sie sich hierfür an die Schriftführung Ihres Studiengangs." } ] } \ No newline at end of file diff --git "a/knowledge/sample-correspondences/Inquery about reallocation of Credits for \"Concepts of C++ Programming IN2377\"_de.json" "b/knowledge/sample-correspondences/Inquery about reallocation of Credits for \"Concepts of C++ Programming IN2377\"_de.json" index 8836436..2092e81 100644 --- "a/knowledge/sample-correspondences/Inquery about reallocation of Credits for \"Concepts of C++ Programming IN2377\"_de.json" +++ "b/knowledge/sample-correspondences/Inquery about reallocation of Credits for \"Concepts of C++ Programming IN2377\"_de.json" @@ -10,7 +10,7 @@ { "orderKey": 1, "sender": "AA", - "message": "Bitte wenden Sie sich hierzu an die Sekretärin des für Ihren Studiengang zuständigen Prüfungsausschusses. Die Kontaktdaten finden Sie hier: cit.tum.de/cit/kontakt-studium-informatik/" + "message": "Bitte wenden Sie sich hierzu an die für Ihren Studiengang zuständige Schriftführung. Die Kontaktdaten finden Sie hier: cit.tum.de/cit/kontakt-studium-informatik/" } ] } \ No newline at end of file diff --git a/knowledge/sample-correspondences/Language course cannot be added to the MSc. Informatics program_de.json b/knowledge/sample-correspondences/Language course cannot be added to the MSc. Informatics program_de.json index 72fe566..dfade57 100644 --- a/knowledge/sample-correspondences/Language course cannot be added to the MSc. Informatics program_de.json +++ b/knowledge/sample-correspondences/Language course cannot be added to the MSc. Informatics program_de.json @@ -10,7 +10,7 @@ { "orderKey": 1, "sender": "AA", - "message": "Bitte wenden Sie sich bei Fragen zur Kursanmeldung an die Sekretärin des Prüfungsausschusses." + "message": "Bitte wenden Sie sich bei Fragen zur Kursanmeldung an die Schriftführung Ihres Studiengangs." } ] } \ No newline at end of file diff --git a/knowledge/sample-correspondences/Praktikum_de.json b/knowledge/sample-correspondences/Praktikum_de.json index 8e64346..a774a08 100644 --- a/knowledge/sample-correspondences/Praktikum_de.json +++ b/knowledge/sample-correspondences/Praktikum_de.json @@ -10,7 +10,7 @@ { "orderKey": 1, "sender": "AA", - "message": "Bitte wenden Sie sich hierfür an die Sekretärin Ihres Prüfungsausschusses." + "message": "Bitte wenden Sie sich hierfür an die Schriftführung Ihres Studiengangs." } ] } \ No newline at end of file diff --git a/knowledge/sample-correspondences/Registration of second praktikum_de.json b/knowledge/sample-correspondences/Registration of second praktikum_de.json index 3043ea3..6a16eda 100644 --- a/knowledge/sample-correspondences/Registration of second praktikum_de.json +++ b/knowledge/sample-correspondences/Registration of second praktikum_de.json @@ -10,7 +10,7 @@ { "orderKey": 1, "sender": "AA", - "message": "Bitte wenden Sie sich für Unterstützung bei der Aktualisierung Ihrer Daten an die Sekretärin Ihres Prüfungsausschusses." + "message": "Bitte wenden Sie sich für Unterstützung bei der Aktualisierung Ihrer Daten an die zuständige Schriftführung." } ] } \ No newline at end of file