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
@@ -18,6 +18,7 @@ type Service struct {
|
||||
repoChat domain.ChatRepository
|
||||
llmEngine domain.LLMEngine
|
||||
runningSessions map[string]*ChatSession
|
||||
sessionCancels map[string]context.CancelFunc
|
||||
toolService *tool.Service
|
||||
mu sync.Mutex
|
||||
}
|
||||
@@ -38,6 +39,7 @@ func NewService(
|
||||
llmEngine: llmEngine,
|
||||
toolService: toolService,
|
||||
runningSessions: make(map[string]*ChatSession),
|
||||
sessionCancels: make(map[string]context.CancelFunc),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,6 +136,17 @@ func (s *Service) AddChatMessage(
|
||||
cb = params.OnChunk
|
||||
}
|
||||
|
||||
contextMax := defaultContextMaxTokens
|
||||
maxResponse := defaultMaxResponseTokens
|
||||
if params != nil {
|
||||
if params.ContextMaxTokens > 0 {
|
||||
contextMax = params.ContextMaxTokens
|
||||
}
|
||||
if params.MaxResponseTokens > 0 {
|
||||
maxResponse = params.MaxResponseTokens
|
||||
}
|
||||
}
|
||||
|
||||
s.runQuery(
|
||||
ctx,
|
||||
userID,
|
||||
@@ -142,6 +155,8 @@ func (s *Service) AddChatMessage(
|
||||
agent,
|
||||
provider,
|
||||
chatModelID,
|
||||
contextMax,
|
||||
maxResponse,
|
||||
messages,
|
||||
cb,
|
||||
)
|
||||
@@ -155,8 +170,8 @@ func (s *Service) AddChatMessage(
|
||||
return message, nil
|
||||
}
|
||||
|
||||
func (s *Service) ListChats(userID string, teamID string, page int) ([]*domain.Chat, error) {
|
||||
return s.repoChat.ListChats(userID, teamID, page)
|
||||
func (s *Service) ListChats(userID string, teamID string, page int, query string) ([]*domain.Chat, error) {
|
||||
return s.repoChat.ListChats(userID, teamID, page, query)
|
||||
}
|
||||
|
||||
func (s *Service) GetChat(userID string, teamID, chatID string) (*domain.Chat, error) {
|
||||
@@ -180,6 +195,15 @@ func (s *Service) GetChatWithMessages(userID string, teamID, chatID string) (*do
|
||||
}
|
||||
|
||||
func (s *Service) DeleteChat(userID string, teamID, chatID string) error {
|
||||
// stoppe une éventuelle session en cours avant la suppression
|
||||
s.mu.Lock()
|
||||
if cancel, ok := s.sessionCancels[chatID]; ok {
|
||||
cancel()
|
||||
}
|
||||
delete(s.runningSessions, chatID)
|
||||
delete(s.sessionCancels, chatID)
|
||||
s.mu.Unlock()
|
||||
|
||||
return s.repoChat.DeleteChat(userID, teamID, chatID)
|
||||
}
|
||||
|
||||
@@ -191,30 +215,38 @@ func (s *Service) runQuery(
|
||||
agent *domain.Agent,
|
||||
provider *domain.Provider,
|
||||
modelID string,
|
||||
contextMaxTokens int,
|
||||
maxResponseTokens int,
|
||||
messages []*domain.Message,
|
||||
callback domain.StreamCallback,
|
||||
) error {
|
||||
|
||||
chatSession := &ChatSession{
|
||||
userID: userID,
|
||||
teamID: teamID,
|
||||
chatID: chatID,
|
||||
agent: agent,
|
||||
provider: provider,
|
||||
modelID: modelID,
|
||||
messages: messages,
|
||||
llmEngine: s.llmEngine,
|
||||
toolService: s.toolService,
|
||||
subscribers: make([]domain.StreamCallback, 0),
|
||||
repoChat: s.repoChat,
|
||||
userID: userID,
|
||||
teamID: teamID,
|
||||
chatID: chatID,
|
||||
agent: agent,
|
||||
provider: provider,
|
||||
modelID: modelID,
|
||||
messages: messages,
|
||||
contextMaxTokens: contextMaxTokens,
|
||||
maxResponseTokens: maxResponseTokens,
|
||||
llmEngine: s.llmEngine,
|
||||
toolService: s.toolService,
|
||||
subscribers: make([]domain.StreamCallback, 0),
|
||||
repoChat: s.repoChat,
|
||||
}
|
||||
|
||||
if callback != nil {
|
||||
chatSession.subscribers = append(chatSession.subscribers, callback)
|
||||
}
|
||||
|
||||
// contexte annulable : permet d'arrêter la session (ex. suppression du chat)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
|
||||
s.mu.Lock()
|
||||
s.runningSessions[chatID] = chatSession
|
||||
s.sessionCancels[chatID] = cancel
|
||||
s.mu.Unlock()
|
||||
|
||||
go func() {
|
||||
@@ -222,7 +254,11 @@ func (s *Service) runQuery(
|
||||
if err != nil {
|
||||
slog.Info("chat session error", "error", err)
|
||||
}
|
||||
s.mu.Lock()
|
||||
delete(s.runningSessions, chatID)
|
||||
delete(s.sessionCancels, chatID)
|
||||
s.mu.Unlock()
|
||||
cancel()
|
||||
}()
|
||||
|
||||
return nil
|
||||
|
||||
Reference in new issue
Block a user