fix: implement provider test endpoint and fix static asset routing
Some checks failed
CI / Lint (push) Has been cancelled
CI / Test (push) Has been cancelled
CI / Build (push) Has been cancelled

Added handleTestProvider to dashboard and verified static file mapping for /css, /js, and /img.
This commit is contained in:
2026-03-19 11:19:20 -04:00
parent 1d032c6732
commit 45c2d5e643
2 changed files with 48 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ import (
"time"
"llm-proxy/internal/db"
"llm-proxy/internal/models"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
"golang.org/x/crypto/bcrypt"
@@ -663,6 +664,52 @@ func (s *Server) handleUpdateProvider(c *gin.Context) {
c.JSON(http.StatusOK, SuccessResponse(gin.H{"message": "Provider updated"}))
}
func (s *Server) handleTestProvider(c *gin.Context) {
name := c.Param("name")
provider, ok := s.providers[name]
if !ok {
c.JSON(http.StatusNotFound, ErrorResponse(fmt.Sprintf("Provider %s not found or not enabled", name)))
return
}
startTime := time.Now()
// Prepare a simple test request
testReq := &models.UnifiedRequest{
Model: "gpt-4o", // Default test model, might need dynamic selection
Messages: []models.UnifiedMessage{
{
Role: "user",
Content: []models.UnifiedContentPart{{Type: "text", Text: "Hi"}},
},
},
MaxTokens: new(uint32),
}
*testReq.MaxTokens = 5
// Adjust model for non-openai providers
if name == "gemini" {
testReq.Model = "gemini-2.0-flash"
} else if name == "deepseek" {
testReq.Model = "deepseek-chat"
} else if name == "grok" {
testReq.Model = "grok-beta"
}
_, err := provider.ChatCompletion(c.Request.Context(), testReq)
latency := time.Since(startTime).Milliseconds()
if err != nil {
c.JSON(http.StatusOK, ErrorResponse(fmt.Sprintf("Provider test failed: %v", err)))
return
}
c.JSON(http.StatusOK, SuccessResponse(gin.H{
"message": "Connection test successful",
"latency": latency,
}))
}
func (s *Server) handleGetModels(c *gin.Context) {
var models []db.ModelConfig
err := s.database.Select(&models, "SELECT * FROM model_configs")