Skip to content
Merged

1885 #1888

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.bytechef.component.ComponentHandler;
import com.bytechef.component.ai.text.analysis.action.ClassifyTextAction;
import com.bytechef.component.ai.text.analysis.action.SentimentAnalysisAction;
import com.bytechef.component.ai.text.analysis.action.SummarizeTextAction;
import com.bytechef.component.definition.ComponentCategory;
import com.bytechef.component.definition.ComponentDefinition;
Expand Down Expand Up @@ -60,6 +61,7 @@ private AiTextAnalysisComponentDefinitionImpl(ApplicationProperties.Ai.Component
.categories(ComponentCategory.ARTIFICIAL_INTELLIGENCE)
.actions(
new ClassifyTextAction(component).actionDefinition,
new SentimentAnalysisAction(component).actionDefinition,
new SummarizeTextAction(component).actionDefinition));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* 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.analysis.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.analysis.constant.AiTextAnalysisConstants.MODEL_NO_OPTIONS_PROPERTY;
import static com.bytechef.component.ai.text.analysis.constant.AiTextAnalysisConstants.MODEL_OPTIONS_PROPERTY;
import static com.bytechef.component.ai.text.analysis.constant.AiTextAnalysisConstants.MODEL_PROVIDER_PROPERTY;
import static com.bytechef.component.ai.text.analysis.constant.AiTextAnalysisConstants.MODEL_URL_PROPERTY;
import static com.bytechef.component.ai.text.analysis.constant.AiTextAnalysisConstants.TEXT;
import static com.bytechef.component.definition.ComponentDsl.action;
import static com.bytechef.component.definition.ComponentDsl.string;

import com.bytechef.component.ai.text.analysis.action.definition.AiTextAnalysisActionDefinition;
import com.bytechef.component.ai.text.analysis.constant.AiTextAnalysisConstants;
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;

public class SentimentAnalysisAction implements AiTextAnalysisAction {
public final AiTextAnalysisActionDefinition actionDefinition;

public SentimentAnalysisAction(ApplicationProperties.Ai.Component component) {
this.actionDefinition = getActionDefinition(component);
}

private AiTextAnalysisActionDefinition getActionDefinition(ApplicationProperties.Ai.Component component) {
return new AiTextAnalysisActionDefinition(
action(AiTextAnalysisConstants.SENTIMENT_ANALYSIS)
.title("Sentiment Analysis")
.description("The sentiment of the text is typically categorized as POSITIVE, NEGATIVE, or NEUTRAL.")
.properties(
MODEL_PROVIDER_PROPERTY,
MODEL_OPTIONS_PROPERTY,
MODEL_NO_OPTIONS_PROPERTY,
MODEL_URL_PROPERTY,
string(TEXT)
.label("Text")
.description("The text that is to be classified.")
.required(true),
MAX_TOKENS_PROPERTY,
TEMPERATURE_PROPERTY)
.output(),
component, this);
}

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

String systemPrompt =
"You are a sentiment analysis specialist. I will give you some text and you will only reply with 'POSITIVE', 'NEGATIVE' or 'NEUTRAL'.";

String userBuilder = "Text: " + inputParameters.getString(TEXT);

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

return ParametersFactory.createParameters(modelInputParametersMap);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class AiTextAnalysisConstants {
public static final String MODEL_PROVIDER = "modelProvider";
public static final String SUMMARIZE_TEXT = "summarizeText";
public static final String CLASSIFY_TEXT = "classifyText";
public static final String SENTIMENT_ANALYSIS = "sentimentAnalysis";

public static final ModifiableIntegerProperty MODEL_PROVIDER_PROPERTY = integer(MODEL_PROVIDER)
.label("Model provider")
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.analysis.task.handler;

import static com.bytechef.component.ai.text.analysis.constant.AiTextAnalysisConstants.CLASSIFY_TEXT;
import static com.bytechef.platform.component.definition.AiComponentDefinition.AI_TEXT_ANALYSIS;

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

/**
* @author Ivica Cardic
*/
@Component(AI_TEXT_ANALYSIS + "/v1/" + CLASSIFY_TEXT)
public class AiTextAnalysisClassifyTextTaskHandler extends AbstractTaskHandler {

public AiTextAnalysisClassifyTextTaskHandler(ActionDefinitionFacade actionDefinitionFacade) {
super(AI_TEXT_ANALYSIS, 1, CLASSIFY_TEXT, actionDefinitionFacade);
}
}
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.analysis.task.handler;

import static com.bytechef.component.ai.text.analysis.constant.AiTextAnalysisConstants.SENTIMENT_ANALYSIS;
import static com.bytechef.platform.component.definition.AiComponentDefinition.AI_TEXT_ANALYSIS;

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

/**
* @author Ivica Cardic
*/
@Component(AI_TEXT_ANALYSIS + "/v1/" + SENTIMENT_ANALYSIS)
public class AiTextAnalysisSentimentAnalysisTaskHandler extends AbstractTaskHandler {

public AiTextAnalysisSentimentAnalysisTaskHandler(ActionDefinitionFacade actionDefinitionFacade) {
super(AI_TEXT_ANALYSIS, 1, SENTIMENT_ANALYSIS, actionDefinitionFacade);
}
}
Loading
Loading