Skip to content

Commit a91b45c

Browse files
ndeloofglours
authored andcommitted
Fix models support with compose include
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 2f5f8d9 commit a91b45c

File tree

2 files changed

+306
-0
lines changed

2 files changed

+306
-0
lines changed

loader/include.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ func importResources(source map[string]any, target map[string]any) error {
177177
if err := importResource(source, target, "configs"); err != nil {
178178
return err
179179
}
180+
if err := importResource(source, target, "models"); err != nil {
181+
return err
182+
}
180183
return nil
181184
}
182185

override/merge_models_test.go

Lines changed: 303 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,303 @@
1+
/*
2+
Copyright 2020 The Compose Specification Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package override
18+
19+
import (
20+
"testing"
21+
)
22+
23+
func Test_mergeYamlServiceModelsShortSyntax(t *testing.T) {
24+
assertMergeYaml(t, `
25+
services:
26+
test:
27+
image: foo
28+
models:
29+
- llm
30+
- embedding-model
31+
`, `
32+
services:
33+
test:
34+
models:
35+
- vision-model
36+
`, `
37+
services:
38+
test:
39+
image: foo
40+
models:
41+
llm:
42+
embedding-model:
43+
vision-model:
44+
`)
45+
}
46+
47+
func Test_mergeYamlServiceModelsLongSyntax(t *testing.T) {
48+
assertMergeYaml(t, `
49+
services:
50+
test:
51+
image: foo
52+
models:
53+
llm:
54+
endpoint_var: AI_MODEL_URL
55+
model_var: AI_MODEL_NAME
56+
`, `
57+
services:
58+
test:
59+
models:
60+
embedding-model:
61+
endpoint_var: EMBEDDING_URL
62+
model_var: EMBEDDING_MODEL
63+
`, `
64+
services:
65+
test:
66+
image: foo
67+
models:
68+
llm:
69+
endpoint_var: AI_MODEL_URL
70+
model_var: AI_MODEL_NAME
71+
embedding-model:
72+
endpoint_var: EMBEDDING_URL
73+
model_var: EMBEDDING_MODEL
74+
`)
75+
}
76+
77+
func Test_mergeYamlServiceModelsMixed(t *testing.T) {
78+
assertMergeYaml(t, `
79+
services:
80+
test:
81+
image: foo
82+
models:
83+
- llm
84+
- embedding-model
85+
`, `
86+
services:
87+
test:
88+
models:
89+
vision-model:
90+
endpoint_var: VISION_URL
91+
model_var: VISION_MODEL
92+
`, `
93+
services:
94+
test:
95+
image: foo
96+
models:
97+
llm:
98+
embedding-model:
99+
vision-model:
100+
endpoint_var: VISION_URL
101+
model_var: VISION_MODEL
102+
`)
103+
}
104+
105+
func Test_mergeYamlServiceModelsOverride(t *testing.T) {
106+
assertMergeYaml(t, `
107+
services:
108+
test:
109+
image: foo
110+
models:
111+
llm:
112+
endpoint_var: OLD_MODEL_URL
113+
model_var: OLD_MODEL_NAME
114+
`, `
115+
services:
116+
test:
117+
models:
118+
llm:
119+
endpoint_var: NEW_MODEL_URL
120+
model_var: NEW_MODEL_NAME
121+
`, `
122+
services:
123+
test:
124+
image: foo
125+
models:
126+
llm:
127+
endpoint_var: NEW_MODEL_URL
128+
model_var: NEW_MODEL_NAME
129+
`)
130+
}
131+
132+
func Test_mergeYamlTopLevelModels(t *testing.T) {
133+
assertMergeYaml(t, `
134+
services:
135+
test:
136+
image: foo
137+
models:
138+
llm:
139+
model: ai/smollm2
140+
context_size: 2048
141+
runtime_flags:
142+
- "--gpu"
143+
`, `
144+
services:
145+
test:
146+
image: foo
147+
models:
148+
embedding-model:
149+
model: ai/all-minilm
150+
context_size: 512
151+
runtime_flags:
152+
- "--cpu"
153+
`, `
154+
services:
155+
test:
156+
image: foo
157+
models:
158+
llm:
159+
model: ai/smollm2
160+
context_size: 2048
161+
runtime_flags:
162+
- "--gpu"
163+
embedding-model:
164+
model: ai/all-minilm
165+
context_size: 512
166+
runtime_flags:
167+
- "--cpu"
168+
`)
169+
}
170+
171+
func Test_mergeYamlModelsCompleteScenario(t *testing.T) {
172+
assertMergeYaml(t, `
173+
services:
174+
app:
175+
image: myapp
176+
models:
177+
- llm
178+
worker:
179+
image: worker
180+
models:
181+
embedding-model:
182+
endpoint_var: EMBEDDING_URL
183+
models:
184+
llm:
185+
model: ai/smollm2
186+
context_size: 2048
187+
embedding-model:
188+
model: ai/all-minilm
189+
context_size: 512
190+
`, `
191+
services:
192+
app:
193+
models:
194+
- vision-model
195+
worker:
196+
models:
197+
llm:
198+
endpoint_var: LLM_URL
199+
model_var: LLM_NAME
200+
models:
201+
vision-model:
202+
model: ai/clip
203+
context_size: 1024
204+
llm:
205+
model: ai/gpt-4
206+
context_size: 8192
207+
`, `
208+
services:
209+
app:
210+
image: myapp
211+
models:
212+
llm:
213+
vision-model:
214+
worker:
215+
image: worker
216+
models:
217+
embedding-model:
218+
endpoint_var: EMBEDDING_URL
219+
llm:
220+
endpoint_var: LLM_URL
221+
model_var: LLM_NAME
222+
models:
223+
llm:
224+
model: ai/gpt-4
225+
context_size: 8192
226+
embedding-model:
227+
model: ai/all-minilm
228+
context_size: 512
229+
vision-model:
230+
model: ai/clip
231+
context_size: 1024
232+
`)
233+
}
234+
235+
/*
236+
func Test_mergeYamlModelsRuntimeFlagsMerge(t *testing.T) {
237+
assertMergeYaml(t, `
238+
services:
239+
test:
240+
image: foo
241+
models:
242+
llm:
243+
model: ai/smollm2
244+
runtime_flags:
245+
- "--gpu"
246+
- "--batch-size=32"
247+
`, `
248+
services:
249+
test:
250+
image: foo
251+
models:
252+
llm:
253+
model: ai/smollm2
254+
runtime_flags:
255+
- "--fp16"
256+
- "--batch-size=64"
257+
`, `
258+
services:
259+
test:
260+
image: foo
261+
models:
262+
llm:
263+
model: ai/smollm2
264+
runtime_flags:
265+
- "--fp16"
266+
- "--batch-size=64"
267+
`)
268+
}
269+
*/
270+
271+
func Test_mergeYamlModelsMultipleServices(t *testing.T) {
272+
assertMergeYaml(t, `
273+
services:
274+
go-genai:
275+
models:
276+
- llm
277+
models:
278+
llm:
279+
model: ai/smollm2
280+
context_size: 2048
281+
`, `
282+
services:
283+
node-genai:
284+
models:
285+
- llm
286+
models:
287+
llm:
288+
model: ai/smollm2
289+
context_size: 2048
290+
`, `
291+
services:
292+
go-genai:
293+
models:
294+
- llm
295+
node-genai:
296+
models:
297+
- llm
298+
models:
299+
llm:
300+
model: ai/smollm2
301+
context_size: 2048
302+
`)
303+
}

0 commit comments

Comments
 (0)