chatai/main.go

50 lines
1.5 KiB
Go
Raw Normal View History

2024-12-25 17:18:23 +00:00
package main
import (
"flag"
"os"
2025-01-11 04:31:04 +00:00
"devops.lty.name/luo/chatai/internal/config"
"devops.lty.name/luo/chatai/internal/log"
"devops.lty.name/luo/chatai/internal/server"
2024-12-25 17:18:23 +00:00
"github.com/gin-gonic/gin"
)
func main() {
2025-01-11 04:31:04 +00:00
listen := flag.String("listen", config.FlagListen, "http listen address")
agentsDir := flag.String("agents", config.FlagAgentsDir, "directory to store agent configurations")
logLevel := flag.String("level", config.FlagLogLevel, "log level (dbg, inf, wrn, err)")
msgLogPath := flag.String("msglog", config.FlagMsgLogPath, "audit log path")
model := flag.String("model", config.DefaultGoogleAIModel, "Google AI model (gemini-1.5-flash, gemini-2.0-flash-exp)")
2024-12-25 17:18:23 +00:00
flag.Parse()
server.GoogleAIKey = os.Getenv("GOOGLE_AI_KEY")
if server.GoogleAIKey == "" {
log.T("main").Errf("GOOGLE_AI_KEY environment variable is not set")
os.Exit(1)
}
server.GoogleAIModel = *model
log.Setup(log.LogLevel(log.ParseLogLevel(*logLevel)))
2025-01-11 04:31:04 +00:00
log.T("main").Inff("AI-Agent version %s, %s mode (build %s)", config.BuildVersion, config.BuildMode, config.BuildTime)
log.T("main").Inff("%s", config.Copyright)
2024-12-25 17:18:23 +00:00
log.SetupGin1()
2025-01-11 04:31:04 +00:00
if config.BuildMode == "release" {
2024-12-25 17:18:23 +00:00
gin.SetMode(gin.ReleaseMode)
}
engine := gin.New()
engine.Use(gin.Recovery())
log.SetupGin2(engine)
server.Setup(engine, *agentsDir, *msgLogPath)
log.T("main").Inff("Starting server on %s", *listen)
err := engine.Run(*listen)
if err != nil {
log.T("main").Errf("Server error: %v", err)
os.Exit(1)
}
}