joeyutong commented on code in PR #1382:
URL: https://github.com/apache/flink-agents/pull/1382#discussion_r4695364422
##########
plan/src/main/java/org/apache/flink/agents/plan/resourceprovider/PythonResourceProvider.java:
##########
@@ -96,6 +108,10 @@ public Resource provide(ResourceContext resourceContext)
throws Exception {
PyObject pyResource =
pythonResourceAdapter.initPythonResource(pyModule, pyClazz, kwargs);
try {
+ if (getType() == ResourceType.MEDIA_MODEL) {
Review Comment:
Done. Replaced `RESOURCE_TYPE_TO_CLASS` and constructor reflection with a
`WrapperFactory` registry (`RESOURCE_FACTORIES`) using constructor references
and `PythonMediaModelSetup::create`, removing the `MEDIA_MODEL`-specific branch
in `provide()`.
##########
plan/src/main/java/org/apache/flink/agents/plan/resource/python/PythonMediaModelSetup.java:
##########
@@ -0,0 +1,548 @@
+/*
+ * 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 org.apache.flink.agents.plan.resource.python;
+
+import org.apache.flink.agents.api.chat.messages.AudioBlock;
+import org.apache.flink.agents.api.chat.messages.DataContentBlock;
+import org.apache.flink.agents.api.chat.messages.ImageBlock;
+import org.apache.flink.agents.api.chat.messages.TextBlock;
+import org.apache.flink.agents.api.chat.messages.VideoBlock;
+import org.apache.flink.agents.api.media.AsyncJobModel;
+import org.apache.flink.agents.api.media.AsyncJobPolling;
+import org.apache.flink.agents.api.media.BaseImageGenerationModelSetup;
+import org.apache.flink.agents.api.media.BaseMediaModelSetup;
+import org.apache.flink.agents.api.media.BaseSpeechSynthesisModelSetup;
+import org.apache.flink.agents.api.media.BaseTranscriptionModelSetup;
+import org.apache.flink.agents.api.media.BaseVideoGenerationModelSetup;
+import org.apache.flink.agents.api.media.ImageGenerationRequest;
+import org.apache.flink.agents.api.media.MediaJob;
+import org.apache.flink.agents.api.media.MediaJobState;
+import org.apache.flink.agents.api.media.MediaResult;
+import org.apache.flink.agents.api.media.SpeechSynthesisRequest;
+import org.apache.flink.agents.api.media.TranscriptionRequest;
+import org.apache.flink.agents.api.media.VideoGenerationRequest;
+import org.apache.flink.agents.api.metrics.FlinkAgentsMetricGroup;
+import org.apache.flink.agents.api.resource.PythonResourceDescriptor;
+import org.apache.flink.agents.api.resource.ResourceContext;
+import org.apache.flink.agents.api.resource.ResourceDescriptor;
+import org.apache.flink.agents.api.resource.ResourceType;
+import org.apache.flink.agents.api.utils.StringValidationUtils;
+import org.apache.flink.agents.plan.exceptions.UncapturableException;
+import pemja.core.object.PyObject;
+
+import javax.annotation.Nullable;
+
+import java.time.Duration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.Function;
+
+/**
+ * Factory creating Java {@link BaseMediaModelSetup} bridges around Python
{@link
+ * ResourceType#MEDIA_MODEL} setup instances.
+ *
+ * <p>Each created resource extends the task-specific {@code Base*ModelSetup}
class and implements
+ * {@link AsyncJobModel} if and only if the underlying Python resource
supports async jobs.
+ */
+public final class PythonMediaModelSetup {
+ private PythonMediaModelSetup() {}
+
+ /** Inspect the Python media model setup and return a matching typed Java
wrapper. */
+ public static BaseMediaModelSetup create(
+ PythonResourceAdapter adapter,
+ PyObject resource,
+ ResourceDescriptor descriptor,
+ @Nullable ResourceContext resourceContext) {
+ Objects.requireNonNull(descriptor, "descriptor");
+ Object inspection =
adapter.invoke("python_java_utils.inspect_media_model", resource);
+ if (!(inspection instanceof Map)) {
Review Comment:
Done. Cast the `inspect_media_model` result directly to `Map<?, ?>` without
the intermediate `Object` variable and `instanceof Map` check.
--
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]