xintongsong commented on code in PR #314:
URL: https://github.com/apache/flink-agents/pull/314#discussion_r2609631343


##########
plan/src/main/java/org/apache/flink/agents/plan/resourceprovider/PythonResourceProvider.java:
##########
@@ -63,11 +90,21 @@ public Map<String, Object> getKwargs() {
     @Override
     public Resource provide(BiFunction<String, ResourceType, Resource> 
getResource)
             throws Exception {
-        // TODO: Implement Python resource creation logic
-        // This would typically involve calling into Python runtime to create 
the
-        // resource
-        throw new UnsupportedOperationException(
-                "Python resource creation not yet implemented in Java 
runtime");
+        if (pythonResourceAdapter != null) {
+            Class<?> clazz = Class.forName(descriptor.getClazz());
+            PyObject pyResource =
+                    pythonResourceAdapter.initPythonResource(this.module, 
this.clazz, kwargs);
+            Constructor<?> constructor =
+                    clazz.getConstructor(
+                            PythonResourceAdapter.class,
+                            PyObject.class,
+                            ResourceDescriptor.class,
+                            BiFunction.class);
+            return (Resource)
+                    constructor.newInstance(
+                            pythonResourceAdapter, pyResource, descriptor, 
getResource);
+        }
+        throw new UnsupportedOperationException("PythonResourceAdapter is not 
set.");

Review Comment:
   Use `checkState`



##########
api/src/main/java/org/apache/flink/agents/api/chat/model/python/PythonChatModelConnection.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.api.chat.model.python;
+
+import org.apache.flink.agents.api.chat.messages.ChatMessage;
+import org.apache.flink.agents.api.chat.model.BaseChatModelConnection;
+import org.apache.flink.agents.api.resource.Resource;
+import org.apache.flink.agents.api.resource.ResourceDescriptor;
+import org.apache.flink.agents.api.resource.ResourceType;
+import org.apache.flink.agents.api.resource.python.PythonResourceAdapter;
+import org.apache.flink.agents.api.resource.python.PythonResourceWrapper;
+import org.apache.flink.agents.api.tools.Tool;
+import pemja.core.object.PyObject;
+
+import java.util.List;
+import java.util.Map;
+import java.util.function.BiFunction;
+
+/**
+ * Python-based implementation of ChatModelConnection that wraps a Python chat 
model object. This
+ * class serves as a bridge between Java and Python chat model environments, 
but unlike {@link
+ * PythonChatModelSetup}, it does not provide direct chat functionality in 
Java.
+ */
+public class PythonChatModelConnection extends BaseChatModelConnection
+        implements PythonResourceWrapper {
+    private PyObject chatModel;
+
+    /**
+     * Creates a new PythonChatModelConnection.
+     *
+     * @param adapter The Python resource adapter (required by 
PythonResourceProvider's
+     *     reflection-based instantiation but not used directly in this 
implementation)
+     * @param chatModel The Python chat model object
+     * @param descriptor The resource descriptor
+     * @param getResource Function to retrieve resources by name and type
+     */
+    public PythonChatModelConnection(
+            PythonResourceAdapter adapter,
+            PyObject chatModel,
+            ResourceDescriptor descriptor,
+            BiFunction<String, ResourceType, Resource> getResource) {
+        super(descriptor, getResource);
+        this.chatModel = chatModel;
+    }
+
+    @Override
+    public Object getPythonResource() {
+        return chatModel;
+    }
+
+    @Override
+    public ChatMessage chat(
+            List<ChatMessage> messages, List<Tool> tools, Map<String, Object> 
arguments) {
+        throw new UnsupportedOperationException(

Review Comment:
   Why is this not supported?



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