Cachinde commited on
Commit
08b0f79
·
1 Parent(s): a66c44d

fix: sanitizador generalizado (qualquer variante da marca/bot vira forma correta, com guardas)

Browse files
Files changed (1) hide show
  1. ai_engine.py +23 -5
ai_engine.py CHANGED
@@ -51,13 +51,29 @@ def tirar_saudacao(resposta: str, nome: str = "") -> str:
51
  return texto if texto else (resposta or "").strip()
52
 
53
 
54
- # Corrupções observadas no Llama-8B -> forma correcta.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  # Lista fechada (só o que já apareceu nos logs); ordem importa.
56
  _CORRECOES = [
57
- (r"\bNeg(?:re|rela|rega|reira|ral)\s+Plena\b"
58
- r"|\bNegra\s+(?:Pena|Piena)\b"
59
- r"|\bNegral\s+(?:Piena|Pi[ñn]a)\b", "Negra Plena"),
60
- (r"\bPlentude\b|\bPlenuidade\b", "Plenitude"),
61
  (r"\bservicios\b", "serviços"),
62
  (r"\bpasteleira\b|\bpasteleria\b", "pastelaria"),
63
  (r"\bmás\b", "mais"),
@@ -79,6 +95,8 @@ _CORRECOES_RX = [(re.compile(pat, re.IGNORECASE), rep) for pat, rep in _CORRECOE
79
  def sanitizar(resposta: str) -> str:
80
  """Corrige corrupções conhecidas do 8B (nomes, idioma, produtos)."""
81
  texto = resposta or ""
 
 
82
  for rx, rep in _CORRECOES_RX:
83
  texto = rx.sub(rep, texto)
84
  return texto.strip() or (resposta or "").strip()
 
51
  return texto if texto else (resposta or "").strip()
52
 
53
 
54
+ # Marca e assistente: qualquer par parecido vira a forma correcta,
55
+ # menos a forma correcta (guardas). Cobre variantes ainda não vistas.
56
+ _MARCA = re.compile(r"\bNeg[a-z]{1,6}\s+[Pp][a-z]{2,6}\b", re.IGNORECASE)
57
+ _BOTNOME = re.compile(r"\bPlen[a-z]{4,7}\b", re.IGNORECASE)
58
+
59
+
60
+ def _fix_marca(m):
61
+ a, b = m.group(0).split()
62
+ if a.lower() == "negra" and b.lower() == "plena":
63
+ return m.group(0)
64
+ return "Negra Plena"
65
+
66
+
67
+ def _fix_botnome(m):
68
+ w = m.group(0)
69
+ if w.lower() == "plenitude":
70
+ return w
71
+ return "Plenitude"
72
+
73
+
74
+ # Outras corrupções observadas no Llama-8B -> forma correcta.
75
  # Lista fechada (só o que já apareceu nos logs); ordem importa.
76
  _CORRECOES = [
 
 
 
 
77
  (r"\bservicios\b", "serviços"),
78
  (r"\bpasteleira\b|\bpasteleria\b", "pastelaria"),
79
  (r"\bmás\b", "mais"),
 
95
  def sanitizar(resposta: str) -> str:
96
  """Corrige corrupções conhecidas do 8B (nomes, idioma, produtos)."""
97
  texto = resposta or ""
98
+ texto = _MARCA.sub(_fix_marca, texto)
99
+ texto = _BOTNOME.sub(_fix_botnome, texto)
100
  for rx, rep in _CORRECOES_RX:
101
  texto = rx.sub(rep, texto)
102
  return texto.strip() or (resposta or "").strip()