Files

67 lines
1.2 KiB
Go

package gateway
import (
"context"
"fmt"
"sync"
"trankilou.fr/lassistanoque/backend/internal/domain"
"trankilou.fr/lassistanoque/backend/internal/utility"
)
type Dependencies struct {
ChatRepository domain.ChatRepository
}
type Router struct {
started bool
mu sync.Mutex
sessions map[string]*Session // running sessions
newSessionChan chan string
closeChan chan bool
}
func NewRouter(deps Dependencies) *Router {
return &Router{
started: true,
sessions: make(map[string]*Session),
newSessionChan: make(chan string),
closeChan: make(chan bool),
}
}
func (s *Router) Start() error {
for {
select {
case _ = <-s.closeChan:
fmt.Println("Closing LLM Server")
return nil
}
}
}
func (s *Router) Stop(ctx context.Context) error {
s.closeChan <- true
s.started = false
return nil
}
func (s *Router) StartSession() (*Session, error) {
sid := utility.GenID()
session := &Session{}
s.mu.Lock()
s.sessions[sid] = session
s.mu.Unlock()
return session, nil
}
func (s *Router) Process(ctx context.Context, Chat *domain.ChatWithMessages) error {
s.closeChan <- true
s.started = false
return nil
}