Update app.py
Browse files
app.py
CHANGED
@@ -125,6 +125,7 @@ def determine_response_type(message):
|
|
125 |
|
126 |
def post_process_response(response, is_short_response):
|
127 |
def count_questions(text):
|
|
|
128 |
return len(re.findall(r'\?', text))
|
129 |
|
130 |
def truncate_to_questions(text, max_questions):
|
@@ -142,13 +143,16 @@ def post_process_response(response, is_short_response):
|
|
142 |
|
143 |
return ' '.join(truncated_sentences)
|
144 |
|
|
|
|
|
|
|
|
|
145 |
if is_short_response:
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
def check_coherence(response):
|
153 |
sentences = re.split(r'(?<=[.!?])\s+', response)
|
154 |
unique_sentences = set(sentences)
|
|
|
125 |
|
126 |
def post_process_response(response, is_short_response):
|
127 |
def count_questions(text):
|
128 |
+
# Compte le nombre de phrases interrogatives
|
129 |
return len(re.findall(r'\?', text))
|
130 |
|
131 |
def truncate_to_questions(text, max_questions):
|
|
|
143 |
|
144 |
return ' '.join(truncated_sentences)
|
145 |
|
146 |
+
# Limiter à 2 questions, quelle que soit la longueur de la réponse
|
147 |
+
truncated_response = truncate_to_questions(response, 2)
|
148 |
+
|
149 |
+
# Appliquer la limitation de longueur si nécessaire
|
150 |
if is_short_response:
|
151 |
+
sentences = re.split(r'(?<=[.!?])\s+', truncated_response)
|
152 |
+
if len(sentences) > 2:
|
153 |
+
return ' '.join(sentences[:2]).strip()
|
154 |
+
|
155 |
+
return truncated_response.strip()
|
|
|
156 |
def check_coherence(response):
|
157 |
sentences = re.split(r'(?<=[.!?])\s+', response)
|
158 |
unique_sentences = set(sentences)
|