Update utils/utils.py
Browse files- utils/utils.py +8 -16
utils/utils.py
CHANGED
|
@@ -115,23 +115,15 @@ def read_pptx_text(file_path):
|
|
| 115 |
def validate_input(question, openai_api_key, gemini_api_key, anthropic_api_key):
|
| 116 |
is_valid = True
|
| 117 |
|
| 118 |
-
if (
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
is_valid = False
|
| 123 |
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
# Max length is MAX_LENGTH
|
| 129 |
-
#temp = temp[:MAX_LENGTH]
|
| 130 |
-
|
| 131 |
-
# Max word length is MAX_WORD_LENGTH
|
| 132 |
-
#temp = ' '.join(word[:MAX_WORD_LENGTH] for word in temp.split(' '))
|
| 133 |
-
|
| 134 |
-
# Max word count is MAX_WORD_COUNT
|
| 135 |
-
#temp = ' '.join(temp.split(' ')[:MAX_WORD_COUNT])
|
| 136 |
|
| 137 |
return is_valid
|
|
|
|
| 115 |
def validate_input(question, openai_api_key, gemini_api_key, anthropic_api_key):
|
| 116 |
is_valid = True
|
| 117 |
|
| 118 |
+
if (len(question) > 500
|
| 119 |
+
or len(openai_api_key) > 150
|
| 120 |
+
or len(gemini_api_key) > 150
|
| 121 |
+
or len(anthropic_api_key) > 150:
|
| 122 |
is_valid = False
|
| 123 |
|
| 124 |
+
sanitized_question = re.sub(r'[^\w\s.,!?\'\-()@$%&+/:;"=\[\]]', '', question)
|
| 125 |
+
|
| 126 |
+
if sanitized_question != question:
|
| 127 |
+
is_valid = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
|
| 129 |
return is_valid
|