Skip to content

Commit a285d66

Browse files
mholder6pierDipiisrael-hdez
authored
fix: expose the actual model name instead of the resource name (#143)
* expose the actual model name instead of the resource name for the /v1/models endpoint * Update maas-api/internal/models/kserve.go Co-authored-by: Pierangelo Di Pilato <pierangelodipilato@gmail.com> * updated testing isvc to be llmisvc * typo * squash * Update maas-api/internal/handlers/models_test.go Co-authored-by: Edgar Hernández <ehernand@redhat.com> * updated the test to test the fallback logic instead --------- Co-authored-by: Pierangelo Di Pilato <pierangelodipilato@gmail.com> Co-authored-by: Edgar Hernández <ehernand@redhat.com>
1 parent d6d491f commit a285d66

File tree

3 files changed

+64
-10
lines changed

3 files changed

+64
-10
lines changed

maas-api/internal/handlers/models_test.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import (
1717
)
1818

1919
func TestListingModels(t *testing.T) {
20+
strptr := func(s string) *string { return &s }
21+
2022
llmTestScenarios := []fixtures.LLMTestScenario{
2123
{
2224
Name: "llama-7b",
@@ -48,6 +50,13 @@ func TestListingModels(t *testing.T) {
4850
URL: fixtures.PublicURL(""),
4951
Ready: false,
5052
},
53+
{
54+
Name: "fallback-model-name",
55+
Namespace: fixtures.TestNamespace,
56+
URL: fixtures.PublicURL("http://fallback-model-name." + fixtures.TestNamespace + ".acme.com/v1"),
57+
Ready: true,
58+
SpecModelName: strptr("fallback-model-name"),
59+
},
5160
}
5261
llmInferenceServices := fixtures.CreateLLMInferenceServices(llmTestScenarios...)
5362

@@ -88,11 +97,17 @@ func TestListingModels(t *testing.T) {
8897
var testCases []expectedModel
8998

9099
for _, llmTestScenario := range llmTestScenarios {
100+
// expected ID mirrors toModels(): fallback to metadata.name unless spec.model.name is non-empty
101+
expectedModelID := llmTestScenario.Name
102+
if llmTestScenario.SpecModelName != nil && *llmTestScenario.SpecModelName != "" {
103+
expectedModelID = *llmTestScenario.SpecModelName
104+
}
105+
91106
testCases = append(testCases, expectedModel{
92-
name: llmTestScenario.Name,
107+
name: expectedModelID,
93108
expectedModel: models.Model{
94109
Model: openai.Model{
95-
ID: llmTestScenario.Name,
110+
ID: expectedModelID,
96111
Object: "model",
97112
OwnedBy: llmTestScenario.Namespace,
98113
},

maas-api/internal/models/kserve.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,24 @@ func toModels(list *unstructured.UnstructuredList) ([]Model, error) {
7878
for _, item := range list.Items {
7979
url, errURL := findURL(item)
8080
if errURL != nil {
81-
log.Printf("DEBUG: Failed to find URL for %s: %v", item.GetKind(), errURL)
81+
log.Printf("DEBUG: Failed to find URL for %s %s/%s: %v",
82+
item.GetKind(), item.GetNamespace(), item.GetName(), errURL)
83+
}
84+
85+
// Default to metadata.name
86+
modelID := item.GetName()
87+
88+
// Check if .spec.model.name exists
89+
if name, found, err := unstructured.NestedString(item.Object, "spec", "model", "name"); err != nil {
90+
log.Printf("DEBUG: Error reading spec.model.name for %s %s/%s: %v",
91+
item.GetKind(), item.GetNamespace(), item.GetName(), err)
92+
} else if found && name != "" {
93+
modelID = name
8294
}
8395

8496
models = append(models, Model{
8597
Model: openai.Model{
86-
ID: item.GetName(),
98+
ID: modelID,
8799
Object: "model",
88100
OwnedBy: item.GetNamespace(),
89101
Created: item.GetCreationTimestamp().Unix(),

maas-api/test/fixtures/llm_models.go

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,17 @@ func (i AddressEntry) AddTo(obj *unstructured.Unstructured) {
4242
}, "status", "addresses")
4343
}
4444

45+
type LLMInferenceServiceOption func(*unstructured.Unstructured)
46+
47+
// WithSpecModelName sets .spec.model.name (can be an empty string "" to test fallback logic).
48+
func WithSpecModelName(name string) LLMInferenceServiceOption {
49+
return func(obj *unstructured.Unstructured) {
50+
_ = unstructured.SetNestedField(obj.Object, name, "spec", "model", "name")
51+
}
52+
}
53+
4554
// CreateLLMInferenceService creates a test LLMInferenceService unstructured object
46-
func CreateLLMInferenceService(name, namespace string, url ModelURL, ready bool) *unstructured.Unstructured {
55+
func CreateLLMInferenceService(name, namespace string, url ModelURL, ready bool, opts ...LLMInferenceServiceOption) *unstructured.Unstructured {
4756
obj := &unstructured.Unstructured{}
4857
obj.Object = map[string]any{}
4958
obj.SetAPIVersion("serving.kserve.io/v1alpha1")
@@ -114,22 +123,40 @@ func CreateLLMInferenceService(name, namespace string, url ModelURL, ready bool)
114123

115124
_ = unstructured.SetNestedSlice(obj.Object, conditions, "status", "conditions")
116125

126+
// Apply options (e.g., WithSpecModelName)
127+
for _, opt := range opts {
128+
opt(obj)
129+
}
130+
117131
return obj
118132
}
119133

120134
// LLMTestScenario defines a test scenario for LLM models
121135
type LLMTestScenario struct {
122-
Name string
123-
Namespace string
124-
URL ModelURL
125-
Ready bool
136+
Name string
137+
Namespace string
138+
URL ModelURL
139+
Ready bool
140+
SpecModelName *string
126141
}
127142

128143
// CreateLLMInferenceServices creates a set of test LLM objects for testing
129144
func CreateLLMInferenceServices(scenarios ...LLMTestScenario) []runtime.Object {
130145
var objects []runtime.Object
131146
for _, scenario := range scenarios {
132-
obj := CreateLLMInferenceService(scenario.Name, scenario.Namespace, scenario.URL, scenario.Ready)
147+
var opts []LLMInferenceServiceOption
148+
if scenario.SpecModelName != nil {
149+
opts = append(opts, WithSpecModelName(*scenario.SpecModelName))
150+
}
151+
152+
obj := CreateLLMInferenceService(
153+
scenario.Name,
154+
scenario.Namespace,
155+
scenario.URL,
156+
scenario.Ready,
157+
opts..., // apply any options (e.g., WithSpecModelName)
158+
)
159+
133160
objects = append(objects, obj)
134161
}
135162

0 commit comments

Comments
 (0)