-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create mlmodel_service in testutils/inject (#2205)
- Loading branch information
1 parent
f9ba224
commit de0b51c
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package inject | ||
|
||
import ( | ||
"context" | ||
|
||
"go.viam.com/rdk/services/mlmodel" | ||
) | ||
|
||
// MLModelService represents a fake instance of a mlmodel service. | ||
type MLModelService struct { | ||
mlmodel.Service | ||
InferFunc func(ctx context.Context, input map[string]interface{}) (map[string]interface{}, error) | ||
MetadataFunc func(ctx context.Context) (mlmodel.MLMetadata, error) | ||
} | ||
|
||
// Infer calls the injected InferFunc or the real version. | ||
func (mlmodelSvc *MLModelService) Infer(ctx context.Context, input map[string]interface{}) (map[string]interface{}, error) { | ||
if mlmodelSvc.InferFunc == nil { | ||
return mlmodelSvc.Service.Infer(ctx, input) | ||
} | ||
return mlmodelSvc.InferFunc(ctx, input) | ||
} | ||
|
||
// Metadata calls the injected MetadataFunc or the real version. | ||
func (mlmodelSvc *MLModelService) Metadata(ctx context.Context) (mlmodel.MLMetadata, error) { | ||
if mlmodelSvc.MetadataFunc == nil { | ||
return mlmodelSvc.Service.Metadata(ctx) | ||
} | ||
return mlmodelSvc.MetadataFunc(ctx) | ||
} |