-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
64 lines (51 loc) · 2.5 KB
/
main.go
File metadata and controls
64 lines (51 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"context"
"net/http"
"com.deablabs.teno-voice/internal/auth"
"com.deablabs.teno-voice/internal/calls"
Config "com.deablabs.teno-voice/internal/config"
"com.deablabs.teno-voice/internal/deps"
"com.deablabs.teno-voice/internal/llm"
"com.deablabs.teno-voice/internal/redis"
texttospeech "com.deablabs.teno-voice/internal/textToSpeech"
"github.com/disgoorg/log"
"github.com/go-chi/chi"
"github.com/go-playground/validator/v10"
)
var validate *validator.Validate
func main() {
// log.SetLevel(log.LevelTrace)
// log.SetFlags(log.LstdFlags | log.Llongfile)
validate = validator.New()
validate.RegisterValidation("LLMConfigValidation", llm.LLMConfigValidation)
validate.RegisterValidation("TTSConfigValidation", texttospeech.TTSConfigValidation)
log.Info("starting up")
redisAddr := Config.Environment.Redis
redisClient, redisCloseClient := redis.NewClient(context.Background(), redisAddr)
defer redisCloseClient()
// create a new instance of the Deps struct
// We pass this struct into the handlers so they can access the discord client
// and kill signal
dependencies := &deps.Deps{RedisClient: redisClient, Validate: validate}
// Set up the router, connected to discord functionality
router := chi.NewRouter()
router.Use(auth.ApiKeyAuthMiddleware(Config.Environment.ApiKey))
// Accepts join request and joins the voice channel
router.Post("/join", calls.JoinVoiceChannel(dependencies))
// Accepts leave request and leaves the voice channel
router.Post("/{bot_id}/{guild_id}/leave", calls.LeaveVoiceChannel(dependencies))
// Accepts a Config object and sets the responder config
router.Post("/{bot_id}/{guild_id}/config", calls.UpdateConfig(dependencies))
// Subscribes to the transcript SSE stream, which sends lines of the transcript as strings when new lines are available
router.Get("/{bot_id}/{guild_id}/transcript", calls.TranscriptSSEHandler(dependencies))
// Subscribes to the tool messages SSE stream, which sends tool messages as strings when the responder sends them
router.Get("/{bot_id}/{guild_id}/tool-messages", calls.ToolMessagesSSEHandler(dependencies))
// Subscribes to the usages SSE stream, which sends tts, transcription, and llm usage events as strings when the responder sends them
router.Get("/{bot_id}/{guild_id}/service-usages", calls.UsageSSEHandler(dependencies))
// Start the REST API server
log.Info("Starting REST API server on :8080")
if err := http.ListenAndServe(":8080", router); err != nil {
log.Fatalf("Error starting REST API server: %v", err)
}
}