package main import ( "fmt" "html/template" "io/ioutil" "os" "github.com/microcosm-cc/bluemonday" "gopkg.in/yaml.v3" ) var modelPageTemplate string = ` LocalAI models

LocalAI model gallery list


🖼️ Available {{.AvailableModels}} models

Refer to the Model gallery for more information on how to use the models with LocalAI.
You can install models with the CLI command local-ai models install . or by using the WebUI.

{{ range $_, $model := .Models }}
{{ $icon := "https://upload.wikimedia.org/wikipedia/commons/6/65/No-Image-Placeholder.svg" }} {{ if $model.Icon }} {{ $icon = $model.Icon }} {{ end }}
{{$model.Name}}
{{$model.Name}}

{{ $model.Description }}

{{ end }}
` type GalleryModel struct { Name string `json:"name" yaml:"name"` URLs []string `json:"urls" yaml:"urls"` Icon string `json:"icon" yaml:"icon"` Description string `json:"description" yaml:"description"` } func main() { // read the YAML file which contains the models f, err := ioutil.ReadFile(os.Args[1]) if err != nil { fmt.Println("Error reading file:", err) return } models := []*GalleryModel{} err = yaml.Unmarshal(f, &models) if err != nil { // write to stderr os.Stderr.WriteString("Error unmarshaling YAML: " + err.Error() + "\n") return } // Ensure that all arbitrary text content is sanitized before display for i, m := range models { models[i].Name = bluemonday.StrictPolicy().Sanitize(m.Name) models[i].Description = bluemonday.StrictPolicy().Sanitize(m.Description) } // render the template data := struct { Models []*GalleryModel AvailableModels int }{ Models: models, AvailableModels: len(models), } tmpl := template.Must(template.New("modelPage").Parse(modelPageTemplate)) err = tmpl.Execute(os.Stdout, data) if err != nil { fmt.Println("Error executing template:", err) return } }