mirror of
https://github.com/mudler/LocalAI.git
synced 2024-06-07 19:40:48 +00:00
5dcfdbe51d
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
38 lines
901 B
Go
38 lines
901 B
Go
package openai
|
|
|
|
import (
|
|
config "github.com/go-skynet/LocalAI/api/config"
|
|
model "github.com/go-skynet/LocalAI/pkg/model"
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
func ListModelsEndpoint(loader *model.ModelLoader, cm *config.ConfigLoader) func(ctx *fiber.Ctx) error {
|
|
return func(c *fiber.Ctx) error {
|
|
models, err := loader.ListModels()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
var mm map[string]interface{} = map[string]interface{}{}
|
|
|
|
dataModels := []OpenAIModel{}
|
|
for _, m := range models {
|
|
mm[m] = nil
|
|
dataModels = append(dataModels, OpenAIModel{ID: m, Object: "model"})
|
|
}
|
|
|
|
for _, k := range cm.ListConfigs() {
|
|
if _, exists := mm[k]; !exists {
|
|
dataModels = append(dataModels, OpenAIModel{ID: k, Object: "model"})
|
|
}
|
|
}
|
|
|
|
return c.JSON(struct {
|
|
Object string `json:"object"`
|
|
Data []OpenAIModel `json:"data"`
|
|
}{
|
|
Object: "list",
|
|
Data: dataModels,
|
|
})
|
|
}
|
|
}
|