Skip to content

Commit 2b7e966

Browse files
committed
refactoring
1 parent c701841 commit 2b7e966

File tree

4 files changed

+25
-51
lines changed

4 files changed

+25
-51
lines changed

internal/orchestrator/bricks/bricks.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,13 @@ func (s *Service) BricksDetails(id string, idProvider *app.IDProvider,
202202
ApiDocsPath: apiDocsPath,
203203
CodeExamples: codeExamples,
204204
UsedByApps: usedByApps,
205-
Models: s.modelsIndex.GetModelsLiteInfoByBrick(brick.ID),
205+
Models: f.Map(s.modelsIndex.GetModelsByBrick(brick.ID), func(m modelsindex.AIModel) AIModelLite {
206+
return AIModelLite{
207+
ID: m.ID,
208+
Name: m.Name,
209+
Description: m.ModuleDescription,
210+
}
211+
}),
206212
}, nil
207213
}
208214

internal/orchestrator/bricks/types.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
package bricks
1717

18-
import "github.com/arduino/arduino-app-cli/internal/orchestrator/modelsindex"
19-
2018
type BrickListResult struct {
2119
Bricks []BrickListItem `json:"bricks"`
2220
}
@@ -68,16 +66,22 @@ type AppReference struct {
6866
}
6967

7068
type BrickDetailsResult struct {
71-
ID string `json:"id"`
72-
Name string `json:"name"`
73-
Author string `json:"author"`
74-
Description string `json:"description"`
75-
Category string `json:"category"`
76-
Status string `json:"status"`
77-
Variables map[string]BrickVariable `json:"variables,omitempty"`
78-
Readme string `json:"readme"`
79-
ApiDocsPath string `json:"api_docs_path"`
80-
CodeExamples []CodeExample `json:"code_examples"`
81-
UsedByApps []AppReference `json:"used_by_apps"`
82-
Models []modelsindex.AIModelLite `json:"models"`
69+
ID string `json:"id"`
70+
Name string `json:"name"`
71+
Author string `json:"author"`
72+
Description string `json:"description"`
73+
Category string `json:"category"`
74+
Status string `json:"status"`
75+
Variables map[string]BrickVariable `json:"variables,omitempty"`
76+
Readme string `json:"readme"`
77+
ApiDocsPath string `json:"api_docs_path"`
78+
CodeExamples []CodeExample `json:"code_examples"`
79+
UsedByApps []AppReference `json:"used_by_apps"`
80+
Models []AIModelLite `json:"models"`
81+
}
82+
83+
type AIModelLite struct {
84+
ID string `json:"id"`
85+
Name string `json:"name"`
86+
Description string `json:"description"`
8387
}

internal/orchestrator/modelsindex/models_index.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,6 @@ type AIModel struct {
5353
ModelConfiguration map[string]string `yaml:"model_configuration,omitempty"`
5454
}
5555

56-
type AIModelLite struct {
57-
ID string `json:"id"`
58-
Name string `json:"name"`
59-
ModuleDescription string `json:"description"`
60-
}
61-
6256
type ModelsIndex struct {
6357
models []AIModel
6458
}
@@ -88,25 +82,6 @@ func (m *ModelsIndex) GetModelsByBrick(brick string) []AIModel {
8882
return matches
8983
}
9084

91-
func (m *ModelsIndex) GetModelsLiteInfoByBrick(brick string) []AIModelLite {
92-
var matches []AIModelLite
93-
for i := range m.models {
94-
if len(m.models[i].Bricks) > 0 && slices.Contains(m.models[i].Bricks, brick) {
95-
matches = append(matches,
96-
AIModelLite{
97-
ID: m.models[i].ID,
98-
Name: m.models[i].Name,
99-
ModuleDescription: m.models[i].ModuleDescription,
100-
},
101-
)
102-
}
103-
}
104-
if len(matches) == 0 {
105-
return []AIModelLite{}
106-
}
107-
return matches
108-
}
109-
11085
func (m *ModelsIndex) GetModelsByBricks(bricks []string) []AIModel {
11186
var matchingModels []AIModel
11287
for _, model := range m.models {

internal/orchestrator/modelsindex/modelsindex_test.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,4 @@ func TestModelsIndex(t *testing.T) {
6969
assert.Equal(t, "face-detection", models[0].ID)
7070
assert.Equal(t, "yolox-object-detection", models[1].ID)
7171
})
72-
73-
t.Run("it gets models lite by a brick", func(t *testing.T) {
74-
model := modelsIndex.GetModelsLiteInfoByBrick("not-existing-brick")
75-
assert.Empty(t, model)
76-
77-
model = modelsIndex.GetModelsLiteInfoByBrick("arduino:object_detection")
78-
assert.Len(t, model, 1)
79-
assert.Equal(t, "face-detection", model[0].ID)
80-
assert.Equal(t, "Face bounding box detection. This model is trained on the WIDER FACE dataset and can detect faces in images.", model[0].ModuleDescription)
81-
assert.Equal(t, "Lightweight-Face-Detection", model[0].Name)
82-
})
8372
}

0 commit comments

Comments
 (0)