Files
Fabric/internal/server/models.go
Kayvan Sylvan c06c94f8b8 # CHANGES
- Add Swagger UI at `/swagger/index.html` endpoint
- Generate OpenAPI spec files (JSON and YAML)
- Document chat, patterns, and models endpoints
- Update contributing guide with Swagger annotation instructions
- Add swaggo dependencies to project
- Configure authentication bypass for Swagger documentation
- Add custom YAML handler for OpenAPI spec
- Update REST API documentation with Swagger links
- Add dictionary entries for new tools
2025-12-18 07:12:08 -08:00

55 lines
1.4 KiB
Go
Executable File

package restapi
import (
"github.com/danielmiessler/fabric/internal/plugins/ai"
"github.com/gin-gonic/gin"
)
type ModelsHandler struct {
vendorManager *ai.VendorsManager
}
func NewModelsHandler(r *gin.Engine, vendorManager *ai.VendorsManager) {
handler := &ModelsHandler{
vendorManager: vendorManager,
}
r.GET("/models/names", handler.GetModelNames)
}
// GetModelNames godoc
// @Summary List all available models
// @Description Get a list of all available AI models grouped by vendor
// @Tags models
// @Produce json
// @Success 200 {object} map[string]interface{} "Returns models (array) and vendors (map)"
// @Failure 500 {object} map[string]string
// @Security ApiKeyAuth
// @Router /models/names [get]
func (h *ModelsHandler) GetModelNames(c *gin.Context) {
vendorsModels, err := h.vendorManager.GetModels()
if err != nil {
c.JSON(500, gin.H{"error": "Server failed to retrieve model names"})
return
}
response := make(map[string]any)
vendors := make(map[string][]string)
for _, groupItems := range vendorsModels.GroupsItems {
vendors[groupItems.Group] = groupItems.Items
}
response["models"] = h.getAllModelNames(vendorsModels)
response["vendors"] = vendors
c.JSON(200, response)
}
func (h *ModelsHandler) getAllModelNames(vendorsModels *ai.VendorsModels) []string {
var allModelNames []string
for _, groupItems := range vendorsModels.GroupsItems {
allModelNames = append(allModelNames, groupItems.Items...)
}
return allModelNames
}