Skip to content

Commit aa4bce2

Browse files
1937 - implemented
1 parent 33e1882 commit aa4bce2

File tree

5 files changed

+116
-1434
lines changed

5 files changed

+116
-1434
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.bytechef.component.ai.text.action.SentimentAction;
2626
import com.bytechef.component.ai.text.action.SimilaritySearchAction;
2727
import com.bytechef.component.ai.text.action.SummarizeTextAction;
28+
import com.bytechef.component.ai.text.action.TextGenerationAction;
2829
import com.bytechef.component.definition.ComponentCategory;
2930
import com.bytechef.component.definition.ComponentDefinition;
3031
import com.bytechef.config.ApplicationProperties;
@@ -66,7 +67,8 @@ private AiTextComponentDefinitionImpl(ApplicationProperties.Ai.Component compone
6667
new SentimentAction(component).actionDefinition,
6768
new ScoreAction(component).actionDefinition,
6869
new SummarizeTextAction(component).actionDefinition,
69-
new SimilaritySearchAction(component).actionDefinition));
70+
new SimilaritySearchAction(component).actionDefinition,
71+
new TextGenerationAction(component).actionDefinition));
7072
}
7173
}
7274
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright 2023-present ByteChef Inc.
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.text.action;
18+
19+
import static com.bytechef.component.ai.llm.constant.LLMConstants.MAX_TOKENS_PROPERTY;
20+
import static com.bytechef.component.ai.llm.constant.LLMConstants.MODEL;
21+
import static com.bytechef.component.ai.llm.constant.LLMConstants.TEMPERATURE_PROPERTY;
22+
import static com.bytechef.component.ai.text.constant.AiTextConstants.MODEL_NO_OPTIONS_PROPERTY;
23+
import static com.bytechef.component.ai.text.constant.AiTextConstants.MODEL_OPTIONS_PROPERTY;
24+
import static com.bytechef.component.ai.text.constant.AiTextConstants.MODEL_PROVIDER_PROPERTY;
25+
import static com.bytechef.component.ai.text.constant.AiTextConstants.MODEL_URL_PROPERTY;
26+
import static com.bytechef.component.ai.text.constant.AiTextConstants.PROMPT;
27+
import static com.bytechef.component.ai.text.constant.AiTextConstants.TEXT;
28+
import static com.bytechef.component.definition.ComponentDsl.action;
29+
import static com.bytechef.component.definition.ComponentDsl.string;
30+
31+
import com.bytechef.component.ai.text.action.definition.AiTextActionDefinition;
32+
import com.bytechef.component.ai.text.constant.AiTextConstants;
33+
import com.bytechef.component.definition.Parameters;
34+
import com.bytechef.config.ApplicationProperties;
35+
import com.bytechef.platform.component.definition.ParametersFactory;
36+
import java.util.HashMap;
37+
import java.util.List;
38+
import java.util.Map;
39+
40+
/**
41+
* @author Marko Kriskovic
42+
*/
43+
public class TextGenerationAction implements AiTextAction {
44+
45+
public final AiTextActionDefinition actionDefinition;
46+
47+
public TextGenerationAction(ApplicationProperties.Ai.Component component) {
48+
this.actionDefinition = new AiTextActionDefinition(
49+
action(AiTextConstants.TEXT_GENERATION)
50+
.title("Text Generation")
51+
.description("AI generates text based on the given prompt.")
52+
.properties(
53+
MODEL_PROVIDER_PROPERTY,
54+
MODEL_OPTIONS_PROPERTY,
55+
MODEL_NO_OPTIONS_PROPERTY,
56+
MODEL_URL_PROPERTY,
57+
string(PROMPT)
58+
.label("Prompt")
59+
.description("Write your prompt for generating text.")
60+
.required(true),
61+
MAX_TOKENS_PROPERTY,
62+
TEMPERATURE_PROPERTY)
63+
.output(),
64+
component, this);
65+
}
66+
67+
public Parameters createParameters(Parameters inputParameters) {
68+
Map<String, Object> modelInputParametersMap = new HashMap<>();
69+
70+
modelInputParametersMap.put("messages",
71+
List.of(
72+
Map.of("content", inputParameters.getString(TEXT), "role", "user")));
73+
modelInputParametersMap.put("model", inputParameters.getString(MODEL));
74+
75+
return ParametersFactory.createParameters(modelInputParametersMap);
76+
}
77+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public class AiTextConstants {
4848

4949
public static final String MODEL_PROVIDER = "modelProvider";
5050
public static final String SUMMARIZE_TEXT = "summarizeText";
51+
public static final String TEXT_GENERATION = "textGeneration";
5152
public static final String SIMILARITY_SEARCH = "similaritySearch";
5253
public static final String CLASSIFY_TEXT = "classifyText";
5354
public static final String SENTIMENT_ANALYSIS = "sentimentAnalysis";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2023-present ByteChef Inc.
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.text.task.handler;
18+
19+
import static com.bytechef.component.ai.text.constant.AiTextConstants.TEXT_GENERATION;
20+
import static com.bytechef.platform.component.definition.AiComponentDefinition.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 Ivica Cardic
28+
*/
29+
@Component(AI_TEXT + "/v1/" + TEXT_GENERATION)
30+
public class AiTextTextGenerationTaskHandler extends AbstractTaskHandler {
31+
32+
public AiTextTextGenerationTaskHandler(ActionDefinitionFacade actionDefinitionFacade) {
33+
super(AI_TEXT, 1, TEXT_GENERATION, actionDefinitionFacade);
34+
}
35+
}

0 commit comments

Comments
 (0)