Files
Fabric/internal/server/models.go
Kayvan Sylvan 4004c51b9e refactor: restructure project to align with standard Go layout
### CHANGES

- Introduce `cmd` directory for all main application binaries.
- Move all Go packages into the `internal` directory.
- Rename the `restapi` package to `server` for clarity.
- Consolidate patterns and strategies into a new `data` directory.
- Group all auxiliary scripts into a new `scripts` directory.
- Move all documentation and images into a `docs` directory.
- Update all Go import paths to reflect the new structure.
- Adjust CI/CD workflows and build commands for new layout.
2025-07-08 22:47:17 -07:00

46 lines
1.1 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)
}
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]interface{})
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
}