compaction de contexte, filtre/pagination/suppression des conversations
- compaction automatique du contexte LLM quand la taille atteint le seuil (contexte max - taille de réponse max), par résumé de l'historique ancien - filtre textuel (?q=) et pagination (20/page) de l'historique des conversations - correctif ORM : offset de pagination en base 0 - suppression d'une conversation : messages associés supprimés, session en cours annulée, popup de confirmation (ConfirmDialog) - titres de conversation nettoyés du markdown - styles des listes markdown, variante danger du bouton - go.mod/go.sum : dépendances go-rod et stealth manquantes du commit précédent
This commit is contained in:
1 parent
a970bfa991
commit
51bbb45b32
86 files changed
+770
-113
No files matched your search
@@ -3,10 +3,30 @@ package chat
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
"trankilou.fr/lassistanoque/backend/internal/domain"
|
||||
)
|
||||
|
||||
// markdownDecorations liste les marqueurs markdown susceptibles d'apparaître
|
||||
// dans un titre généré par un LLM.
|
||||
var markdownDecorations = []string{"**", "__", "~~", "*", "_", "~", "#", "`"}
|
||||
|
||||
func sanitizeTitle(title string) string {
|
||||
title = strings.TrimSpace(title)
|
||||
// le titre doit tenir sur une ligne
|
||||
title = strings.ReplaceAll(title, "\n", " ")
|
||||
// guillemets et tirets d'encadrement ajoutés par le LLM
|
||||
title = strings.Trim(title, `"'«»`)
|
||||
// décorations markdown
|
||||
for _, marker := range markdownDecorations {
|
||||
title = strings.ReplaceAll(title, marker, "")
|
||||
}
|
||||
// espaces multiples créés par les suppressions
|
||||
title = strings.Join(strings.Fields(title), " ")
|
||||
return strings.TrimSpace(title)
|
||||
}
|
||||
|
||||
func (s *Service) RefreshTitles(provider *domain.Provider, modelID string, teamID string) {
|
||||
|
||||
ctx := context.Background()
|
||||
@@ -24,14 +44,19 @@ func (s *Service) RefreshTitles(provider *domain.Provider, modelID string, teamI
|
||||
slog.Error("RefreshTitles.GetMessages", "error", err)
|
||||
}
|
||||
title, err := s.llmEngine.Generate(ctx, provider, modelID, append(messages, &domain.Message{
|
||||
Role: string(domain.RoleSystem),
|
||||
Content: "Tu génères un titre de conversation. Réponds uniquement par le titre, " +
|
||||
"en texte brut : jamais de markdown (pas de **, *, _, ~, #), " +
|
||||
"pas de guillemets, pas de liste, pas de ponctuation finale.",
|
||||
}, &domain.Message{
|
||||
Role: string(domain.RoleUser),
|
||||
Content: "resume toute la conversation dans un titre entre 5 et 10 mots",
|
||||
Content: "Résume toute la conversation dans un titre entre 5 et 10 mots, en texte brut, sans aucun formatage.",
|
||||
}))
|
||||
if err != nil {
|
||||
slog.Error("RefreshTitles.Generate", "error", err)
|
||||
}
|
||||
newchat.FreshTitle = true
|
||||
newchat.Title = title
|
||||
newchat.Title = sanitizeTitle(title)
|
||||
s.repoChat.UpdateChat(newchat.UserID, newchat)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user