jrmccluskey commented on code in PR #36623:
URL: https://github.com/apache/beam/pull/36623#discussion_r2470662909


##########
sdks/java/ml/remoteinference/src/main/java/org/apache/beam/sdk/ml/remoteinference/openai/OpenAiModelHandler.java:
##########
@@ -0,0 +1,44 @@
+package org.apache.beam.sdk.ml.remoteinference.openai;
+
+import com.openai.client.OpenAIClient;
+import com.openai.client.okhttp.OpenAIOkHttpClient;
+import com.openai.models.responses.ResponseCreateParams;
+import org.apache.beam.sdk.ml.remoteinference.base.BaseModelHandler;
+
+import java.util.stream.Collectors;
+
+public class OpenAiModelHandler

Review Comment:
   Stylize this as `OpenAIModelHandler` (this goes for all of the other classes 
as well)



##########
sdks/java/ml/remoteinference/src/main/java/org/apache/beam/sdk/ml/remoteinference/RemoteInference.java:
##########
@@ -0,0 +1,91 @@
+package org.apache.beam.sdk.ml.remoteinference;
+
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+import org.apache.beam.sdk.ml.remoteinference.base.BaseInput;
+import org.apache.beam.sdk.ml.remoteinference.base.BaseModelHandler;
+import org.apache.beam.sdk.ml.remoteinference.base.BaseModelParameters;
+import org.apache.beam.sdk.ml.remoteinference.base.BaseResponse;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.PTransform;
+import org.apache.beam.sdk.transforms.ParDo;
+import org.apache.beam.sdk.values.PCollection;
+
+
+import com.google.auto.value.AutoValue;
+
+@SuppressWarnings({ "rawtypes", "unchecked" })
+public class RemoteInference {
+
+  public static <InputT extends BaseInput, OutputT extends BaseResponse> 
Invoke<InputT, OutputT> invoke() {
+    return new AutoValue_RemoteInference_Invoke.Builder<InputT, 
OutputT>().setParameters(null)
+      .build();
+  }
+
+  private RemoteInference() {
+  }
+
+  @AutoValue
+  public abstract static class Invoke<InputT extends BaseInput, OutputT 
extends BaseResponse>
+    extends PTransform<PCollection<InputT>, PCollection<OutputT>> {
+
+    abstract @Nullable Class<? extends BaseModelHandler> handler();
+
+    abstract @Nullable BaseModelParameters parameters();
+
+    abstract Builder<InputT, OutputT> builder();
+
+    @AutoValue.Builder
+    abstract static class Builder<InputT extends BaseInput, OutputT extends 
BaseResponse> {
+
+      abstract Builder<InputT, OutputT> setHandler(Class<? extends 
BaseModelHandler> modelHandler);
+
+      abstract Builder<InputT, OutputT> setParameters(BaseModelParameters 
modelParameters);
+
+      abstract Invoke<InputT, OutputT> build();
+    }
+
+    public Invoke<InputT, OutputT> handler(Class<? extends BaseModelHandler> 
modelHandler) {
+      return builder().setHandler(modelHandler).build();
+    }
+
+    public Invoke<InputT, OutputT> withParameters(BaseModelParameters 
modelParameters) {
+      return builder().setParameters(modelParameters).build();
+    }
+
+    @Override

Review Comment:
   From the Python implementation (as well as the cross-language implementation 
in Java) we're generally trying to return input-output pairs to make it easier 
to process the results downstream.



##########
sdks/java/ml/build.gradle:
##########
@@ -0,0 +1,32 @@
+/*
+ * 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.
+ */

Review Comment:
   The Apache license header needs to be at the top of every new file (this is 
what the RAT pre-commit check is)



##########
sdks/java/ml/remoteinference/src/test/java/Example.java:
##########
@@ -0,0 +1,43 @@
+import org.apache.beam.runners.direct.DirectRunner;
+import org.apache.beam.sdk.Pipeline;
+import org.apache.beam.sdk.ml.remoteinference.RemoteInference;
+import org.apache.beam.sdk.ml.remoteinference.openai.OpenAiModelHandler;
+import org.apache.beam.sdk.ml.remoteinference.openai.OpenAiModelInput;
+import org.apache.beam.sdk.ml.remoteinference.openai.OpenAiModelParameters;
+import org.apache.beam.sdk.ml.remoteinference.openai.OpenAiModelResponse;
+import org.apache.beam.sdk.options.PipelineOptions;
+import org.apache.beam.sdk.options.PipelineOptionsFactory;
+import org.apache.beam.sdk.transforms.Create;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.MapElements;
+import org.apache.beam.sdk.transforms.ParDo;
+import org.apache.beam.sdk.values.TypeDescriptor;
+
+public class Example {

Review Comment:
   I'd like to see this written as an integration test rather than just an 
example



-- 
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