Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -189,33 +189,34 @@ def generate(
|
|
| 189 |
"""
|
| 190 |
yield warning_message
|
| 191 |
is_first_interaction = False
|
|
|
|
| 192 |
try:
|
| 193 |
-
|
| 194 |
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
|
| 217 |
-
|
| 218 |
-
|
| 219 |
|
| 220 |
if input_ids.shape[1] > MAX_INPUT_TOKEN_LENGTH:
|
| 221 |
input_ids = input_ids[:, -MAX_INPUT_TOKEN_LENGTH:]
|
|
@@ -261,7 +262,7 @@ def generate(
|
|
| 261 |
finally:
|
| 262 |
# Nettoyage de la mΓ©moire GPU
|
| 263 |
torch.cuda.empty_cache()
|
| 264 |
-
|
| 265 |
def vote(data: gr.LikeData, history):
|
| 266 |
user_input = history[-1][0] if history else ""
|
| 267 |
|
|
|
|
| 189 |
"""
|
| 190 |
yield warning_message
|
| 191 |
is_first_interaction = False
|
| 192 |
+
|
| 193 |
try:
|
| 194 |
+
response_type = determine_response_type(message)
|
| 195 |
|
| 196 |
+
if response_type == "short":
|
| 197 |
+
max_new_tokens = max(70, max_new_tokens)
|
| 198 |
+
elif response_type == "long":
|
| 199 |
+
max_new_tokens = min(max(150, max_new_tokens), 250)
|
| 200 |
+
else: # medium
|
| 201 |
+
max_new_tokens = min(max(70, max_new_tokens), 150)
|
| 202 |
|
| 203 |
+
chat_history = chat_history[-MAX_HISTORY_LENGTH:]
|
| 204 |
+
|
| 205 |
+
conversation = []
|
| 206 |
+
|
| 207 |
+
# Ajout du system prompt et du LUCAS_KNOWLEDGE_BASE
|
| 208 |
+
enhanced_system_prompt = f"{system_prompt}\n\n{LUCAS_KNOWLEDGE_BASE}"
|
| 209 |
+
conversation.append({"role": "system", "content": enhanced_system_prompt})
|
| 210 |
+
|
| 211 |
+
# Ajout des 5 derniers inputs utilisateur uniquement
|
| 212 |
+
for user, _ in chat_history:
|
| 213 |
+
conversation.append({"role": "user", "content": user})
|
| 214 |
+
|
| 215 |
+
# Ajout du message actuel de l'utilisateur
|
| 216 |
+
conversation.append({"role": "user", "content": message})
|
| 217 |
|
| 218 |
+
input_ids = tokenizer.apply_chat_template(conversation, return_tensors="pt")
|
| 219 |
+
attention_mask = input_ids.ne(tokenizer.pad_token_id).long()
|
| 220 |
|
| 221 |
if input_ids.shape[1] > MAX_INPUT_TOKEN_LENGTH:
|
| 222 |
input_ids = input_ids[:, -MAX_INPUT_TOKEN_LENGTH:]
|
|
|
|
| 262 |
finally:
|
| 263 |
# Nettoyage de la mΓ©moire GPU
|
| 264 |
torch.cuda.empty_cache()
|
| 265 |
+
|
| 266 |
def vote(data: gr.LikeData, history):
|
| 267 |
user_input = history[-1][0] if history else ""
|
| 268 |
|