notes
This commit is contained in:
76
app.py
76
app.py
@@ -179,6 +179,20 @@ def detecter_action_directe(texte):
|
||||
texte_nettoye = texte.strip()
|
||||
texte_min = texte_nettoye.lower()
|
||||
|
||||
clients_a_ajouter = extraire_liste_clients(texte_nettoye)
|
||||
if clients_a_ajouter:
|
||||
return {
|
||||
"actions": [
|
||||
{
|
||||
"action": "ajouter_client",
|
||||
"nom": nom,
|
||||
"notes": "Ajoute depuis une liste dictee par Laurent.",
|
||||
"statut": "actif",
|
||||
}
|
||||
for nom in clients_a_ajouter
|
||||
]
|
||||
}
|
||||
|
||||
recherche_match = re.search(
|
||||
r"(?:qu(?:'| )?est[- ]?ce que tu sais sur|que sais[- ]?tu sur|cherche dans la memoire|memoire sur)\s+(.+)",
|
||||
texte_nettoye,
|
||||
@@ -247,6 +261,61 @@ def detecter_action_directe(texte):
|
||||
return {"actions": actions}
|
||||
|
||||
|
||||
def extraire_liste_clients(texte):
|
||||
if not re.search(r"\bclients?\b", texte, flags=re.IGNORECASE):
|
||||
return []
|
||||
if not re.search(r"\b(voici|liste|note|notes|noter|memorise|ajoute|ajoutes)\b", texte, flags=re.IGNORECASE):
|
||||
return []
|
||||
|
||||
lignes = [ligne.strip(" -\t\r.,;") for ligne in texte.splitlines()]
|
||||
candidats = []
|
||||
apres_entete = False
|
||||
|
||||
for ligne in lignes:
|
||||
if not ligne:
|
||||
continue
|
||||
ligne_min = ligne.lower()
|
||||
if "client" in ligne_min:
|
||||
apres_entete = True
|
||||
apres_deux_points = ligne.split(":", 1)[1].strip() if ":" in ligne else ""
|
||||
if apres_deux_points:
|
||||
candidats.extend(separer_noms_clients(apres_deux_points))
|
||||
continue
|
||||
if not apres_entete:
|
||||
continue
|
||||
if re.search(r"\b(note|notes|noter|quelque part|merci|stp|s'il te plait)\b", ligne_min):
|
||||
continue
|
||||
candidats.extend(separer_noms_clients(ligne))
|
||||
|
||||
noms = []
|
||||
deja_vus = set()
|
||||
for candidat in candidats:
|
||||
nom = nettoyer_nom_client(candidat)
|
||||
if not nom:
|
||||
continue
|
||||
cle = nom.lower()
|
||||
if cle not in deja_vus:
|
||||
noms.append(nom)
|
||||
deja_vus.add(cle)
|
||||
return noms
|
||||
|
||||
|
||||
def separer_noms_clients(texte):
|
||||
morceaux = re.split(r"[,;/]|\s+\bet\b\s+", texte)
|
||||
return [morceau.strip() for morceau in morceaux if morceau.strip()]
|
||||
|
||||
|
||||
def nettoyer_nom_client(nom):
|
||||
nom = nom.strip(" -\t\r.,;:")
|
||||
if not nom or len(nom) < 2:
|
||||
return ""
|
||||
if re.search(r"\b(liste|clients?|voici|note|notes|noter|quelque|part)\b", nom, flags=re.IGNORECASE):
|
||||
return ""
|
||||
if len(nom.split()) > 4:
|
||||
return ""
|
||||
return nom
|
||||
|
||||
|
||||
def transcrire_audio(fichier):
|
||||
suffix = Path(fichier.filename or "voice.webm").suffix or ".webm"
|
||||
with tempfile.NamedTemporaryFile(delete=False, suffix=suffix) as tmp:
|
||||
@@ -375,15 +444,22 @@ def executer_actions(action_data):
|
||||
"memorySaved": False,
|
||||
"memoryRead": False,
|
||||
}
|
||||
actions_executees = []
|
||||
for action in actions:
|
||||
if not isinstance(action, dict):
|
||||
continue
|
||||
reponse, action_flags = executer_action(action)
|
||||
actions_executees.append(action)
|
||||
if reponse:
|
||||
reponses.append(reponse)
|
||||
for cle in flags:
|
||||
flags[cle] = flags[cle] or bool(action_flags.get(cle))
|
||||
|
||||
if actions_executees and all(action.get("action") == "ajouter_client" for action in actions_executees):
|
||||
noms = [action.get("nom", "").strip() for action in actions_executees if action.get("nom", "").strip()]
|
||||
if len(noms) > 1:
|
||||
return f"C'est note : {len(noms)} clients ajoutes ({', '.join(noms)}).", flags
|
||||
|
||||
return " ".join(reponses), flags
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user