feat: full model catalog (settings enabledModels + custom providers) and provider credentials in spawned containers (keys passthrough + host auth.json bind)
This commit is contained in:
+38
-2
@@ -23,8 +23,10 @@ import (
|
||||
const (
|
||||
envToken string = "LVMH_TOKEN"
|
||||
|
||||
envModelsFile string = "LVMH_MODELS_FILE"
|
||||
defaultModelsFile string = "/app/build/docker/worker-models.json"
|
||||
envSettingsFile string = "LVMH_SETTINGS_FILE"
|
||||
defaultSettingsFile string = "/app/build/docker/pi-agent/settings.json"
|
||||
envModelsFile string = "LVMH_MODELS_FILE"
|
||||
defaultModelsFile string = "/app/build/docker/worker-models.json"
|
||||
|
||||
defaultEventsAfter int64 = 0
|
||||
defaultEventsLimit int = 1000
|
||||
@@ -544,6 +546,27 @@ func parseModelCatalog(data []byte) []ModelCatalogItem {
|
||||
return out
|
||||
}
|
||||
|
||||
// parseEnabledModels turns settings.json "enabledModels" entries
|
||||
// ("provider/model-id") into catalog items, so built-in providers
|
||||
// (anthropic, openai, google, ...) show up next to custom ones.
|
||||
func parseEnabledModels(data []byte) []ModelCatalogItem {
|
||||
var doc struct {
|
||||
EnabledModels []string `json:"enabledModels"`
|
||||
}
|
||||
if err := json.Unmarshal(data, &doc); err != nil {
|
||||
return nil
|
||||
}
|
||||
out := []ModelCatalogItem{}
|
||||
for _, entry := range doc.EnabledModels {
|
||||
provider, id, ok := strings.Cut(entry, "/")
|
||||
if !ok || provider == "" || id == "" {
|
||||
continue
|
||||
}
|
||||
out = append(out, ModelCatalogItem{Provider: provider, ID: id, Name: id})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (s *Server) handleModelCatalog(w http.ResponseWriter, r *http.Request) {
|
||||
data, err := os.ReadFile(envOr(envModelsFile, defaultModelsFile))
|
||||
if err != nil {
|
||||
@@ -555,6 +578,19 @@ func (s *Server) handleModelCatalog(w http.ResponseWriter, r *http.Request) {
|
||||
writeError(w, http.StatusInternalServerError, "model catalog unreadable")
|
||||
return
|
||||
}
|
||||
// Merge in enabled built-in models from the baked pi settings; custom
|
||||
// providers (models.json) win on duplicates.
|
||||
if sdata, serr := os.ReadFile(envOr(envSettingsFile, defaultSettingsFile)); serr == nil {
|
||||
seen := make(map[string]bool, len(catalog))
|
||||
for _, m := range catalog {
|
||||
seen[m.Provider+"/"+m.ID] = true
|
||||
}
|
||||
for _, m := range parseEnabledModels(sdata) {
|
||||
if !seen[m.Provider+"/"+m.ID] {
|
||||
catalog = append(catalog, m)
|
||||
}
|
||||
}
|
||||
}
|
||||
writeJSON(w, http.StatusOK, catalog)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user