Skip to content

Commit c52ad8f

Browse files
marko-kriskovicivicac
authored andcommitted
1345 - unmask action
1 parent 3299574 commit c52ad8f

5 files changed

Lines changed: 438 additions & 9 deletions

File tree

server/libs/modules/components/ai/universal/universal-text/src/main/java/com/bytechef/component/ai/universal/text/AiTextComponentHandler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.bytechef.component.ai.universal.text.action.SentimentAction;
2929
import com.bytechef.component.ai.universal.text.action.SimilaritySearchAction;
3030
import com.bytechef.component.ai.universal.text.action.SummarizeTextAction;
31+
import com.bytechef.component.ai.universal.text.action.UnmaskAction;
3132
import com.bytechef.component.definition.ComponentCategory;
3233
import com.bytechef.component.definition.ComponentDefinition;
3334
import com.bytechef.config.ApplicationProperties;
@@ -70,6 +71,7 @@ private AiUniversalTextComponentDefinitionImpl(
7071
ClassifyTextAction.of(provider, propertyService),
7172
ExtractDataAction.of(provider, propertyService),
7273
MaskAction.of(provider, propertyService),
74+
UnmaskAction.of(provider, propertyService),
7375
SentimentAction.of(provider, propertyService),
7476
ScoreAction.of(provider, propertyService),
7577
SummarizeTextAction.of(provider, propertyService),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Copyright 2025 ByteChef
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.bytechef.component.ai.universal.text.action;
18+
19+
import static com.bytechef.component.ai.llm.ChatModel.Role.SYSTEM;
20+
import static com.bytechef.component.ai.llm.ChatModel.Role.USER;
21+
import static com.bytechef.component.ai.llm.constant.LLMConstants.MAX_TOKENS_PROPERTY;
22+
import static com.bytechef.component.ai.llm.constant.LLMConstants.MODEL;
23+
import static com.bytechef.component.ai.llm.constant.LLMConstants.ROLE;
24+
import static com.bytechef.component.ai.llm.constant.LLMConstants.TEMPERATURE_PROPERTY;
25+
import static com.bytechef.component.ai.universal.text.constant.AiTextConstants.MASK_MAP;
26+
import static com.bytechef.component.ai.universal.text.constant.AiTextConstants.MODEL_NO_OPTIONS_PROPERTY;
27+
import static com.bytechef.component.ai.universal.text.constant.AiTextConstants.MODEL_OPTIONS_PROPERTY;
28+
import static com.bytechef.component.ai.universal.text.constant.AiTextConstants.MODEL_URL_PROPERTY;
29+
import static com.bytechef.component.ai.universal.text.constant.AiTextConstants.PROVIDER_PROPERTY;
30+
import static com.bytechef.component.ai.universal.text.constant.AiTextConstants.TEXT;
31+
import static com.bytechef.component.definition.ComponentDsl.action;
32+
import static com.bytechef.component.definition.ComponentDsl.object;
33+
import static com.bytechef.component.definition.ComponentDsl.outputSchema;
34+
import static com.bytechef.component.definition.ComponentDsl.sampleOutput;
35+
import static com.bytechef.component.definition.ComponentDsl.string;
36+
37+
import com.bytechef.component.ai.universal.text.action.definition.AiTextActionDefinition;
38+
import com.bytechef.component.ai.universal.text.constant.AiTextConstants;
39+
import com.bytechef.component.definition.Parameters;
40+
import com.bytechef.config.ApplicationProperties;
41+
import com.bytechef.platform.component.definition.ParametersFactory;
42+
import com.bytechef.platform.configuration.service.PropertyService;
43+
import java.util.HashMap;
44+
import java.util.List;
45+
import java.util.Map;
46+
47+
/**
48+
* @author Marko Kriskovic
49+
*/
50+
public class UnmaskAction implements AiTextAction {
51+
52+
public static AiTextActionDefinition of(
53+
ApplicationProperties.Ai.Provider provider, PropertyService propertyService) {
54+
55+
return new AiTextActionDefinition(
56+
action(AiTextConstants.UNMASK)
57+
.title("Unmask")
58+
.description("Uses AI and a map of masking entities to unmask the text.")
59+
.properties(
60+
PROVIDER_PROPERTY.apply(provider, propertyService),
61+
MODEL_OPTIONS_PROPERTY,
62+
MODEL_NO_OPTIONS_PROPERTY,
63+
MODEL_URL_PROPERTY,
64+
string(TEXT)
65+
.label("Text")
66+
.description("The text to process.")
67+
.required(true),
68+
object(MASK_MAP)
69+
.label("Masked map")
70+
.description("Map of masked entities to replace with values.")
71+
.additionalProperties(string()),
72+
MAX_TOKENS_PROPERTY,
73+
TEMPERATURE_PROPERTY)
74+
.output(
75+
outputSchema(string().description("The text with sensitive content redacted.")),
76+
sampleOutput("Hello, my name is [REDACTED] and my email is [EMAIL].")),
77+
provider, new UnmaskAction(), propertyService);
78+
}
79+
80+
private UnmaskAction() {
81+
}
82+
83+
@Override
84+
public Parameters createParameters(Parameters inputParameters) {
85+
Map<String, Object> modelInputParametersMap = new HashMap<>();
86+
87+
String systemPrompt =
88+
"Replace the redacted content with values in the map. Return only the unredacted text with no additional commentary.";
89+
90+
StringBuilder userBuilder = new StringBuilder();
91+
92+
userBuilder.append("Text: ")
93+
.append(inputParameters.getString(TEXT))
94+
.append("\n\nInstructions:\n");
95+
96+
Map<String, String> maskMap = inputParameters.getMap(MASK_MAP, String.class, Map.of());
97+
98+
if (!maskMap.isEmpty()) {
99+
userBuilder.append("Mask Map: ")
100+
.append("\n");
101+
maskMap.forEach((key, value) -> userBuilder.append("- ")
102+
.append(key)
103+
.append(": ")
104+
.append(value)
105+
.append("\n"));
106+
}
107+
108+
modelInputParametersMap.put(
109+
"messages",
110+
List.of(
111+
Map.of("content", systemPrompt, ROLE, SYSTEM.name()),
112+
Map.of("content", userBuilder.toString(), ROLE, USER.name())));
113+
modelInputParametersMap.put("model", inputParameters.getString(MODEL));
114+
115+
return ParametersFactory.create(modelInputParametersMap);
116+
}
117+
}

server/libs/modules/components/ai/universal/universal-text/src/main/java/com/bytechef/component/ai/universal/text/constant/AiTextConstants.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,13 @@ public class AiTextConstants {
5555
public static final String IS_DECIMAL = "isDecimal";
5656
public static final String NUM_RESULTS = "numResults";
5757
public static final String CHUNK_SIZE = "chunkSize";
58-
public static final String DATA_FIELDS = "dataFields";
59-
public static final String FIELD_NAME = "fieldName";
60-
public static final String FIELD_TYPE = "fieldType";
61-
public static final String FIELD_DESCRIPTION = "fieldDescription";
62-
public static final String EXTRACT_LIST = "extractList";
6358
public static final String ADDITIONAL_CONTEXT = "additionalContext";
6459
public static final String SENSITIVE_KEYWORDS = "sensitiveKeywords";
6560
public static final String PII_DETECTION = "piiDetection";
6661
public static final String CUSTOM_PATTERNS = "customRegexPatterns";
67-
public static final String MODE = "mode";
68-
public static final String MODE_CLASSIFY = "classify";
69-
public static final String MODE_SANITIZE = "sanitize";
70-
public static final String BLOCKED_MESSAGE = "blockedMessage";
7162
public static final String MASK = "mask";
63+
public static final String UNMASK = "unmask";
64+
public static final String MASK_MAP = "maskMap";
7265
public static final String SUMMARIZE_TEXT = "summarizeText";
7366
public static final String TEXT_GENERATION = "textGeneration";
7467
public static final String SIMILARITY_SEARCH = "similaritySearch";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2025 ByteChef
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.bytechef.component.ai.universal.text.task.handler;
18+
19+
import static com.bytechef.component.ai.universal.text.constant.AiTextConstants.UNMASK;
20+
import static com.bytechef.platform.component.definition.AiUniversalComponentDefinition.AI_TEXT;
21+
22+
import com.bytechef.platform.component.facade.ActionDefinitionFacade;
23+
import com.bytechef.platform.workflow.worker.task.handler.AbstractTaskHandler;
24+
import org.springframework.stereotype.Component;
25+
26+
/**
27+
* @author Marko Kriskovic
28+
*/
29+
@Component(AI_TEXT + "/v1/" + UNMASK)
30+
public class AiTextUnmaskTaskHandler extends AbstractTaskHandler {
31+
32+
public AiTextUnmaskTaskHandler(ActionDefinitionFacade actionDefinitionFacade) {
33+
super(AI_TEXT, 1, UNMASK, actionDefinitionFacade);
34+
}
35+
}

0 commit comments

Comments
 (0)