Split ingress keys into text/image protocols with Replicate model listing.
CI / docker (push) Successful in 3m38s
CI / docker (push) Successful in 3m38s
Add model input defaults (including prompt), workflow model editing, ingress API docs, and fix img2img image upload filenames for signed URLs. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
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) {
|
||||
return model.SplitIngressOwnerName(ingressID, providerName)
|
||||
}
|
||||
|
||||
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)
|
||||
defaults, _ := ParseInputDefaults(m.InputDefaultsJSON)
|
||||
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, defaults),
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
return results, nil
|
||||
}
|
||||
Reference in New Issue
Block a user