forked from opendatahub-io/models-as-a-service
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathllm_models.go
More file actions
164 lines (140 loc) · 4.64 KB
/
llm_models.go
File metadata and controls
164 lines (140 loc) · 4.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package fixtures
import (
"time"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
)
type ModelURL interface {
AddTo(obj *unstructured.Unstructured)
String() string
}
var _ ModelURL = PublicURL("")
type PublicURL string
func (p PublicURL) String() string {
return string(p)
}
func (p PublicURL) AddTo(obj *unstructured.Unstructured) {
_ = unstructured.SetNestedField(obj.Object, p.String(), "status", "url")
AddressEntry(p.String()).AddTo(obj)
}
var _ ModelURL = AddressEntry("")
type AddressEntry string
func (i AddressEntry) String() string {
return string(i)
}
func (i AddressEntry) AddTo(obj *unstructured.Unstructured) {
_ = unstructured.SetNestedSlice(obj.Object, []any{
map[string]any{
"url": i.String(),
},
}, "status", "addresses")
}
type LLMInferenceServiceOption func(*unstructured.Unstructured)
// WithSpecModelName sets .spec.model.name (can be an empty string "" to test fallback logic).
func WithSpecModelName(name string) LLMInferenceServiceOption {
return func(obj *unstructured.Unstructured) {
_ = unstructured.SetNestedField(obj.Object, name, "spec", "model", "name")
}
}
// CreateLLMInferenceService creates a test LLMInferenceService unstructured object
func CreateLLMInferenceService(name, namespace string, url ModelURL, ready bool, opts ...LLMInferenceServiceOption) *unstructured.Unstructured {
obj := &unstructured.Unstructured{}
obj.Object = map[string]any{}
obj.SetAPIVersion("serving.kserve.io/v1alpha1")
obj.SetKind("LLMInferenceService")
obj.SetName(name)
obj.SetNamespace(namespace)
obj.SetCreationTimestamp(metav1.NewTime(time.Now().Add(-time.Hour)))
obj.SetGeneration(1)
_ = unstructured.SetNestedField(obj.Object, "1", "status", "observedGeneration")
url.AddTo(obj)
// Set conditions based on ready state - using actual LLMInferenceService condition types
var conditions []any
if ready {
conditions = append(conditions, map[string]any{
"type": "HTTPRoutesReady",
"status": "True",
"lastTransitionTime": "2025-09-18T10:57:50Z",
"severity": "Info",
})
conditions = append(conditions, map[string]any{
"type": "InferencePoolReady",
"status": "True",
"lastTransitionTime": "2025-09-18T10:57:50Z",
"severity": "Info",
})
conditions = append(conditions, map[string]any{
"type": "MainWorkloadReady",
"status": "True",
"lastTransitionTime": "2025-09-18T11:04:20Z",
"severity": "Info",
})
conditions = append(conditions, map[string]any{
"type": "PresetsCombined",
"status": "True",
"lastTransitionTime": "2025-09-18T10:57:50Z",
})
conditions = append(conditions, map[string]any{
"type": "Ready",
"status": "True",
"lastTransitionTime": "2025-09-18T11:04:20Z",
})
conditions = append(conditions, map[string]any{
"type": "RouterReady",
"status": "True",
"lastTransitionTime": "2025-09-18T10:57:50Z",
})
conditions = append(conditions, map[string]any{
"type": "WorkloadsReady",
"status": "True",
"lastTransitionTime": "2025-09-18T11:04:20Z",
})
} else {
conditions = append(conditions, map[string]any{
"type": "Ready",
"status": "False",
"lastTransitionTime": "2025-09-18T11:04:20Z",
"reason": "ServiceNotReady",
})
conditions = append(conditions, map[string]any{
"type": "WorkloadsReady",
"status": "False",
"lastTransitionTime": "2025-09-18T11:04:20Z",
"reason": "NotReady",
})
}
_ = unstructured.SetNestedSlice(obj.Object, conditions, "status", "conditions")
// Apply options (e.g., WithSpecModelName)
for _, opt := range opts {
opt(obj)
}
return obj
}
// LLMTestScenario defines a test scenario for LLM models
type LLMTestScenario struct {
Name string
Namespace string
URL ModelURL
Ready bool
SpecModelName *string
}
// CreateLLMInferenceServices creates a set of test LLM objects for testing
func CreateLLMInferenceServices(scenarios ...LLMTestScenario) []runtime.Object {
var objects []runtime.Object
for _, scenario := range scenarios {
var opts []LLMInferenceServiceOption
if scenario.SpecModelName != nil {
opts = append(opts, WithSpecModelName(*scenario.SpecModelName))
}
obj := CreateLLMInferenceService(
scenario.Name,
scenario.Namespace,
scenario.URL,
scenario.Ready,
opts..., // apply any options (e.g., WithSpecModelName)
)
objects = append(objects, obj)
}
return objects
}