Skip to content

Commit

Permalink
1937 - implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
marko-kriskovic committed Jan 15, 2025
1 parent 33e1882 commit 4da1965
Show file tree
Hide file tree
Showing 5 changed files with 336 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.bytechef.component.ai.text.action.SentimentAction;
import com.bytechef.component.ai.text.action.SimilaritySearchAction;
import com.bytechef.component.ai.text.action.SummarizeTextAction;
import com.bytechef.component.ai.text.action.TextGenerationAction;
import com.bytechef.component.definition.ComponentCategory;
import com.bytechef.component.definition.ComponentDefinition;
import com.bytechef.config.ApplicationProperties;
Expand Down Expand Up @@ -66,7 +67,8 @@ private AiTextComponentDefinitionImpl(ApplicationProperties.Ai.Component compone
new SentimentAction(component).actionDefinition,
new ScoreAction(component).actionDefinition,
new SummarizeTextAction(component).actionDefinition,
new SimilaritySearchAction(component).actionDefinition));
new SimilaritySearchAction(component).actionDefinition,
new TextGenerationAction(component).actionDefinition));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright 2023-present ByteChef Inc.
*
* Licensed 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
*
* https://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 com.bytechef.component.ai.text.action;

import static com.bytechef.component.ai.llm.constant.LLMConstants.MAX_TOKENS_PROPERTY;
import static com.bytechef.component.ai.llm.constant.LLMConstants.MODEL;
import static com.bytechef.component.ai.llm.constant.LLMConstants.TEMPERATURE_PROPERTY;
import static com.bytechef.component.ai.text.constant.AiTextConstants.MODEL_NO_OPTIONS_PROPERTY;
import static com.bytechef.component.ai.text.constant.AiTextConstants.MODEL_OPTIONS_PROPERTY;
import static com.bytechef.component.ai.text.constant.AiTextConstants.MODEL_PROVIDER_PROPERTY;
import static com.bytechef.component.ai.text.constant.AiTextConstants.MODEL_URL_PROPERTY;
import static com.bytechef.component.ai.text.constant.AiTextConstants.PROMPT;
import static com.bytechef.component.definition.ComponentDsl.action;
import static com.bytechef.component.definition.ComponentDsl.string;

import com.bytechef.component.ai.text.action.definition.AiTextActionDefinition;
import com.bytechef.component.ai.text.constant.AiTextConstants;
import com.bytechef.component.definition.Parameters;
import com.bytechef.config.ApplicationProperties;
import com.bytechef.platform.component.definition.ParametersFactory;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author Marko Kriskovic
*/
public class TextGenerationAction implements AiTextAction {

public final AiTextActionDefinition actionDefinition;

public TextGenerationAction(ApplicationProperties.Ai.Component component) {
this.actionDefinition = new AiTextActionDefinition(
action(AiTextConstants.TEXT_GENERATION)
.title("Text Generation")
.description("AI generates text based on the given prompt.")
.properties(
MODEL_PROVIDER_PROPERTY,
MODEL_OPTIONS_PROPERTY,
MODEL_NO_OPTIONS_PROPERTY,
MODEL_URL_PROPERTY,
string(PROMPT)
.label("Prompt")
.description("Write your prompt for generating text.")
.required(true),
MAX_TOKENS_PROPERTY,
TEMPERATURE_PROPERTY)
.output(),
component, this);
}

public Parameters createParameters(Parameters inputParameters) {
Map<String, Object> modelInputParametersMap = new HashMap<>();

modelInputParametersMap.put("messages",
List.of(
Map.of("content", inputParameters.getString(PROMPT), "role", "user")));
modelInputParametersMap.put("model", inputParameters.getString(MODEL));

return ParametersFactory.createParameters(modelInputParametersMap);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class AiTextConstants {

public static final String MODEL_PROVIDER = "modelProvider";
public static final String SUMMARIZE_TEXT = "summarizeText";
public static final String TEXT_GENERATION = "textGeneration";
public static final String SIMILARITY_SEARCH = "similaritySearch";
public static final String CLASSIFY_TEXT = "classifyText";
public static final String SENTIMENT_ANALYSIS = "sentimentAnalysis";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2023-present ByteChef Inc.
*
* Licensed 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
*
* https://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 com.bytechef.component.ai.text.task.handler;

import static com.bytechef.component.ai.text.constant.AiTextConstants.TEXT_GENERATION;
import static com.bytechef.platform.component.definition.AiComponentDefinition.AI_TEXT;

import com.bytechef.platform.component.facade.ActionDefinitionFacade;
import com.bytechef.platform.workflow.worker.task.handler.AbstractTaskHandler;
import org.springframework.stereotype.Component;

/**
* @author Ivica Cardic
*/
@Component(AI_TEXT + "/v1/" + TEXT_GENERATION)
public class AiTextTextGenerationTaskHandler extends AbstractTaskHandler {

public AiTextTextGenerationTaskHandler(ActionDefinitionFacade actionDefinitionFacade) {
super(AI_TEXT, 1, TEXT_GENERATION, actionDefinitionFacade);
}
}
Loading

0 comments on commit 4da1965

Please sign in to comment.