riteshghorse commented on code in PR #24497:
URL: https://github.com/apache/beam/pull/24497#discussion_r1046046494


##########
sdks/go/pkg/beam/transforms/xlang/inference/inference.go:
##########
@@ -0,0 +1,115 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// Package inference has the cross language implementation of RunInference API 
implemented in Python SDK.
+// An exapnsion service for python external transforms can be started by 
running
+//
+//     $ python -m apache_beam.runners.portability.expansion_service_main -p 
$PORT_FOR_EXPANSION_SERVICE
+package inference
+
+import (
+       "reflect"
+
+       "github.com/apache/beam/sdks/v2/go/pkg/beam"
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/core/runtime/xlangx"
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/core/typex"
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/transforms/xlang"
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/transforms/xlang/python"
+)
+
+func init() {
+       beam.RegisterType(reflect.TypeOf((*sklearnConfig)(nil)).Elem())
+       beam.RegisterType(reflect.TypeOf((*argsStruct)(nil)).Elem())
+       beam.RegisterType(reflect.TypeOf((*sklearnKwargs)(nil)).Elem())
+       beam.RegisterType(reflect.TypeOf((*PredictionResult)(nil)).Elem())
+}
+
+var outputT = reflect.TypeOf((*PredictionResult)(nil)).Elem()
+
+// PredictionResult represents the result of a prediction obtained from 
Python's RunInference API.
+type PredictionResult struct {
+       Example   []int64 `beam:"example"`
+       Inference int32   `beam:"inference"`
+}
+
+type sklearnConfig struct {
+       kwargs        sklearnKwargs
+       args          argsStruct
+       expansionAddr string
+}
+
+type sklearnConfigOption func(*sklearnConfig)
+
+// WithArgs set arguments for the sklearn inference transform parameters
+func WithArgs(args []string) sklearnConfigOption {

Review Comment:
   Made it generic



##########
sdks/go/pkg/beam/transforms/xlang/inference/inference.go:
##########
@@ -0,0 +1,115 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// Package inference has the cross language implementation of RunInference API 
implemented in Python SDK.
+// An exapnsion service for python external transforms can be started by 
running
+//
+//     $ python -m apache_beam.runners.portability.expansion_service_main -p 
$PORT_FOR_EXPANSION_SERVICE
+package inference
+
+import (
+       "reflect"
+
+       "github.com/apache/beam/sdks/v2/go/pkg/beam"
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/core/runtime/xlangx"
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/core/typex"
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/transforms/xlang"
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/transforms/xlang/python"
+)
+
+func init() {
+       beam.RegisterType(reflect.TypeOf((*sklearnConfig)(nil)).Elem())
+       beam.RegisterType(reflect.TypeOf((*argsStruct)(nil)).Elem())
+       beam.RegisterType(reflect.TypeOf((*sklearnKwargs)(nil)).Elem())
+       beam.RegisterType(reflect.TypeOf((*PredictionResult)(nil)).Elem())
+}
+
+var outputT = reflect.TypeOf((*PredictionResult)(nil)).Elem()
+
+// PredictionResult represents the result of a prediction obtained from 
Python's RunInference API.
+type PredictionResult struct {
+       Example   []int64 `beam:"example"`
+       Inference int32   `beam:"inference"`
+}
+
+type sklearnConfig struct {
+       kwargs        sklearnKwargs
+       args          argsStruct
+       expansionAddr string
+}
+
+type sklearnConfigOption func(*sklearnConfig)
+
+// WithArgs set arguments for the sklearn inference transform parameters
+func WithArgs(args []string) sklearnConfigOption {
+       return func(c *sklearnConfig) {
+               c.args.args = append(c.args.args, args...)
+       }
+}
+
+// WithExpansionAddr provides URL for Python expansion service.
+func WithExpansionAddr(expansionAddr string) sklearnConfigOption {

Review Comment:
   Done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to