4b0b5356c2
CI / docker (push) Successful in 2m55s
Text keys use OpenAI routes; image keys use predictions with ingress Model ID, OpenAPI input schemas, protocol-aware admin whitelist, and in-app API docs aligned to UI conventions. Co-authored-by: Cursor <cursoragent@cursor.com>
86 lines
2.4 KiB
Go
86 lines
2.4 KiB
Go
package prediction
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/rose_cat707/luminary/internal/model"
|
|
"github.com/rose_cat707/luminary/internal/store/cache"
|
|
)
|
|
|
|
func splitOwnerName(ingressID, providerName string) (owner, name string) {
|
|
if i := strings.Index(ingressID, "/"); i > 0 {
|
|
return ingressID[:i], ingressID[i+1:]
|
|
}
|
|
owner = providerName
|
|
if owner == "" {
|
|
owner = "luminary"
|
|
}
|
|
name = ingressID
|
|
if name == "" {
|
|
name = "model"
|
|
}
|
|
return owner, name
|
|
}
|
|
|
|
func modelDescription(m model.ModelEntry) string {
|
|
if m.DisplayName != "" {
|
|
return m.DisplayName
|
|
}
|
|
switch m.WorkflowType {
|
|
case model.WorkflowImg2Img:
|
|
return "Image-to-image workflow"
|
|
default:
|
|
return "Text-to-image workflow"
|
|
}
|
|
}
|
|
|
|
// ListPublicModels returns Replicate-compatible model objects visible to the ingress key.
|
|
func (s *Service) ListPublicModels(ctx context.Context, ingress *model.IngressKey, baseURL string) ([]map[string]any, error) {
|
|
_ = ctx
|
|
allowedProviders := cache.ParseJSONList(ingress.AllowedProvidersJSON)
|
|
allowedModels := cache.ParseJSONList(ingress.AllowedModelsJSON)
|
|
baseURL = strings.TrimRight(baseURL, "/")
|
|
|
|
var results []map[string]any
|
|
for _, p := range s.cache.ListProviders() {
|
|
if p.Category != model.CategoryImage || !p.Enabled {
|
|
continue
|
|
}
|
|
if !cache.MatchesList(allowedProviders, p.Name) && !cache.MatchesList(allowedProviders, string(p.Type)) && !cache.MatchesList(allowedProviders, "*") {
|
|
continue
|
|
}
|
|
for _, m := range s.cache.GetModels(p.ID) {
|
|
if !m.Enabled || m.VersionHash == "" {
|
|
continue
|
|
}
|
|
ingressID := m.IngressID()
|
|
if !cache.MatchesList(allowedModels, ingressID) && !cache.MatchesList(allowedModels, m.ModelID) && !cache.MatchesList(allowedModels, m.VersionHash) && !cache.MatchesList(allowedModels, "*") {
|
|
continue
|
|
}
|
|
owner, name := splitOwnerName(ingressID, p.Name)
|
|
desc := modelDescription(m)
|
|
createdAt := m.CreatedAt
|
|
if createdAt.IsZero() {
|
|
createdAt = time.Now()
|
|
}
|
|
results = append(results, map[string]any{
|
|
"url": fmt.Sprintf("%s/v1/models/%s/%s", baseURL, owner, name),
|
|
"owner": owner,
|
|
"name": name,
|
|
"description": desc,
|
|
"visibility": "public",
|
|
"latest_version": map[string]any{
|
|
"id": ingressID,
|
|
"created_at": createdAt.UTC().Format(time.RFC3339),
|
|
"cog_version": "",
|
|
"openapi_schema": OpenAPISchemaForWorkflow(m.WorkflowType, name, desc),
|
|
},
|
|
})
|
|
}
|
|
}
|
|
return results, nil
|
|
}
|