Completions api (#8) (#29)

This commit is contained in:
2026-02-16 17:00:11 +00:00
parent d83217504c
commit d9ab162dfb
13 changed files with 1885 additions and 113 deletions

View File

@@ -9,11 +9,15 @@ import (
"git.gobha.me/xcaliber/chat-switchboard/database"
"git.gobha.me/xcaliber/chat-switchboard/handlers"
"git.gobha.me/xcaliber/chat-switchboard/middleware"
"git.gobha.me/xcaliber/chat-switchboard/providers"
)
func main() {
cfg := config.Load()
// Register LLM providers
providers.Init()
if err := database.Connect(cfg); err != nil {
log.Printf("⚠ Database unavailable: %v", err)
log.Println(" Running in unmanaged mode (no persistence)")
@@ -23,7 +27,7 @@ func main() {
r := gin.Default()
r.Use(middleware.CORS())
// Health check
// Health check (k8s probes hit this directly)
r.GET("/health", func(c *gin.Context) {
c.JSON(200, gin.H{
"status": "ok",
@@ -36,15 +40,17 @@ func main() {
auth := handlers.NewAuthHandler(cfg)
authLimiter := middleware.NewRateLimiter(1, 5)
api := r.Group("/api/v1")
{
api.GET("/health", func(c *gin.Context) {
c.JSON(200, gin.H{
"status": "ok",
"version": Version,
"database": database.IsConnected(),
})
})
api := r.Group("/api/v1")
{
// Health (routable through ingress)
api.GET("/health", func(c *gin.Context) {
c.JSON(200, gin.H{
"status": "ok",
"version": Version,
"database": database.IsConnected(),
"providers": providers.List(),
})
})
authGroup := api.Group("/auth")
authGroup.Use(authLimiter.Limit())
@@ -71,23 +77,32 @@ func main() {
msgs := handlers.NewMessageHandler()
protected.GET("/chats/:id/messages", msgs.ListMessages)
protected.POST("/chats/:id/messages", msgs.CreateMessage)
protected.POST("/chats/:id/regenerate", msgs.Regenerate)
// Settings — ticket #10
// ── Chat Engine (#8) ────────────────
comp := handlers.NewCompletionHandler()
protected.POST("/chat/completions", comp.Complete)
protected.POST("/chats/:id/regenerate", msgs.Regenerate) // TODO: wire to completion handler
// API Configs
apiCfg := handlers.NewAPIConfigHandler()
protected.GET("/api-configs", apiCfg.ListConfigs)
protected.POST("/api-configs", apiCfg.CreateConfig)
protected.GET("/api-configs/:id", apiCfg.GetConfig)
protected.PUT("/api-configs/:id", apiCfg.UpdateConfig)
protected.DELETE("/api-configs/:id", apiCfg.DeleteConfig)
// Models (per-config and aggregate)
protected.GET("/api-configs/:id/models", apiCfg.ListModels)
protected.GET("/models", apiCfg.ListAllModels)
// Settings — future
protected.GET("/settings", stubHandler("settings"))
protected.PUT("/settings", stubHandler("settings"))
// API Configs — ticket #10
protected.GET("/api-configs", stubHandler("api-configs"))
protected.POST("/api-configs", stubHandler("api-configs"))
protected.DELETE("/api-configs/:id", stubHandler("api-configs"))
// Models — ticket #10
protected.GET("/models", stubHandler("models"))
}
}
log.Printf("🔀 Chat Switchboard API v%s starting on port %s", Version, cfg.Port)
log.Printf(" Providers: %v", providers.List())
if err := r.Run(":" + cfg.Port); err != nil {
log.Fatalf("Failed to start server: %v", err)
}