Sxnan commented on code in PR #314:
URL: https://github.com/apache/flink-agents/pull/314#discussion_r2525957263
##########
api/src/main/java/org/apache/flink/agents/api/prompt/Prompt.java:
##########
@@ -76,6 +77,14 @@ public String formatString(Map<String, String> kwargs) {
});
}
+ public List<ChatMessage> formatMessages(String defaultRoleValue,
Map<String, Object> kwargs) {
Review Comment:
Why do we need to pass the Object type as the value here? Can't we reuse the
`formatMessages(MessageRole defaultRole, Map<String, String> kwargs)`?
This method is not used in Java. We should have documentation to say this is
intended to be used by Python code.
##########
python/flink_agents/runtime/java/java_resourse_wrapper.py:
##########
Review Comment:
Typo in file name, should be java_resource_wrapper.py
##########
python/flink_agents/api/prompts/prompt.py:
##########
@@ -22,10 +22,10 @@
from flink_agents.api.chat_message import ChatMessage, MessageRole
from flink_agents.api.prompts.utils import format_string
-from flink_agents.api.resource import ResourceType, SerializableResource
+from flink_agents.api.resource import Resource, ResourceType,
SerializableResource
-class Prompt(SerializableResource, ABC):
+class Prompt(Resource, ABC):
Review Comment:
This change also affected MCPPrompt
##########
api/src/main/java/org/apache/flink/agents/api/resource/python/PythonChatModelConnection.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.resource.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.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;
+
+ public PythonChatModelConnection(
+ PythonResourceAdapter adapter,
Review Comment:
The adapter is not used. If it must be here for some reason, please document
it
##########
plan/src/main/java/org/apache/flink/agents/plan/AgentPlan.java:
##########
@@ -76,6 +79,8 @@ public class AgentPlan implements Serializable {
private AgentConfiguration config;
+ private PythonResourceAdapter pythonResourceAdapter;
Review Comment:
Is this serializable? Should it be transient?
##########
api/src/main/java/org/apache/flink/agents/api/resource/python/PythonResourceAdapter.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.resource.python;
+
+import org.apache.flink.agents.api.chat.messages.ChatMessage;
+import pemja.core.object.PyObject;
+
+import java.util.Map;
+
+/**
+ * Adapter interface for managing Python resources and facilitating
Java-Python interoperability.
+ * This interface provides methods to interact with Python objects, invoke
Python methods, and
+ * handle data conversion between Java and Python environments.
+ */
+public interface PythonResourceAdapter {
+
+ /**
+ * Retrieves a Python resource by name and type.
+ *
+ * @param resourceName the name of the resource to retrieve
+ * @param resourceType the type of the resource
+ * @return the retrieved resource object
+ */
+ Object getResource(String resourceName, String resourceType);
+
+ /**
+ * Initializes a Python resource instance from the specified module and
class.
+ *
+ * @param module the Python module containing the target class
+ * @param clazz the Python class name to instantiate
+ * @param kwargs keyword arguments to pass to the Python class constructor
+ * @return a PyObject representing the initialized Python resource
+ */
+ PyObject initPythonResource(String module, String clazz, Map<String,
Object> kwargs);
+
+ /**
+ * Invokes a method on a Python object with the specified parameters.
+ *
+ * @param obj the Python object on which to call the method
+ * @param methodName the name of the method to invoke
+ * @param kwargs keyword arguments to pass to the method
+ * @return the result of the method invocation
+ */
+ Object callMethod(Object obj, String methodName, Map<String, Object>
kwargs);
+
+ /**
+ * Converts a Java ChatMessage object to its Python equivalent.
+ *
+ * @param message the Java ChatMessage to convert
+ * @return the Python representation of the chat message
+ */
+ Object toPythonChatMessage(ChatMessage message);
Review Comment:
Does `ChatMessage` only make sense to ChatModel? If so, we should not put
the method in this General Resource Adapter interface
--
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]