-
Notifications
You must be signed in to change notification settings - Fork 220
[app-platform] add text concatenate node #444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
reeeborn33
wants to merge
4
commits into
ModelEngine-Group:main
Choose a base branch
from
reeeborn33:feature-text-concatenation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4b4979a
[app-builder] add text concatenation tool
reeeborn33 016f11c
[app-builder] add text concatenate node
reeeborn33 64c7cca
[app-builder] Implementing text concatenate node based on fit framework
cda8f4d
[appbuilder] modify fit version
reeeborn33 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>modelengine.fit.jade</groupId> | ||
<artifactId>app-builder-plugin-parent</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<groupId>modelengine.fit.jade.plugin</groupId> | ||
<artifactId>aipp-template-render</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.source>17</maven.compiler.source> | ||
<maven.compiler.target>17</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<!-- Services --> | ||
<dependency> | ||
<groupId>modelengine.jade.service</groupId> | ||
<artifactId>aipp-template-render-service</artifactId> | ||
</dependency> | ||
|
||
<!-- Test --> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>modelengine.fit.jade</groupId> | ||
<artifactId>aipp-service</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.fitframework</groupId> | ||
<artifactId>fit-build-maven-plugin</artifactId> | ||
<version>${fit.version}</version> | ||
<executions> | ||
<execution> | ||
<id>build-plugin</id> | ||
<goals> | ||
<goal>build-plugin</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>package-plugin</id> | ||
<goals> | ||
<goal>package-plugin</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-antrun-plugin</artifactId> | ||
<version>${maven.antrun.version}</version> | ||
<executions> | ||
<execution> | ||
<phase>install</phase> | ||
<configuration> | ||
<target> | ||
<copy file="${project.build.directory}/${project.build.finalName}.jar" | ||
todir="../../../build/plugins"/> | ||
</target> | ||
</configuration> | ||
<goals> | ||
<goal>run</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
41 changes: 41 additions & 0 deletions
41
...e-render/src/main/java/modelengine/fit/jade/aipp/template/render/TemplateServiceImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved. | ||
* This file is a part of the ModelEngine Project. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
package modelengine.fit.jade.aipp.template.render; | ||
|
||
import static modelengine.fitframework.util.ObjectUtils.nullIf; | ||
|
||
import modelengine.fitframework.annotation.Component; | ||
import modelengine.fitframework.parameterization.ParameterizationMode; | ||
import modelengine.fitframework.parameterization.ParameterizedString; | ||
import modelengine.fitframework.parameterization.ParameterizedStringResolver; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
/** | ||
* {@link TemplateService} 的实现类。 | ||
* | ||
* @author 孙怡菲 | ||
* @since 2025-08-29 | ||
*/ | ||
@Component | ||
public class TemplateServiceImpl implements TemplateService { | ||
reeeborn33 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@Override | ||
public String renderTemplate(String template, Map<String, Object> args) { | ||
if (template == null) { | ||
return null; | ||
} | ||
if (args == null) { | ||
args = Map.of(); | ||
} | ||
Map<String, Object> params = nullIf(args, Collections.emptyMap()); | ||
ParameterizedStringResolver resolver = | ||
ParameterizedStringResolver.create("{{", "}}", '/', ParameterizationMode.LENIENT_EMPTY); | ||
ParameterizedString parameterizedString = resolver.resolve(template); | ||
return parameterizedString.format(params, null); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
app-builder/plugins/aipp-template-render/src/main/resources/application.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
fit: | ||
beans: | ||
packages: | ||
- 'modelengine.fit.jade.aipp.template.render' |
118 changes: 118 additions & 0 deletions
118
...nder/src/test/java/modelengine/fit/jade/aipp/template/render/TemplateServiceImplTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved. | ||
* This file is a part of the ModelEngine Project. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
package modelengine.fit.jade.aipp.template.render; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* {@link TemplateServiceImpl} 的测试类。 | ||
* | ||
* @author 孙怡菲 | ||
* @since 2025-08-28 | ||
*/ | ||
class TemplateServiceImplTest { | ||
private TemplateServiceImpl textTool; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
this.textTool = new TemplateServiceImpl(); | ||
} | ||
|
||
@Test | ||
@DisplayName("基础模板变量替换成功") | ||
void shouldReplaceBasicVariables() { | ||
String template = "Hello {{name}}, your score is {{score}}."; | ||
Map<String, Object> args = new HashMap<>(); | ||
args.put("name", "Tom"); | ||
args.put("score", 95); | ||
|
||
String result = this.textTool.renderTemplate(template, args); | ||
assertEquals("Hello Tom, your score is 95.", result); | ||
} | ||
|
||
@Test | ||
@DisplayName("缺失变量时置为空字符串") | ||
void shouldReplaceMissingVariableWithEmpty() { | ||
String template = "Hello {{name}}, your score is {{score}}."; | ||
Map<String, Object> args = new HashMap<>(); | ||
args.put("name", "Tom"); | ||
|
||
String result = this.textTool.renderTemplate(template, args); | ||
assertEquals("Hello Tom, your score is .", result); | ||
} | ||
|
||
@Test | ||
@DisplayName("空参数Map时模板变量置为空") | ||
void shouldHandleEmptyArgsMap() { | ||
String template = "Hello {{name}}!"; | ||
Map<String, Object> args = new HashMap<>(); | ||
|
||
String result = this.textTool.renderTemplate(template, args); | ||
assertEquals("Hello !", result); | ||
} | ||
|
||
@Test | ||
@DisplayName("参数为null时模板变量置为空") | ||
void shouldHandleNullArgs() { | ||
String template = "Hello {{name}}!"; | ||
|
||
String result = this.textTool.renderTemplate(template, null); | ||
assertEquals("Hello !", result); | ||
} | ||
|
||
@Test | ||
@DisplayName("模板无占位符时内容保持不变") | ||
void shouldHandleTemplateWithoutPlaceholders() { | ||
String template = "Hello world!"; | ||
|
||
String result = this.textTool.renderTemplate(template, Map.of("name", "Tom")); | ||
assertEquals("Hello world!", result); | ||
} | ||
|
||
@Test | ||
@DisplayName("变量中包含占位符内容保持不变") | ||
void shouldHandleVariableWithPlaceholders() { | ||
String template = "Hello {{name}}!"; | ||
|
||
String result = this.textTool.renderTemplate(template, Map.of("name", "{{Tom}}")); | ||
assertEquals("Hello {{Tom}}!", result); | ||
} | ||
|
||
@Test | ||
@DisplayName("变量为 List 时正常替换") | ||
void shouldReplaceListVariableCorrectly() { | ||
String template = "Items: {{items}}"; | ||
Map<String, Object> args = new HashMap<>(); | ||
args.put("items", Arrays.asList("apple", "banana", "cherry")); | ||
|
||
String result = this.textTool.renderTemplate(template, args); | ||
assertEquals("Items: [apple, banana, cherry]", result); | ||
} | ||
|
||
@Test | ||
@DisplayName("变量为 Map 时正常替换") | ||
void shouldReplaceMapVariableCorrectly() { | ||
String template = "Map data: {{data}}"; | ||
Map<String, Object> args = new HashMap<>(); | ||
Map<String, Object> mapValue = new LinkedHashMap<>(); | ||
mapValue.put("a", 1); | ||
mapValue.put("b", 2); | ||
args.put("data", mapValue); | ||
|
||
String result = this.textTool.renderTemplate(template, args); | ||
assertEquals("Map data: {a=1, b=2}", result); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.