Skip to content

Commit b6138d2

Browse files
committed
add compatible models in brickinstance details
1 parent 8d4eb51 commit b6138d2

File tree

5 files changed

+59
-16
lines changed

5 files changed

+59
-16
lines changed

internal/api/docs/openapi.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,10 @@ components:
13501350
type: string
13511351
category:
13521352
type: string
1353+
compatible_models:
1354+
items:
1355+
$ref: '#/components/schemas/AIModel'
1356+
type: array
13531357
config_variables:
13541358
items:
13551359
$ref: '#/components/schemas/BrickConfigVariable'

internal/e2e/client/client.gen.go

Lines changed: 8 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/e2e/daemon/instance_bricks_test.go renamed to internal/e2e/daemon/bricks_instance_test.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ var (
5151
Value: f.Ptr("/models/ootb/ei/mobilenet-v2-224px.eim"),
5252
},
5353
}
54+
55+
expectedModelInfo = []client.AIModel{
56+
{
57+
Id: f.Ptr("mobilenet-image-classification"),
58+
Name: f.Ptr("General purpose image classification"),
59+
Description: f.Ptr("General purpose image classification model based on MobileNetV2. This model is trained on the ImageNet dataset and can classify images into 1000 categories."),
60+
},
61+
{
62+
Id: f.Ptr("person-classification"),
63+
Name: f.Ptr("Person classification"),
64+
Description: f.Ptr("Person classification model based on WakeVision dataset. This model is trained to classify images into two categories: person and not-person."),
65+
}}
5466
)
5567

5668
func setupTestApp(t *testing.T) (*client.CreateAppResp, *client.ClientWithResponses) {
@@ -78,7 +90,6 @@ func setupTestApp(t *testing.T) (*client.CreateAppResp, *client.ClientWithRespon
7890
)
7991
require.NoError(t, err)
8092
require.Equal(t, http.StatusOK, resp.StatusCode())
81-
8293
return createResp, httpClient
8394
}
8495

@@ -135,6 +146,20 @@ func TestGetAppBrickInstanceById(t *testing.T) {
135146
require.NotEmpty(t, brickInstance.JSON200)
136147
require.Equal(t, ImageClassifactionBrickID, *brickInstance.JSON200.Id)
137148
require.Equal(t, expectedConfigVariables, (*brickInstance.JSON200.ConfigVariables))
149+
require.Nil(t, brickInstance.JSON200.CompatibleModels)
150+
})
151+
152+
t.Run("GetAppBrickInstanceByBrickIDWithCompatibleModels_Success", func(t *testing.T) {
153+
brickInstance, err := httpClient.GetAppBrickInstanceByBrickIDWithResponse(
154+
t.Context(),
155+
*createResp.JSON201.Id,
156+
ImageClassifactionBrickID,
157+
func(ctx context.Context, req *http.Request) error { return nil })
158+
require.NoError(t, err)
159+
require.NotEmpty(t, brickInstance.JSON200)
160+
require.Equal(t, ImageClassifactionBrickID, *brickInstance.JSON200.Id)
161+
require.NotNil(t, brickInstance.JSON200.CompatibleModels)
162+
require.Equal(t, expectedModelInfo, *(brickInstance.JSON200.CompatibleModels))
138163
})
139164

140165
t.Run("GetAppBrickInstanceByBrickID_InvalidAppID_Fails", func(t *testing.T) {

internal/orchestrator/bricks/bricks.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ func (s *Service) AppBrickInstanceDetails(a *app.ArduinoApp, brickID string) (Br
121121
Variables: variables,
122122
ConfigVariables: configVariables,
123123
ModelID: modelID,
124+
CompatibleModels: f.Map(s.modelsIndex.GetModelsByBrick(brick.ID), func(m modelsindex.AIModel) AIModel {
125+
return AIModel{
126+
ID: m.ID,
127+
Name: m.Name,
128+
Description: m.ModuleDescription,
129+
}
130+
}),
124131
}, nil
125132
}
126133

internal/orchestrator/bricks/types.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,22 @@ type AppBrickInstancesResult struct {
3333
}
3434

3535
type BrickInstance struct {
36-
ID string `json:"id"`
37-
Name string `json:"name"`
38-
Author string `json:"author"`
39-
Category string `json:"category"`
40-
Status string `json:"status"`
41-
Variables map[string]string `json:"variables,omitempty" description:"Deprecated: use config_variables instead. This field is kept for backward compatibility."`
42-
ConfigVariables []BrickConfigVariable `json:"config_variables,omitempty"`
43-
ModelID string `json:"model,omitempty"`
36+
ID string `json:"id"`
37+
Name string `json:"name"`
38+
Author string `json:"author"`
39+
Category string `json:"category"`
40+
Status string `json:"status"`
41+
Variables map[string]string `json:"variables,omitempty" description:"Deprecated: use config_variables instead. This field is kept for backward compatibility."`
42+
ConfigVariables []BrickConfigVariable `json:"config_variables,omitempty"`
43+
ModelID string `json:"model,omitempty"`
44+
CompatibleModels []AIModel `json:"compatible_models,omitempty"`
4445
}
4546

47+
type AIModel struct {
48+
ID string `json:"id"`
49+
Name string `json:"name"`
50+
Description string `json:"description"`
51+
}
4652
type BrickConfigVariable struct {
4753
Name string `json:"name"`
4854
Value string `json:"value"`

0 commit comments

Comments
 (0)