xintongsong commented on code in PR #356: URL: https://github.com/apache/flink-agents/pull/356#discussion_r2641714429
########## api/src/main/java/org/apache/flink/agents/api/prompt/LocalPrompt.java: ########## @@ -0,0 +1,207 @@ +/* + * 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.prompt; + +import org.apache.flink.agents.api.chat.messages.ChatMessage; +import org.apache.flink.agents.api.chat.messages.MessageRole; +import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonCreator; +import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonTypeInfo; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.function.Function; +import java.util.stream.Collectors; + +/** + * Local prompt implementation for language models. + * + * <p>This prompt implementation uses a local template that can be either a string or a sequence of + * ChatMessage objects. The template supports placeholder substitution using {variable} syntax. + * + * <p>Example usage: + * + * <pre>{@code + * // String template + * LocalPrompt prompt = new LocalPrompt("Hello {name}!"); + * String result = prompt.formatString(Map.of("name", "World")); + * // result: "Hello World!" + * + * // Message template + * List<ChatMessage> messages = List.of( + * new ChatMessage(MessageRole.SYSTEM, "You are {role}"), + * new ChatMessage(MessageRole.USER, "Help me with {task}") + * ); + * LocalPrompt prompt2 = new LocalPrompt(messages); + * List<ChatMessage> result2 = prompt2.formatMessages( + * MessageRole.SYSTEM, + * Map.of("role", "an assistant", "task", "coding") + * ); + * }</pre> + */ +public class LocalPrompt extends Prompt { Review Comment: I see. Can we move `LocalPrompt` to the `plan` module, and use reflection to create it in `Prompt.fromText/Messages`? My point is to hide it from the user-facing APIs if possible. -- 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]
