Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions internal/api/docs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,15 @@ components:
runner:
type: string
type: object
AIModelLite:
properties:
description:
type: string
id:
type: string
name:
type: string
type: object
AIModelsListResult:
properties:
models:
Expand Down Expand Up @@ -1314,6 +1323,11 @@ components:
type: string
id:
type: string
models:
items:
$ref: '#/components/schemas/AIModelLite'
nullable: true
type: array
name:
type: string
readme:
Expand Down Expand Up @@ -1365,11 +1379,6 @@ components:
type: string
id:
type: string
models:
items:
type: string
nullable: true
type: array
name:
type: string
status:
Expand Down
23 changes: 15 additions & 8 deletions internal/e2e/client/client.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions internal/e2e/daemon/brick_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@ func TestBricksDetails(t *testing.T) {
},
}

expectedModelLiteInfo := []client.AIModelLite{
{
Id: f.Ptr("mobilenet-image-classification"),
Name: f.Ptr("General purpose image classification"),
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."),
},
{
Id: f.Ptr("person-classification"),
Name: f.Ptr("Person classification"),
Description: f.Ptr("Person classification model based on WakeVision dataset. This model is trained to classify images into two categories: person and not-person."),
}}
response, err := httpClient.GetBrickDetailsWithResponse(t.Context(), validBrickID, func(ctx context.Context, req *http.Request) error { return nil })
require.NoError(t, err)
require.Equal(t, http.StatusOK, response.StatusCode(), "status code should be 200 ok")
Expand All @@ -133,5 +144,7 @@ func TestBricksDetails(t *testing.T) {
require.NotEmpty(t, *response.JSON200.Readme)
require.NotNil(t, response.JSON200.UsedByApps, "UsedByApps should not be nil")
require.Equal(t, expectedUsedByApps, *(response.JSON200.UsedByApps))
require.NotNil(t, response.JSON200.Models, "Models should not be nil")
require.Equal(t, expectedModelLiteInfo, *(response.JSON200.Models))
})
}
5 changes: 1 addition & 4 deletions internal/orchestrator/bricks/bricks.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ func (s *Service) List() (BrickListResult, error) {
Description: brick.Description,
Category: brick.Category,
Status: "installed",
Models: f.Map(s.modelsIndex.GetModelsByBrick(brick.ID), func(m modelsindex.AIModel) string {
return m.ID
}),
}
}
return res, nil
Expand Down Expand Up @@ -193,7 +190,6 @@ func (s *Service) BricksDetails(id string, idProvider *app.IDProvider,
if err != nil {
return BrickDetailsResult{}, fmt.Errorf("unable to get used by apps: %w", err)
}

return BrickDetailsResult{
ID: id,
Name: brick.Name,
Expand All @@ -206,6 +202,7 @@ func (s *Service) BricksDetails(id string, idProvider *app.IDProvider,
ApiDocsPath: apiDocsPath,
CodeExamples: codeExamples,
UsedByApps: usedByApps,
Models: s.modelsIndex.GetModelsLiteInfoByBrick(brick.ID),
}, nil
}

Expand Down
38 changes: 20 additions & 18 deletions internal/orchestrator/bricks/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@

package bricks

import "github.com/arduino/arduino-app-cli/internal/orchestrator/modelsindex"

type BrickListResult struct {
Bricks []BrickListItem `json:"bricks"`
}

type BrickListItem struct {
ID string `json:"id"`
Name string `json:"name"`
Author string `json:"author"`
Description string `json:"description"`
Category string `json:"category"`
Status string `json:"status"`
Models []string `json:"models"`
ID string `json:"id"`
Name string `json:"name"`
Author string `json:"author"`
Description string `json:"description"`
Category string `json:"category"`
Status string `json:"status"`
}

type AppBrickInstancesResult struct {
Expand Down Expand Up @@ -67,15 +68,16 @@ type AppReference struct {
}

type BrickDetailsResult struct {
ID string `json:"id"`
Name string `json:"name"`
Author string `json:"author"`
Description string `json:"description"`
Category string `json:"category"`
Status string `json:"status"`
Variables map[string]BrickVariable `json:"variables,omitempty"`
Readme string `json:"readme"`
ApiDocsPath string `json:"api_docs_path"`
CodeExamples []CodeExample `json:"code_examples"`
UsedByApps []AppReference `json:"used_by_apps"`
ID string `json:"id"`
Name string `json:"name"`
Author string `json:"author"`
Description string `json:"description"`
Category string `json:"category"`
Status string `json:"status"`
Variables map[string]BrickVariable `json:"variables,omitempty"`
Readme string `json:"readme"`
ApiDocsPath string `json:"api_docs_path"`
CodeExamples []CodeExample `json:"code_examples"`
UsedByApps []AppReference `json:"used_by_apps"`
Models []modelsindex.AIModelLite `json:"models"`
}
25 changes: 25 additions & 0 deletions internal/orchestrator/modelsindex/models_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ type AIModel struct {
ModelConfiguration map[string]string `yaml:"model_configuration,omitempty"`
}

type AIModelLite struct {
ID string `json:"id"`
Name string `json:"name"`
ModuleDescription string `json:"description"`
}

type ModelsIndex struct {
models []AIModel
}
Expand Down Expand Up @@ -82,6 +88,25 @@ func (m *ModelsIndex) GetModelsByBrick(brick string) []AIModel {
return matches
}

func (m *ModelsIndex) GetModelsLiteInfoByBrick(brick string) []AIModelLite {
var matches []AIModelLite
for i := range m.models {
if len(m.models[i].Bricks) > 0 && slices.Contains(m.models[i].Bricks, brick) {
matches = append(matches,
AIModelLite{
ID: m.models[i].ID,
Name: m.models[i].Name,
ModuleDescription: m.models[i].ModuleDescription,
},
)
}
}
if len(matches) == 0 {
return []AIModelLite{}
}
return matches
}

func (m *ModelsIndex) GetModelsByBricks(bricks []string) []AIModel {
var matchingModels []AIModel
for _, model := range m.models {
Expand Down
11 changes: 11 additions & 0 deletions internal/orchestrator/modelsindex/modelsindex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,15 @@ func TestModelsIndex(t *testing.T) {
assert.Equal(t, "face-detection", models[0].ID)
assert.Equal(t, "yolox-object-detection", models[1].ID)
})

t.Run("it gets models lite by a brick", func(t *testing.T) {
model := modelsIndex.GetModelsLiteInfoByBrick("not-existing-brick")
assert.Empty(t, model)

model = modelsIndex.GetModelsLiteInfoByBrick("arduino:object_detection")
assert.Len(t, model, 1)
assert.Equal(t, "face-detection", model[0].ID)
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)
assert.Equal(t, "Lightweight-Face-Detection", model[0].Name)
})
}