Skip to content

Commit

Permalink
fix: fix input and output for instill format
Browse files Browse the repository at this point in the history
  • Loading branch information
chuang8511 committed Nov 1, 2024
1 parent 550e76f commit a6f43f4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 24 deletions.
24 changes: 0 additions & 24 deletions pkg/component/ai/instillmodel/v0/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,27 +224,3 @@ type triggerInfo struct {
modelID string
version string
}

func getTriggerInfo(input *structpb.Struct) (*triggerInfo, error) {
if input == nil {
return nil, fmt.Errorf("input is nil")
}
data, ok := input.Fields["data"]
if !ok {
return nil, fmt.Errorf("data field not found")
}
model, ok := data.GetStructValue().Fields["model"]

if !ok {
return nil, fmt.Errorf("model field not found")
}
modelNameSplits := strings.Split(model.GetStringValue(), "/")
if len(modelNameSplits) != 3 {
return nil, fmt.Errorf("model name should be in the format of <namespace>/<model>/<version>")
}
return &triggerInfo{
nsID: modelNameSplits[0],
modelID: modelNameSplits[1],
version: modelNameSplits[2],
}, nil
}
25 changes: 25 additions & 0 deletions pkg/component/ai/instillmodel/v0/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package instillmodel
import (
"context"
"fmt"
"strings"
"time"

"google.golang.org/grpc/metadata"
Expand Down Expand Up @@ -51,3 +52,27 @@ func (e *execution) trigger(ctx context.Context, job *base.Job) error {

return job.Output.WriteData(ctx, res.TaskOutputs[0])
}

func getTriggerInfo(input *structpb.Struct) (*triggerInfo, error) {
if input == nil {
return nil, fmt.Errorf("input is nil")
}
data, ok := input.Fields["data"]
if !ok {
return nil, fmt.Errorf("data field not found")
}
model, ok := data.GetStructValue().Fields["model"]

if !ok {
return nil, fmt.Errorf("model field not found")
}
modelNameSplits := strings.Split(model.GetStringValue(), "/")
if len(modelNameSplits) != 3 {
return nil, fmt.Errorf("model name should be in the format of <namespace>/<model>/<version>")
}
return &triggerInfo{
nsID: modelNameSplits[0],
modelID: modelNameSplits[1],
version: modelNameSplits[2],
}, nil
}

0 comments on commit a6f43f4

Please sign in to comment.