return models sorted by id in /v1/models (#222)

This commit is contained in:
Ben Greene
2025-08-06 12:04:52 -05:00
committed by GitHub
parent 8be5073c51
commit 5c63e0066c
2 changed files with 53 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ import (
"mime/multipart"
"net/http"
"os"
"sort"
"strconv"
"strings"
"sync"
@@ -333,6 +334,13 @@ func (pm *ProxyManager) listModelsHandler(c *gin.Context) {
data = append(data, record)
}
// Sort by the "id" key
sort.Slice(data, func(i, j int) bool {
si, _ := data[i]["id"].(string)
sj, _ := data[j]["id"].(string)
return si < sj
})
// Set CORS headers if origin exists
if origin := c.GetHeader("Origin"); origin != "" {
c.Header("Access-Control-Allow-Origin", origin)