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


##########
e2e-test/integration-test/src/main/java/org/apache/flink/agents/integration/test/AgentWithPythonChatModel.java:
##########
@@ -0,0 +1,144 @@
+/*
+ * 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.integration.test;
+
+import org.apache.flink.agents.api.Agent;
+import org.apache.flink.agents.api.InputEvent;
+import org.apache.flink.agents.api.OutputEvent;
+import org.apache.flink.agents.api.annotation.Action;
+import org.apache.flink.agents.api.annotation.ChatModelConnection;
+import org.apache.flink.agents.api.annotation.ChatModelSetup;
+import org.apache.flink.agents.api.annotation.Tool;
+import org.apache.flink.agents.api.annotation.ToolParam;
+import org.apache.flink.agents.api.chat.messages.ChatMessage;
+import org.apache.flink.agents.api.chat.messages.MessageRole;
+import org.apache.flink.agents.api.context.RunnerContext;
+import org.apache.flink.agents.api.event.ChatRequestEvent;
+import org.apache.flink.agents.api.event.ChatResponseEvent;
+import org.apache.flink.agents.api.resource.ResourceDescriptor;
+import org.apache.flink.agents.api.resource.ResourceType;
+import org.apache.flink.agents.api.resource.python.PythonChatModelConnection;
+import org.apache.flink.agents.api.resource.python.PythonChatModelSetup;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Agent example integrating a built-in Python chat model into Flink Agents.
+ *
+ * <p>This class demonstrates how to:
+ *
+ * <ul>
+ *   <li>Declare a chat model connection using {@link ChatModelConnection} 
metadata pointing to
+ *       {@link PythonChatModelConnection}
+ *   <li>Declare a chat model setup using {@link ChatModelSetup} metadata 
pointing to {@link
+ *       PythonChatModelSetup}
+ *   <li>Expose callable tools via {@link Tool} annotated static methods 
(temperature conversion,
+ *       BMI, random number)
+ *   <li>Fetch a chat model from the {@link RunnerContext} and perform a 
single-turn chat
+ *   <li>Emit the model response as an {@link OutputEvent}
+ * </ul>
+ *
+ * <p>The {@code pythonChatModel()} method publishes a resource with type 
{@link
+ * ResourceType#CHAT_MODEL} so it can be retrieved at runtime inside the 
{@code process} action. The
+ * resource is configured with the connection name, the model name and the 
list of tool names that
+ * the model is allowed to call.
+ */
+public class AgentWithPythonChatModel extends Agent {
+    @ChatModelConnection
+    public static ResourceDescriptor pythonChatModelConnection() {
+        return 
ResourceDescriptor.Builder.newBuilder(PythonChatModelConnection.class.getName())
+                .addInitialArgument(
+                        "module", 
"flink_agents.integrations.chat_models.tongyi_chat_model")
+                .addInitialArgument("clazz", "TongyiChatModelConnection")
+                .build();
+    }
+
+    @ChatModelSetup
+    public static ResourceDescriptor pythonChatModel() {
+        return 
ResourceDescriptor.Builder.newBuilder(PythonChatModelSetup.class.getName())
+                .addInitialArgument("connection", "pythonChatModelConnection")
+                .addInitialArgument(
+                        "module", 
"flink_agents.integrations.chat_models.tongyi_chat_model")

Review Comment:
   Should we use ollama model for e2e test?



##########
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 can't Python chat model call `formatMessages(MessageRole defaultRole, 
Map<String, String> kwargs)` but `formatMessages(MessageRole defaultRole, 
Map<String, Object> kwargs)`?



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