You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
901 B
37 lines
901 B
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,
|
|
})
|
|
}
|
|
}
|
|
|