fix: implement provider test endpoint and fix static asset routing
Added handleTestProvider to dashboard and verified static file mapping for /css, /js, and /img.
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"llm-proxy/internal/db"
|
"llm-proxy/internal/db"
|
||||||
|
"llm-proxy/internal/models"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"golang.org/x/crypto/bcrypt"
|
"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"}))
|
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) {
|
func (s *Server) handleGetModels(c *gin.Context) {
|
||||||
var models []db.ModelConfig
|
var models []db.ModelConfig
|
||||||
err := s.database.Select(&models, "SELECT * FROM model_configs")
|
err := s.database.Select(&models, "SELECT * FROM model_configs")
|
||||||
|
|||||||
@@ -118,6 +118,7 @@ func (s *Server) setupRoutes() {
|
|||||||
|
|
||||||
admin.GET("/providers", s.handleGetProviders)
|
admin.GET("/providers", s.handleGetProviders)
|
||||||
admin.PUT("/providers/:name", s.handleUpdateProvider)
|
admin.PUT("/providers/:name", s.handleUpdateProvider)
|
||||||
|
admin.POST("/providers/:name/test", s.handleTestProvider)
|
||||||
admin.GET("/models", s.handleGetModels)
|
admin.GET("/models", s.handleGetModels)
|
||||||
|
|
||||||
admin.GET("/users", s.handleGetUsers)
|
admin.GET("/users", s.handleGetUsers)
|
||||||
|
|||||||
Reference in New Issue
Block a user