Skip to content

Commit

Permalink
Ability to customize model name in response metadata (#14)
Browse files Browse the repository at this point in the history
Add `--model-name` flag in example server to allow customizing response
metadata.
  • Loading branch information
aria authored Oct 12, 2022
1 parent 8882f9b commit 1faf05e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 6 additions & 2 deletions example/go/simple/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ import (
)

var (
port = flag.Int("port", 50051, "The server port")
port = flag.Int("port", 50051, "The server port")
modelName = flag.String("model-name", "model-a", "Model name to be returned in response metadata")
)

func main() {
flag.Parse()
upiServer := UpiServer{}
upiServer := UpiServer{
modelName: *modelName,
}

upiServer.Run(fmt.Sprintf(":%d", *port))
}
7 changes: 4 additions & 3 deletions example/go/simple/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ import (

type UpiServer struct {
upiv1.UnimplementedUniversalPredictionServiceServer
modelName string
}

func (_ *UpiServer) PredictValues(
func (s *UpiServer) PredictValues(
_ context.Context,
req *upiv1.PredictValuesRequest,
) (*upiv1.PredictValuesResponse, error) {
return &upiv1.PredictValuesResponse{
Metadata: &upiv1.ResponseMetadata{
Models: []*upiv1.ModelMetadata{
{
Name: "Echo Request Table",
Name: s.modelName,
Version: "1",
},
},
Expand All @@ -39,7 +40,7 @@ func (us *UpiServer) Run(address string) {
s := grpc.NewServer()
upiv1.RegisterUniversalPredictionServiceServer(s, us)
reflection.Register(s)
log.Printf("listening on port %s", address)
log.Printf("running model %s on port %s", us.modelName, address)
if err := s.Serve(lis); err != nil {
log.Fatalf("failed to serve: %v", err)
}
Expand Down

0 comments on commit 1faf05e

Please sign in to comment.