diff --git a/server/apps/server-app/build.gradle.kts b/server/apps/server-app/build.gradle.kts index 314a9c369bd..181595a1f84 100644 --- a/server/apps/server-app/build.gradle.kts +++ b/server/apps/server-app/build.gradle.kts @@ -128,6 +128,7 @@ dependencies { implementation(project(":server:libs:modules:components:accelo")) implementation(project(":server:libs:modules:components:active-campaign")) implementation(project(":server:libs:modules:components:affinity")) + implementation(project(":server:libs:modules:components:ai:ai-text-analysis")) implementation(project(":server:libs:modules:components:airtable")) implementation(project(":server:libs:modules:components:aitable")) implementation(project(":server:libs:modules:components:app-event")) diff --git a/server/ee/apps/worker-app/build.gradle.kts b/server/ee/apps/worker-app/build.gradle.kts index 062081dbc62..d84b597527c 100644 --- a/server/ee/apps/worker-app/build.gradle.kts +++ b/server/ee/apps/worker-app/build.gradle.kts @@ -50,6 +50,7 @@ dependencies { implementation(project(":server:libs:modules:components:accelo")) implementation(project(":server:libs:modules:components:active-campaign")) implementation(project(":server:libs:modules:components:affinity")) + implementation(project(":server:libs:modules:components:ai:ai-text-analysis")) implementation(project(":server:libs:modules:components:airtable")) implementation(project(":server:libs:modules:components:aitable")) implementation(project(":server:libs:modules:components:app-event")) diff --git a/server/libs/config/app-config/src/main/java/com/bytechef/config/ApplicationProperties.java b/server/libs/config/app-config/src/main/java/com/bytechef/config/ApplicationProperties.java index 28fea114097..917cfacc3fe 100644 --- a/server/libs/config/app-config/src/main/java/com/bytechef/config/ApplicationProperties.java +++ b/server/libs/config/app-config/src/main/java/com/bytechef/config/ApplicationProperties.java @@ -304,16 +304,25 @@ public void setLevel(Level level) { */ public static class Ai { + private Component component = new Component(); private Copilot copilot = new Copilot(); public Copilot getCopilot() { return copilot; } + public Component getComponent() { + return component; + } + public void setCopilot(Copilot copilot) { this.copilot = copilot; } + public void setComponent(Component component) { + this.component = component; + } + public static class Copilot { public enum Provider { @@ -396,6 +405,215 @@ public void setModel(String model) { } } } + + public static class Component { + private AmazonBedrock amazonBedrock = new AmazonBedrock(); + + public AmazonBedrock getAmazonBedrock() { + return amazonBedrock; + } + + public void setAmazonBedrock(AmazonBedrock amazonBedrock) { + this.amazonBedrock = amazonBedrock; + } + + public static class AmazonBedrock { + + private String apiKey; + + public String getApiKey() { + return apiKey; + } + + public void setApiKey(String apiKey) { + this.apiKey = apiKey; + } + } + + private Anthropic anthropic = new Anthropic(); + + public Anthropic getAnthropic() { + return anthropic; + } + + public void setAnthropic(Anthropic anthropic) { + this.anthropic = anthropic; + } + + public static class Anthropic { + + private String apiKey; + + public String getApiKey() { + return apiKey; + } + + public void setApiKey(String apiKey) { + this.apiKey = apiKey; + } + } + + private AzureOpenAi azureOpenAi = new AzureOpenAi(); + + public AzureOpenAi getAzureOpenAi() { + return azureOpenAi; + } + + public void setAzureOpenAi(AzureOpenAi azureOpenAi) { + this.azureOpenAi = azureOpenAi; + } + + public static class AzureOpenAi { + + private String apiKey; + + public String getApiKey() { + return apiKey; + } + + public void setApiKey(String apiKey) { + this.apiKey = apiKey; + } + } + + private Groq groq = new Groq(); + + public Groq getGroq() { + return groq; + } + + public void setGroq(Groq groq) { + this.groq = groq; + } + + public static class Groq { + + private String apiKey; + + public String getApiKey() { + return apiKey; + } + + public void setApiKey(String apiKey) { + this.apiKey = apiKey; + } + } + + private Nvidia nvidia = new Nvidia(); + + public Nvidia getNvidia() { + return nvidia; + } + + public void setNvidia(Nvidia nvidia) { + this.nvidia = nvidia; + } + + public static class Nvidia { + + private String apiKey; + + public String getApiKey() { + return apiKey; + } + + public void setApiKey(String apiKey) { + this.apiKey = apiKey; + } + } + + private HuggingFace huggingFace = new HuggingFace(); + + public HuggingFace getHuggingFace() { + return huggingFace; + } + + public void setHuggingFace(HuggingFace huggingFace) { + this.huggingFace = huggingFace; + } + + public static class HuggingFace { + + private String apiKey; + + public String getApiKey() { + return apiKey; + } + + public void setApiKey(String apiKey) { + this.apiKey = apiKey; + } + } + + private Mistral mistral = new Mistral(); + + public Mistral getMistral() { + return mistral; + } + + public void setMistral(Mistral mistral) { + this.mistral = mistral; + } + + public static class Mistral { + + private String apiKey; + + public String getApiKey() { + return apiKey; + } + + public void setApiKey(String apiKey) { + this.apiKey = apiKey; + } + } + + private OpenAi openAi = new OpenAi(); + + public OpenAi getOpenAi() { + return openAi; + } + + public void setOpenAi(OpenAi openAi) { + this.openAi = openAi; + } + + public static class OpenAi { + + private String apiKey; + + public String getApiKey() { + return apiKey; + } + + public void setApiKey(String apiKey) { + this.apiKey = apiKey; + } + } + + private VertexGemini vertexGemini = new VertexGemini(); + + public VertexGemini getVertexGemini() { + return vertexGemini; + } + + public void setVertexGemini(VertexGemini vertexGemini) { + this.vertexGemini = vertexGemini; + } + + public static class VertexGemini { + + private String apiKey; + + public String getApiKey() { + return apiKey; + } + + public void setApiKey(String apiKey) { + this.apiKey = apiKey; + } + } + } } /** diff --git a/server/libs/modules/components/ai/ai-text-analysis/build.gradle.kts b/server/libs/modules/components/ai/ai-text-analysis/build.gradle.kts new file mode 100644 index 00000000000..21c8ed9efb2 --- /dev/null +++ b/server/libs/modules/components/ai/ai-text-analysis/build.gradle.kts @@ -0,0 +1,21 @@ +version="1.0" + +dependencies { + implementation("org.springframework.boot:spring-boot-autoconfigure") + + implementation(project(":server:libs:config:app-config")) + implementation(project(":server:libs:platform:platform-component:platform-component-api")) + + implementation(project(":server:libs:modules:components:llm")) + implementation(project(":server:libs:modules:components:llm:amazon-bedrock")) + implementation(project(":server:libs:modules:components:llm:anthropic")) + implementation(project(":server:libs:modules:components:llm:azure-openai")) + implementation(project(":server:libs:modules:components:llm:groq")) + implementation(project(":server:libs:modules:components:llm:hugging-face")) + implementation(project(":server:libs:modules:components:llm:mistral")) + implementation(project(":server:libs:modules:components:llm:nvidia")) + implementation(project(":server:libs:modules:components:llm:openai")) + implementation(project(":server:libs:modules:components:llm:stability")) + implementation(project(":server:libs:modules:components:llm:vertex:gemini")) + implementation(project(":server:libs:modules:components:llm:watsonx")) +} diff --git a/server/libs/modules/components/ai/ai-text-analysis/src/main/java/com/bytechef/component/ai/text/analysis/AiTextAnalysisComponentHandler.java b/server/libs/modules/components/ai/ai-text-analysis/src/main/java/com/bytechef/component/ai/text/analysis/AiTextAnalysisComponentHandler.java new file mode 100644 index 00000000000..721481c8f93 --- /dev/null +++ b/server/libs/modules/components/ai/ai-text-analysis/src/main/java/com/bytechef/component/ai/text/analysis/AiTextAnalysisComponentHandler.java @@ -0,0 +1,63 @@ +/* + * 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; + +import static com.bytechef.component.definition.ComponentDsl.component; +import static com.bytechef.platform.component.definition.AIComponentDefinition.AI_TEXT_ANALYSIS; + +import com.bytechef.component.ComponentHandler; +import com.bytechef.component.ai.text.analysis.action.SummarizeTextAction; +import com.bytechef.component.definition.ComponentCategory; +import com.bytechef.component.definition.ComponentDefinition; +import com.bytechef.config.ApplicationProperties; +import com.bytechef.platform.component.definition.AIComponentDefinition; +import com.bytechef.platform.component.definition.AbstractComponentDefinitionWrapper; +import org.springframework.stereotype.Component; + +/** + * @author Marko Kriskovic + */ +@Component(AI_TEXT_ANALYSIS + "_v1_ComponentHandler") +public class AiTextAnalysisComponentHandler implements ComponentHandler { + + private final AIComponentDefinition componentDefinition; + + public AiTextAnalysisComponentHandler(ApplicationProperties applicationProperties) { + ApplicationProperties.Ai ai = applicationProperties.getAi(); + + this.componentDefinition = new AiTextAnalysisComponentDefinitionImpl(ai.getComponent()); + } + + @Override + public ComponentDefinition getDefinition() { + return componentDefinition; + } + + private static class AiTextAnalysisComponentDefinitionImpl + extends AbstractComponentDefinitionWrapper implements AIComponentDefinition { + + private AiTextAnalysisComponentDefinitionImpl(ApplicationProperties.Ai.Component component) { + super( + component(AI_TEXT_ANALYSIS) + .title("AI Text Analysis") + .description("AI Helper component for text analysis.") + .icon("path:assets/ai-text-analysis.svg") + .categories(ComponentCategory.ARTIFICIAL_INTELLIGENCE) + .actions(new SummarizeTextAction(component).actionDefinition)); + } + } +} diff --git a/server/libs/modules/components/ai/ai-text-analysis/src/main/java/com/bytechef/component/ai/text/analysis/action/SummarizeTextAction.java b/server/libs/modules/components/ai/ai-text-analysis/src/main/java/com/bytechef/component/ai/text/analysis/action/SummarizeTextAction.java new file mode 100644 index 00000000000..3e4dc9a1823 --- /dev/null +++ b/server/libs/modules/components/ai/ai-text-analysis/src/main/java/com/bytechef/component/ai/text/analysis/action/SummarizeTextAction.java @@ -0,0 +1,166 @@ +/* + * 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.text.analysis.constant.AiTextAnalysisConstants.FORMAT; +import static com.bytechef.component.ai.text.analysis.constant.AiTextAnalysisConstants.MODEL_PROVIDER; +import static com.bytechef.component.ai.text.analysis.constant.AiTextAnalysisConstants.PROMPT; +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.integer; +import static com.bytechef.component.definition.ComponentDsl.option; +import static com.bytechef.component.definition.ComponentDsl.string; +import static com.bytechef.component.llm.constant.LLMConstants.MAX_TOKENS_PROPERTY; +import static com.bytechef.component.llm.constant.LLMConstants.MODEL; +import static com.bytechef.component.llm.constant.LLMConstants.TEMPERATURE_PROPERTY; + +import com.bytechef.component.ai.text.analysis.action.definition.AiTextAnalysisActionDefinition; +import com.bytechef.component.ai.text.analysis.constant.AiTextAnalysisConstants; +import com.bytechef.component.amazon.bedrock.constant.AmazonBedrockConstants; +import com.bytechef.component.anthropic.constant.AnthropicConstants; +import com.bytechef.component.mistral.constant.MistralConstants; +import com.bytechef.component.openai.constant.OpenAIConstants; +import com.bytechef.component.vertex.gemini.constant.VertexGeminiConstants; +import com.bytechef.config.ApplicationProperties; + +/** + * @author Marko Kriskovic + */ +public class SummarizeTextAction { + + public final AiTextAnalysisActionDefinition actionDefinition; + + public SummarizeTextAction(ApplicationProperties.Ai.Component component) { + this.actionDefinition = new AiTextAnalysisActionDefinition( + action(AiTextAnalysisConstants.SUMMARIZE_TEXT) + .title("Summarize Text") + .description("AI reads, analyzes and summarizes your text into a shorter format.") + .properties( + integer(MODEL_PROVIDER) + .label("Model provider") + .options( + option("Amazon Bedrock: Anthropic 2", 0), + option("Amazon Bedrock: Anthropic 3", 1), + option("Amazon Bedrock: Cohere", 2), + option("Amazon Bedrock: Jurassic 2", 3), + option("Amazon Bedrock: Llama", 4), + option("Amazon Bedrock: Titan", 5), + option("Anthropic", 6), + option("Azure Open AI", 7), + option("Groq", 8), + option("NVIDIA", 9), + option("Hugging Face", 10), + option("Mistral", 11), + option("Open AI", 12), + option("Vertex Gemini", 13)) + .required(true), + string(MODEL) + .label("Model") + .description("ID of the model to use.") + .options(AmazonBedrockConstants.ANTHROPIC2_MODELS) + .displayCondition("modelProvider == 0") + .required(true), + string(MODEL) + .label("Model") + .description("ID of the model to use.") + .options(AmazonBedrockConstants.ANTHROPIC3_MODELS) + .displayCondition("modelProvider == 1") + .required(true), + string(MODEL) + .label("Model") + .description("ID of the model to use.") + .options(AmazonBedrockConstants.COHERE_MODELS) + .displayCondition("modelProvider == 2") + .required(true), + string(MODEL) + .label("Model") + .description("ID of the model to use.") + .options(AmazonBedrockConstants.JURASSIC2_MODELS) + .displayCondition("modelProvider == 3") + .required(true), + string(MODEL) + .label("Model") + .description("ID of the model to use.") + .options(AmazonBedrockConstants.LLAMA_MODELS) + .displayCondition("modelProvider == 4") + .required(true), + string(MODEL) + .label("Model") + .description("ID of the model to use.") + .options(AmazonBedrockConstants.TITAN_MODELS) + .displayCondition("modelProvider == 5") + .required(true), + string(MODEL) + .label("Model") + .description("ID of the model to use.") + .options(AnthropicConstants.MODELS) + .displayCondition("modelProvider == 6") + .required(true), + string(MODEL) + .label("Model") + .description("ID of the model to use.") + .displayCondition("modelProvider >= 7 && modelProvider <= 9") + .required(true), + string(MODEL) + .label("URL") + .description("Url of the inference endpoint.") + .displayCondition("modelProvider == 10") + .required(true), + string(MODEL) + .label("Model") + .description("ID of the model to use.") + .options(MistralConstants.MODELS) + .displayCondition("modelProvider == 11") + .required(true), + string(MODEL) + .label("Model") + .description("ID of the model to use.") + .options(OpenAIConstants.MODELS) + .displayCondition("modelProvider == 12") + .required(true), + string(MODEL) + .label("Model") + .description("ID of the model to use.") + .options(VertexGeminiConstants.MODELS) + .displayCondition("modelProvider == 13") + .required(true), + string(TEXT) + .label("Text") + .description("The text that is to be summarized.") + .minLength(100) + .required(true), + integer(FORMAT) + .label("Format") + .description("In what format do you wish the text summarized?") + .options( + option("A structured summary with sections", 0), + option("A brief title summarizing the content in 4-7 words", 1), + option("A single, concise sentence", 2), + option("A bulleted list recap", 3), + option("Custom Prompt", 4)) + .required(true), + string(PROMPT) + .label("Custom Prompt") + .description("Write your prompt for summarizing text.") + .displayCondition("format == 4") + .required(true), + MAX_TOKENS_PROPERTY, + TEMPERATURE_PROPERTY) + .output(), + component); + } +} diff --git a/server/libs/modules/components/ai/ai-text-analysis/src/main/java/com/bytechef/component/ai/text/analysis/action/definition/AiTextAnalysisActionDefinition.java b/server/libs/modules/components/ai/ai-text-analysis/src/main/java/com/bytechef/component/ai/text/analysis/action/definition/AiTextAnalysisActionDefinition.java new file mode 100644 index 00000000000..c60bea200c1 --- /dev/null +++ b/server/libs/modules/components/ai/ai-text-analysis/src/main/java/com/bytechef/component/ai/text/analysis/action/definition/AiTextAnalysisActionDefinition.java @@ -0,0 +1,190 @@ +/* + * 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.definition; + +import static com.bytechef.component.ai.text.analysis.constant.AiTextAnalysisConstants.FORMAT; +import static com.bytechef.component.ai.text.analysis.constant.AiTextAnalysisConstants.MODEL_PROVIDER; +import static com.bytechef.component.ai.text.analysis.constant.AiTextAnalysisConstants.TEXT; +import static com.bytechef.component.definition.Authorization.TOKEN; +import static com.bytechef.component.llm.constant.LLMConstants.MODEL; + +import com.bytechef.component.amazon.bedrock.action.AmazonBedrockAnthropic2ChatAction; +import com.bytechef.component.amazon.bedrock.action.AmazonBedrockAnthropic3ChatAction; +import com.bytechef.component.amazon.bedrock.action.AmazonBedrockCohereChatAction; +import com.bytechef.component.amazon.bedrock.action.AmazonBedrockJurassic2ChatAction; +import com.bytechef.component.amazon.bedrock.action.AmazonBedrockLlamaChatAction; +import com.bytechef.component.amazon.bedrock.action.AmazonBedrockTitanChatAction; +import com.bytechef.component.anthropic.action.AnthropicChatAction; +import com.bytechef.component.azure.openai.action.AzureOpenAIChatAction; +import com.bytechef.component.definition.ActionContext; +import com.bytechef.component.definition.ActionDefinition; +import com.bytechef.component.definition.Parameters; +import com.bytechef.component.groq.action.GroqChatAction; +import com.bytechef.component.hugging.face.action.HuggingFaceChatAction; +import com.bytechef.component.llm.Chat; +import com.bytechef.component.mistral.action.MistralChatAction; +import com.bytechef.component.nvidia.action.NVIDIAChatAction; +import com.bytechef.component.openai.action.OpenAIChatAction; +import com.bytechef.component.vertex.gemini.action.VertexGeminiChatAction; +import com.bytechef.config.ApplicationProperties; +import com.bytechef.platform.component.definition.AbstractActionDefinitionWrapper; +import com.bytechef.platform.component.definition.ParametersFactory; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +/** + * @author Marko Kriskovic + */ +public class AiTextAnalysisActionDefinition extends AbstractActionDefinitionWrapper { + + private final ApplicationProperties.Ai.Component component; + + @SuppressFBWarnings("EI") + public AiTextAnalysisActionDefinition(ActionDefinition actionDefinition, + ApplicationProperties.Ai.Component component) { + super(actionDefinition); + + this.component = component; + } + + @Override + public Optional getPerform() { + return Optional.of((SingleConnectionPerformFunction) this::perform); + } + + protected String perform( + Parameters inputParameters, Parameters connectionParameter, ActionContext context) { + + Map modelConnectionParametersMap = new HashMap<>(); + + Chat chat = switch (inputParameters.getRequiredInteger(MODEL_PROVIDER)) { + case 0 -> { + modelConnectionParametersMap.put(TOKEN, component.getAmazonBedrock() + .getApiKey()); + + yield AmazonBedrockAnthropic2ChatAction.CHAT; + } + case 1 -> { + modelConnectionParametersMap.put(TOKEN, component.getAmazonBedrock() + .getApiKey()); + + yield AmazonBedrockAnthropic3ChatAction.CHAT; + } + case 2 -> { + modelConnectionParametersMap.put(TOKEN, component.getAmazonBedrock() + .getApiKey()); + + yield AmazonBedrockCohereChatAction.CHAT; + } + case 3 -> { + modelConnectionParametersMap.put(TOKEN, component.getAmazonBedrock() + .getApiKey()); + + yield AmazonBedrockJurassic2ChatAction.CHAT; + } + case 4 -> { + modelConnectionParametersMap.put(TOKEN, component.getAmazonBedrock() + .getApiKey()); + + yield AmazonBedrockLlamaChatAction.CHAT; + } + case 5 -> { + modelConnectionParametersMap.put(TOKEN, component.getAmazonBedrock() + .getApiKey()); + + yield AmazonBedrockTitanChatAction.CHAT; + } + case 6 -> { + modelConnectionParametersMap.put(TOKEN, component.getAnthropic() + .getApiKey()); + + yield AnthropicChatAction.CHAT; + } + case 7 -> { + modelConnectionParametersMap.put(TOKEN, component.getAzureOpenAi() + .getApiKey()); + + yield AzureOpenAIChatAction.CHAT; + } + case 8 -> { + modelConnectionParametersMap.put(TOKEN, component.getGroq() + .getApiKey()); + + yield GroqChatAction.CHAT; + } + case 9 -> { + modelConnectionParametersMap.put(TOKEN, component.getNvidia() + .getApiKey()); + + yield NVIDIAChatAction.CHAT; + } + case 10 -> { + modelConnectionParametersMap.put(TOKEN, component.getHuggingFace() + .getApiKey()); + + yield HuggingFaceChatAction.CHAT; + } + case 11 -> { + modelConnectionParametersMap.put(TOKEN, component.getMistral() + .getApiKey()); + + yield MistralChatAction.CHAT; + } + case 12 -> { + modelConnectionParametersMap.put(TOKEN, component.getOpenAi() + .getApiKey()); + + yield OpenAIChatAction.CHAT; + } + case 13 -> { + modelConnectionParametersMap.put(TOKEN, component.getVertexGemini() + .getApiKey()); + + yield VertexGeminiChatAction.CHAT; + } + default -> throw new IllegalArgumentException("Invalid connection provider"); + }; + + Parameters modelConnectionParameters = ParametersFactory.createParameters(modelConnectionParametersMap); + + Map modelInputParametersMap = new HashMap<>(); + + String prompt = switch (inputParameters.getRequiredInteger(FORMAT)) { + case 0 -> "You will receive a text. Make a structured summary of that text with sections."; + case 1 -> "You will receive a text. Make a brief title summarizing the content in 4-7 words."; + case 2 -> "You will receive a text. Summarize it in a single, concise sentence."; + case 3 -> "You will receive a text. Create a bullet list recap."; + case 4 -> "You will receive a text." + inputParameters.getString("prompt"); + default -> throw new IllegalArgumentException("Invalid format"); + }; + + modelInputParametersMap.put("messages", + List.of( + Map.of("content", prompt, "role", "system"), + Map.of("content", inputParameters.getString(TEXT), "role", "user"))); + modelInputParametersMap.put("model", inputParameters.getString(MODEL)); + + Parameters modelInputParameters = ParametersFactory.createParameters(modelInputParametersMap); + + Object response = chat.getResponse(modelInputParameters, modelConnectionParameters, context); + + return response.toString(); + } +} diff --git a/server/libs/modules/components/ai/ai-text-analysis/src/main/java/com/bytechef/component/ai/text/analysis/constant/AiTextAnalysisConstants.java b/server/libs/modules/components/ai/ai-text-analysis/src/main/java/com/bytechef/component/ai/text/analysis/constant/AiTextAnalysisConstants.java new file mode 100644 index 00000000000..7a73d0f1eb5 --- /dev/null +++ b/server/libs/modules/components/ai/ai-text-analysis/src/main/java/com/bytechef/component/ai/text/analysis/constant/AiTextAnalysisConstants.java @@ -0,0 +1,31 @@ +/* + * 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.constant; +/** + * @author Marko Krišković + */ +public class AiTextAnalysisConstants { + + public static final String TEXT = "text"; + public static final String FORMAT = "format"; + public static final String PROMPT = "prompt"; + public static final String MODEL_PROVIDER = "modelProvider"; + public static final String SUMMARIZE_TEXT = "summarizeText"; + + private AiTextAnalysisConstants() { + } +} diff --git a/server/libs/modules/components/ai/ai-text-analysis/src/main/java/com/bytechef/component/ai/text/analysis/task/handler/AiTextAnalysisSummarizeTextTaskHandler.java b/server/libs/modules/components/ai/ai-text-analysis/src/main/java/com/bytechef/component/ai/text/analysis/task/handler/AiTextAnalysisSummarizeTextTaskHandler.java new file mode 100644 index 00000000000..cc01cf0dcde --- /dev/null +++ b/server/libs/modules/components/ai/ai-text-analysis/src/main/java/com/bytechef/component/ai/text/analysis/task/handler/AiTextAnalysisSummarizeTextTaskHandler.java @@ -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.SUMMARIZE_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/" + SUMMARIZE_TEXT) +public class AiTextAnalysisSummarizeTextTaskHandler extends AbstractTaskHandler { + + public AiTextAnalysisSummarizeTextTaskHandler(ActionDefinitionFacade actionDefinitionFacade) { + super(AI_TEXT_ANALYSIS, 1, SUMMARIZE_TEXT, actionDefinitionFacade); + } +} diff --git a/server/libs/modules/components/ai/ai-text-analysis/src/main/resources/assets/ai-text-analysis.svg b/server/libs/modules/components/ai/ai-text-analysis/src/main/resources/assets/ai-text-analysis.svg new file mode 100644 index 00000000000..35ce4d0eae7 --- /dev/null +++ b/server/libs/modules/components/ai/ai-text-analysis/src/main/resources/assets/ai-text-analysis.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/server/libs/modules/components/ai/ai-text-analysis/src/test/java/com/bytechef/component/ai/text/analysis/AiTextAnalysisComponentHandlerTest.java b/server/libs/modules/components/ai/ai-text-analysis/src/test/java/com/bytechef/component/ai/text/analysis/AiTextAnalysisComponentHandlerTest.java new file mode 100644 index 00000000000..45dff34fcd3 --- /dev/null +++ b/server/libs/modules/components/ai/ai-text-analysis/src/test/java/com/bytechef/component/ai/text/analysis/AiTextAnalysisComponentHandlerTest.java @@ -0,0 +1,34 @@ +/* + * 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; + +import com.bytechef.config.ApplicationProperties; +import com.bytechef.test.jsonasssert.JsonFileAssert; +import org.junit.jupiter.api.Test; + +/** + * @author Marko Krišković + */ +class AiTextAnalysisComponentHandlerTest { + + @Test + void testGetComponentDefinition() { + JsonFileAssert.assertEquals( + "definition/ai_text_analysis_v1.json", + new AiTextAnalysisComponentHandler(new ApplicationProperties()).getDefinition()); + } +} diff --git a/server/libs/modules/components/ai/ai-text-analysis/src/test/resources/definition/ai_text_analysis_v1.json b/server/libs/modules/components/ai/ai-text-analysis/src/test/resources/definition/ai_text_analysis_v1.json new file mode 100644 index 00000000000..33cd26a9193 --- /dev/null +++ b/server/libs/modules/components/ai/ai-text-analysis/src/test/resources/definition/ai_text_analysis_v1.json @@ -0,0 +1,702 @@ +{ + "actions" : [ { + "batch" : null, + "deprecated" : null, + "description" : "AI reads, analyzes and summarizes your text into a shorter format.", + "help" : null, + "metadata" : null, + "name" : "summarizeText", + "properties" : [ { + "advancedOption" : null, + "description" : null, + "displayCondition" : null, + "expressionEnabled" : null, + "hidden" : null, + "metadata" : { }, + "required" : true, + "name" : "modelProvider", + "type" : "INTEGER", + "defaultValue" : null, + "exampleValue" : null, + "label" : "Model provider", + "placeholder" : null, + "maxValue" : null, + "minValue" : null, + "options" : [ { + "description" : null, + "label" : "Amazon Bedrock: Anthropic 2", + "value" : 0 + }, { + "description" : null, + "label" : "Amazon Bedrock: Anthropic 3", + "value" : 1 + }, { + "description" : null, + "label" : "Amazon Bedrock: Cohere", + "value" : 2 + }, { + "description" : null, + "label" : "Amazon Bedrock: Jurassic 2", + "value" : 3 + }, { + "description" : null, + "label" : "Amazon Bedrock: Llama", + "value" : 4 + }, { + "description" : null, + "label" : "Amazon Bedrock: Titan", + "value" : 5 + }, { + "description" : null, + "label" : "Anthropic", + "value" : 6 + }, { + "description" : null, + "label" : "Azure Open AI", + "value" : 7 + }, { + "description" : null, + "label" : "Groq", + "value" : 8 + }, { + "description" : null, + "label" : "NVIDIA", + "value" : 9 + }, { + "description" : null, + "label" : "Hugging Face", + "value" : 10 + }, { + "description" : null, + "label" : "Mistral", + "value" : 11 + }, { + "description" : null, + "label" : "Open AI", + "value" : 12 + }, { + "description" : null, + "label" : "Vertex Gemini", + "value" : 13 + } ], + "controlType" : "SELECT", + "optionsDataSource" : null + }, { + "advancedOption" : null, + "description" : "ID of the model to use.", + "displayCondition" : "modelProvider == 0", + "expressionEnabled" : null, + "hidden" : null, + "metadata" : { }, + "required" : true, + "name" : "model", + "type" : "STRING", + "defaultValue" : null, + "exampleValue" : null, + "label" : "Model", + "placeholder" : null, + "controlType" : "SELECT", + "languageId" : null, + "maxLength" : null, + "minLength" : null, + "options" : [ { + "description" : null, + "label" : "anthropic.claude-instant-v1", + "value" : "anthropic.claude-instant-v1" + }, { + "description" : null, + "label" : "anthropic.claude-v2:1", + "value" : "anthropic.claude-v2:1" + }, { + "description" : null, + "label" : "anthropic.claude-v2", + "value" : "anthropic.claude-v2" + } ], + "optionsDataSource" : null + }, { + "advancedOption" : null, + "description" : "ID of the model to use.", + "displayCondition" : "modelProvider == 1", + "expressionEnabled" : null, + "hidden" : null, + "metadata" : { }, + "required" : true, + "name" : "model", + "type" : "STRING", + "defaultValue" : null, + "exampleValue" : null, + "label" : "Model", + "placeholder" : null, + "controlType" : "SELECT", + "languageId" : null, + "maxLength" : null, + "minLength" : null, + "options" : [ { + "description" : null, + "label" : "anthropic.claude-instant-v1", + "value" : "anthropic.claude-instant-v1" + }, { + "description" : null, + "label" : "anthropic.claude-v2:1", + "value" : "anthropic.claude-v2:1" + }, { + "description" : null, + "label" : "anthropic.claude-v2", + "value" : "anthropic.claude-v2" + } ], + "optionsDataSource" : null + }, { + "advancedOption" : null, + "description" : "ID of the model to use.", + "displayCondition" : "modelProvider == 2", + "expressionEnabled" : null, + "hidden" : null, + "metadata" : { }, + "required" : true, + "name" : "model", + "type" : "STRING", + "defaultValue" : null, + "exampleValue" : null, + "label" : "Model", + "placeholder" : null, + "controlType" : "SELECT", + "languageId" : null, + "maxLength" : null, + "minLength" : null, + "options" : [ { + "description" : null, + "label" : "cohere.command-light-text-v14", + "value" : "cohere.command-light-text-v14" + }, { + "description" : null, + "label" : "cohere.command-text-v14", + "value" : "cohere.command-text-v14" + } ], + "optionsDataSource" : null + }, { + "advancedOption" : null, + "description" : "ID of the model to use.", + "displayCondition" : "modelProvider == 3", + "expressionEnabled" : null, + "hidden" : null, + "metadata" : { }, + "required" : true, + "name" : "model", + "type" : "STRING", + "defaultValue" : null, + "exampleValue" : null, + "label" : "Model", + "placeholder" : null, + "controlType" : "SELECT", + "languageId" : null, + "maxLength" : null, + "minLength" : null, + "options" : [ { + "description" : null, + "label" : "ai21.j2-ultra-v1", + "value" : "ai21.j2-ultra-v1" + }, { + "description" : null, + "label" : "ai21.j2-mid-v1", + "value" : "ai21.j2-mid-v1" + } ], + "optionsDataSource" : null + }, { + "advancedOption" : null, + "description" : "ID of the model to use.", + "displayCondition" : "modelProvider == 4", + "expressionEnabled" : null, + "hidden" : null, + "metadata" : { }, + "required" : true, + "name" : "model", + "type" : "STRING", + "defaultValue" : null, + "exampleValue" : null, + "label" : "Model", + "placeholder" : null, + "controlType" : "SELECT", + "languageId" : null, + "maxLength" : null, + "minLength" : null, + "options" : [ { + "description" : null, + "label" : "meta.llama2-13b-chat-v1", + "value" : "meta.llama2-13b-chat-v1" + }, { + "description" : null, + "label" : "meta.llama3-1-8b-instruct-v1:0", + "value" : "meta.llama3-1-8b-instruct-v1:0" + }, { + "description" : null, + "label" : "meta.llama3-2-11b-instruct-v1:0", + "value" : "meta.llama3-2-11b-instruct-v1:0" + }, { + "description" : null, + "label" : "meta.llama3-1-70b-instruct-v1:0", + "value" : "meta.llama3-1-70b-instruct-v1:0" + }, { + "description" : null, + "label" : "meta.llama3-70b-instruct-v1:0", + "value" : "meta.llama3-70b-instruct-v1:0" + }, { + "description" : null, + "label" : "meta.llama3-8b-instruct-v1:0", + "value" : "meta.llama3-8b-instruct-v1:0" + }, { + "description" : null, + "label" : "meta.llama3-2-90b-instruct-v1:0", + "value" : "meta.llama3-2-90b-instruct-v1:0" + }, { + "description" : null, + "label" : "meta.llama2-70b-chat-v1", + "value" : "meta.llama2-70b-chat-v1" + }, { + "description" : null, + "label" : "meta.llama3-2-1b-instruct-v1:0", + "value" : "meta.llama3-2-1b-instruct-v1:0" + }, { + "description" : null, + "label" : "meta.llama3-2-3b-instruct-v1:0", + "value" : "meta.llama3-2-3b-instruct-v1:0" + }, { + "description" : null, + "label" : "meta.llama3-1-405b-instruct-v1:0", + "value" : "meta.llama3-1-405b-instruct-v1:0" + } ], + "optionsDataSource" : null + }, { + "advancedOption" : null, + "description" : "ID of the model to use.", + "displayCondition" : "modelProvider == 5", + "expressionEnabled" : null, + "hidden" : null, + "metadata" : { }, + "required" : true, + "name" : "model", + "type" : "STRING", + "defaultValue" : null, + "exampleValue" : null, + "label" : "Model", + "placeholder" : null, + "controlType" : "SELECT", + "languageId" : null, + "maxLength" : null, + "minLength" : null, + "options" : [ { + "description" : null, + "label" : "amazon.titan-text-premier-v1:0", + "value" : "amazon.titan-text-premier-v1:0" + }, { + "description" : null, + "label" : "amazon.titan-text-express-v1", + "value" : "amazon.titan-text-express-v1" + }, { + "description" : null, + "label" : "amazon.titan-text-lite-v1", + "value" : "amazon.titan-text-lite-v1" + } ], + "optionsDataSource" : null + }, { + "advancedOption" : null, + "description" : "ID of the model to use.", + "displayCondition" : "modelProvider == 6", + "expressionEnabled" : null, + "hidden" : null, + "metadata" : { }, + "required" : true, + "name" : "model", + "type" : "STRING", + "defaultValue" : null, + "exampleValue" : null, + "label" : "Model", + "placeholder" : null, + "controlType" : "SELECT", + "languageId" : null, + "maxLength" : null, + "minLength" : null, + "options" : [ { + "description" : null, + "label" : "claude-instant-1.2", + "value" : "claude-instant-1.2" + }, { + "description" : null, + "label" : "claude-3-haiku-20240307", + "value" : "claude-3-haiku-20240307" + }, { + "description" : null, + "label" : "claude-3-opus-20240229", + "value" : "claude-3-opus-20240229" + }, { + "description" : null, + "label" : "claude-2.0", + "value" : "claude-2.0" + }, { + "description" : null, + "label" : "claude-3-5-sonnet-20241022", + "value" : "claude-3-5-sonnet-20241022" + }, { + "description" : null, + "label" : "claude-3-sonnet-20240229", + "value" : "claude-3-sonnet-20240229" + }, { + "description" : null, + "label" : "claude-2.1", + "value" : "claude-2.1" + } ], + "optionsDataSource" : null + }, { + "advancedOption" : null, + "description" : "ID of the model to use.", + "displayCondition" : "modelProvider >= 7 && modelProvider <= 9", + "expressionEnabled" : null, + "hidden" : null, + "metadata" : { }, + "required" : true, + "name" : "model", + "type" : "STRING", + "defaultValue" : null, + "exampleValue" : null, + "label" : "Model", + "placeholder" : null, + "controlType" : "TEXT", + "languageId" : null, + "maxLength" : null, + "minLength" : null, + "options" : null, + "optionsDataSource" : null + }, { + "advancedOption" : null, + "description" : "Url of the inference endpoint.", + "displayCondition" : "modelProvider == 10", + "expressionEnabled" : null, + "hidden" : null, + "metadata" : { }, + "required" : true, + "name" : "model", + "type" : "STRING", + "defaultValue" : null, + "exampleValue" : null, + "label" : "URL", + "placeholder" : null, + "controlType" : "TEXT", + "languageId" : null, + "maxLength" : null, + "minLength" : null, + "options" : null, + "optionsDataSource" : null + }, { + "advancedOption" : null, + "description" : "ID of the model to use.", + "displayCondition" : "modelProvider == 11", + "expressionEnabled" : null, + "hidden" : null, + "metadata" : { }, + "required" : true, + "name" : "model", + "type" : "STRING", + "defaultValue" : null, + "exampleValue" : null, + "label" : "Model", + "placeholder" : null, + "controlType" : "SELECT", + "languageId" : null, + "maxLength" : null, + "minLength" : null, + "options" : [ { + "description" : null, + "label" : "open-mixtral-8x22b", + "value" : "open-mixtral-8x22b" + }, { + "description" : null, + "label" : "pixtral-12b-2409", + "value" : "pixtral-12b-2409" + }, { + "description" : null, + "label" : "mistral-small-latest", + "value" : "mistral-small-latest" + }, { + "description" : null, + "label" : "pixtral-large-latest", + "value" : "pixtral-large-latest" + }, { + "description" : null, + "label" : "open-mixtral-8x7b", + "value" : "open-mixtral-8x7b" + }, { + "description" : null, + "label" : "mistral-medium-latest", + "value" : "mistral-medium-latest" + }, { + "description" : null, + "label" : "open-mistral-7b", + "value" : "open-mistral-7b" + }, { + "description" : null, + "label" : "mistral-large-latest", + "value" : "mistral-large-latest" + } ], + "optionsDataSource" : null + }, { + "advancedOption" : null, + "description" : "ID of the model to use.", + "displayCondition" : "modelProvider == 12", + "expressionEnabled" : null, + "hidden" : null, + "metadata" : { }, + "required" : true, + "name" : "model", + "type" : "STRING", + "defaultValue" : null, + "exampleValue" : null, + "label" : "Model", + "placeholder" : null, + "controlType" : "SELECT", + "languageId" : null, + "maxLength" : null, + "minLength" : null, + "options" : [ { + "description" : null, + "label" : "gpt-4-0125-preview", + "value" : "gpt-4-0125-preview" + }, { + "description" : null, + "label" : "o1-preview-2024-09-12", + "value" : "o1-preview-2024-09-12" + }, { + "description" : null, + "label" : "gpt-4-turbo-preview", + "value" : "gpt-4-turbo-preview" + }, { + "description" : null, + "label" : "gpt-4-turbo", + "value" : "gpt-4-turbo" + }, { + "description" : null, + "label" : "gpt-4o-mini", + "value" : "gpt-4o-mini" + }, { + "description" : null, + "label" : "gpt-4", + "value" : "gpt-4" + }, { + "description" : null, + "label" : "o1-preview", + "value" : "o1-preview" + }, { + "description" : null, + "label" : "gpt-3.5-turbo", + "value" : "gpt-3.5-turbo" + }, { + "description" : null, + "label" : "gpt-4-turbo-2024-04-09", + "value" : "gpt-4-turbo-2024-04-09" + }, { + "description" : null, + "label" : "gpt-3.5-turbo-0125", + "value" : "gpt-3.5-turbo-0125" + }, { + "description" : null, + "label" : "o1-mini", + "value" : "o1-mini" + }, { + "description" : null, + "label" : "o1-mini-2024-09-12", + "value" : "o1-mini-2024-09-12" + }, { + "description" : null, + "label" : "gpt-3.5-turbo-1106", + "value" : "gpt-3.5-turbo-1106" + }, { + "description" : null, + "label" : "gpt-4o", + "value" : "gpt-4o" + } ], + "optionsDataSource" : null + }, { + "advancedOption" : null, + "description" : "ID of the model to use.", + "displayCondition" : "modelProvider == 13", + "expressionEnabled" : null, + "hidden" : null, + "metadata" : { }, + "required" : true, + "name" : "model", + "type" : "STRING", + "defaultValue" : null, + "exampleValue" : null, + "label" : "Model", + "placeholder" : null, + "controlType" : "SELECT", + "languageId" : null, + "maxLength" : null, + "minLength" : null, + "options" : [ { + "description" : null, + "label" : "gemini-1.5-flash-001", + "value" : "gemini-1.5-flash-001" + }, { + "description" : null, + "label" : "gemini-pro-vision", + "value" : "gemini-pro-vision" + }, { + "description" : null, + "label" : "gemini-1.5-pro-001", + "value" : "gemini-1.5-pro-001" + }, { + "description" : null, + "label" : "gemini-pro", + "value" : "gemini-pro" + } ], + "optionsDataSource" : null + }, { + "advancedOption" : null, + "description" : "The text that is to be summarized.", + "displayCondition" : null, + "expressionEnabled" : null, + "hidden" : null, + "metadata" : { }, + "required" : true, + "name" : "text", + "type" : "STRING", + "defaultValue" : null, + "exampleValue" : null, + "label" : "Text", + "placeholder" : null, + "controlType" : "TEXT", + "languageId" : null, + "maxLength" : null, + "minLength" : 100, + "options" : null, + "optionsDataSource" : null + }, { + "advancedOption" : null, + "description" : "In what format do you wish the text summarized?", + "displayCondition" : null, + "expressionEnabled" : null, + "hidden" : null, + "metadata" : { }, + "required" : true, + "name" : "format", + "type" : "INTEGER", + "defaultValue" : null, + "exampleValue" : null, + "label" : "Format", + "placeholder" : null, + "maxValue" : null, + "minValue" : null, + "options" : [ { + "description" : null, + "label" : "A structured summary with sections", + "value" : 0 + }, { + "description" : null, + "label" : "A brief title summarizing the content in 4-7 words", + "value" : 1 + }, { + "description" : null, + "label" : "A single, concise sentence", + "value" : 2 + }, { + "description" : null, + "label" : "A bulleted list recap", + "value" : 3 + }, { + "description" : null, + "label" : "Custom Prompt", + "value" : 4 + } ], + "controlType" : "SELECT", + "optionsDataSource" : null + }, { + "advancedOption" : null, + "description" : "Write your prompt for summarizing text.", + "displayCondition" : "format == 4", + "expressionEnabled" : null, + "hidden" : null, + "metadata" : { }, + "required" : true, + "name" : "prompt", + "type" : "STRING", + "defaultValue" : null, + "exampleValue" : null, + "label" : "Custom Prompt", + "placeholder" : null, + "controlType" : "TEXT", + "languageId" : null, + "maxLength" : null, + "minLength" : null, + "options" : null, + "optionsDataSource" : null + }, { + "advancedOption" : true, + "description" : "The maximum number of tokens to generate in the chat completion.", + "displayCondition" : null, + "expressionEnabled" : null, + "hidden" : null, + "metadata" : { }, + "required" : null, + "name" : "maxTokens", + "type" : "INTEGER", + "defaultValue" : null, + "exampleValue" : null, + "label" : "Max Tokens", + "placeholder" : null, + "maxValue" : null, + "minValue" : null, + "options" : null, + "controlType" : "INTEGER", + "optionsDataSource" : null + }, { + "advancedOption" : true, + "description" : "Controls randomness: Higher values will make the output more random, while lower values like will make it more focused and deterministic.", + "displayCondition" : null, + "expressionEnabled" : null, + "hidden" : null, + "metadata" : { }, + "required" : null, + "name" : "temperature", + "type" : "NUMBER", + "defaultValue" : 1.0, + "exampleValue" : null, + "label" : "Temperature", + "placeholder" : null, + "maxNumberPrecision" : null, + "maxValue" : 2.0, + "minNumberPrecision" : null, + "minValue" : 0.0, + "numberPrecision" : null, + "options" : null, + "controlType" : "NUMBER", + "optionsDataSource" : null + } ], + "title" : "Summarize Text", + "perform" : { }, + "processErrorResponse" : null, + "outputDefinition" : { + "output" : null, + "outputResponse" : null, + "outputSchema" : null, + "sampleOutput" : null + }, + "workflowNodeDescription" : null + } ], + "categories" : [ { + "key" : "artificial-intelligence", + "label" : "artificial-intelligence" + } ], + "connection" : null, + "customAction" : null, + "customActionHelp" : null, + "description" : "AI Helper component for text analysis.", + "icon" : "path:assets/ai-text-analysis.svg", + "tags" : null, + "metadata" : null, + "name" : "aiTextAnalysis", + "resources" : null, + "title" : "AI Text Analysis", + "triggers" : null, + "unifiedApi" : null, + "version" : 1, + "dataStream" : null +} \ No newline at end of file diff --git a/server/libs/modules/components/code-workflow/src/main/java/com/bytechef/component/codeworkflow/action/CodeWorkflowPerformAction.java b/server/libs/modules/components/code-workflow/src/main/java/com/bytechef/component/codeworkflow/action/CodeWorkflowPerformAction.java index a67dfc5c273..ce2dc636a32 100644 --- a/server/libs/modules/components/code-workflow/src/main/java/com/bytechef/component/codeworkflow/action/CodeWorkflowPerformAction.java +++ b/server/libs/modules/components/code-workflow/src/main/java/com/bytechef/component/codeworkflow/action/CodeWorkflowPerformAction.java @@ -21,17 +21,8 @@ import static com.bytechef.component.definition.ComponentDsl.integer; import static com.bytechef.component.definition.ComponentDsl.string; +import com.bytechef.component.codeworkflow.action.definition.CodeWorkflowPerformActionDefinition; import com.bytechef.component.codeworkflow.task.CodeWorkflowTaskExecutor; -import com.bytechef.component.definition.ActionContext; -import com.bytechef.component.definition.ActionDefinition; -import com.bytechef.component.definition.Parameters; -import com.bytechef.platform.component.constant.MetadataConstants; -import com.bytechef.platform.component.definition.AbstractActionDefinitionWrapper; -import com.bytechef.platform.component.definition.MultipleConnectionsPerformFunction; -import com.bytechef.platform.component.definition.ParameterConnection; -import com.bytechef.platform.constant.ModeType; -import java.util.Map; -import java.util.Optional; /** * @author Ivica Cardic @@ -54,31 +45,4 @@ public CodeWorkflowPerformAction(CodeWorkflowTaskExecutor codeWorkflowTaskExecut .label("Task Name")), codeWorkflowTaskExecutor); } - - public static class CodeWorkflowPerformActionDefinition extends AbstractActionDefinitionWrapper { - - private final CodeWorkflowTaskExecutor codeWorkflowTaskExecutor; - - public CodeWorkflowPerformActionDefinition(ActionDefinition actionDefinition, - CodeWorkflowTaskExecutor codeWorkflowTaskExecutor) { - super(actionDefinition); - - this.codeWorkflowTaskExecutor = codeWorkflowTaskExecutor; - } - - @Override - public Optional getPerform() { - return Optional.of((MultipleConnectionsPerformFunction) this::perform); - } - - protected Object perform( - Parameters inputParameters, Map connectionParameters, - Parameters extensions, ActionContext actionContext) { - - return codeWorkflowTaskExecutor.executePerform( - inputParameters.getRequiredString("codeWorkflowContainerReference"), - inputParameters.getRequiredString("workflowName"), inputParameters.getRequiredString("taskName"), - inputParameters.getRequired(MetadataConstants.TYPE, ModeType.class)); - } - } } diff --git a/server/libs/modules/components/code-workflow/src/main/java/com/bytechef/component/codeworkflow/action/definition/CodeWorkflowPerformActionDefinition.java b/server/libs/modules/components/code-workflow/src/main/java/com/bytechef/component/codeworkflow/action/definition/CodeWorkflowPerformActionDefinition.java new file mode 100644 index 00000000000..768675d12f7 --- /dev/null +++ b/server/libs/modules/components/code-workflow/src/main/java/com/bytechef/component/codeworkflow/action/definition/CodeWorkflowPerformActionDefinition.java @@ -0,0 +1,57 @@ +/* + * 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.codeworkflow.action.definition; + +import com.bytechef.component.codeworkflow.task.CodeWorkflowTaskExecutor; +import com.bytechef.component.definition.ActionContext; +import com.bytechef.component.definition.ActionDefinition; +import com.bytechef.component.definition.Parameters; +import com.bytechef.platform.component.constant.MetadataConstants; +import com.bytechef.platform.component.definition.AbstractActionDefinitionWrapper; +import com.bytechef.platform.component.definition.MultipleConnectionsPerformFunction; +import com.bytechef.platform.component.definition.ParameterConnection; +import com.bytechef.platform.constant.ModeType; +import java.util.Map; +import java.util.Optional; + +public class CodeWorkflowPerformActionDefinition extends AbstractActionDefinitionWrapper { + + private final CodeWorkflowTaskExecutor codeWorkflowTaskExecutor; + + public CodeWorkflowPerformActionDefinition( + ActionDefinition actionDefinition, CodeWorkflowTaskExecutor codeWorkflowTaskExecutor) { + + super(actionDefinition); + + this.codeWorkflowTaskExecutor = codeWorkflowTaskExecutor; + } + + @Override + public Optional getPerform() { + return Optional.of((MultipleConnectionsPerformFunction) this::perform); + } + + protected Object perform( + Parameters inputParameters, Map connectionParameters, + Parameters extensions, ActionContext actionContext) { + + return codeWorkflowTaskExecutor.executePerform( + inputParameters.getRequiredString("codeWorkflowContainerReference"), + inputParameters.getRequiredString("workflowName"), inputParameters.getRequiredString("taskName"), + inputParameters.getRequired(MetadataConstants.TYPE, ModeType.class)); + } +} diff --git a/server/libs/modules/components/data-stream/src/main/java/com/bytechef/component/datastream/action/DataStreamStreamAction.java b/server/libs/modules/components/data-stream/src/main/java/com/bytechef/component/datastream/action/DataStreamStreamAction.java index 7bef0dc4d9f..00694838ce2 100644 --- a/server/libs/modules/components/data-stream/src/main/java/com/bytechef/component/datastream/action/DataStreamStreamAction.java +++ b/server/libs/modules/components/data-stream/src/main/java/com/bytechef/component/datastream/action/DataStreamStreamAction.java @@ -16,38 +16,13 @@ package com.bytechef.component.datastream.action; -import static com.bytechef.component.datastream.constant.DataStreamConstants.CONNECTION_PARAMETERS; -import static com.bytechef.component.datastream.constant.DataStreamConstants.DESTINATION; -import static com.bytechef.component.datastream.constant.DataStreamConstants.DEV_ENVIRONMENT; -import static com.bytechef.component.datastream.constant.DataStreamConstants.INPUT_PARAMETERS; -import static com.bytechef.component.datastream.constant.DataStreamConstants.INSTANCE_ID; -import static com.bytechef.component.datastream.constant.DataStreamConstants.INSTANCE_WORKFLOW_ID; -import static com.bytechef.component.datastream.constant.DataStreamConstants.JOB_ID; -import static com.bytechef.component.datastream.constant.DataStreamConstants.SOURCE; import static com.bytechef.component.datastream.constant.DataStreamConstants.STREAM; -import static com.bytechef.component.datastream.constant.DataStreamConstants.TENANT_ID; -import static com.bytechef.component.datastream.constant.DataStreamConstants.TYPE; import static com.bytechef.component.definition.ComponentDsl.action; import static com.bytechef.component.definition.ComponentDsl.integer; import static com.bytechef.component.definition.ComponentDsl.option; -import com.bytechef.component.definition.ActionContext; -import com.bytechef.component.definition.ActionDefinition; -import com.bytechef.component.definition.Parameters; -import com.bytechef.platform.component.definition.AbstractActionDefinitionWrapper; -import com.bytechef.platform.component.definition.ActionContextAware; -import com.bytechef.platform.component.definition.MultipleConnectionsPerformFunction; -import com.bytechef.platform.component.definition.ParameterConnection; -import com.bytechef.platform.tenant.TenantContext; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.stream.Collectors; +import com.bytechef.component.datastream.action.definition.SyncActionDefinition; import org.springframework.batch.core.Job; -import org.springframework.batch.core.JobExecution; -import org.springframework.batch.core.JobParameter; -import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.launch.JobLauncher; /** @@ -73,75 +48,4 @@ public DataStreamStreamAction(Job job, JobLauncher jobLauncher) { job, jobLauncher); } - public static class SyncActionDefinition extends AbstractActionDefinitionWrapper { - - private final Job job; - private final JobLauncher jobLauncher; - - public SyncActionDefinition(ActionDefinition actionDefinition, Job job, JobLauncher jobLauncher) { - super(actionDefinition); - - this.job = job; - this.jobLauncher = jobLauncher; - } - - @Override - public Optional getPerform() { - return Optional.of((MultipleConnectionsPerformFunction) this::perform); - } - - protected Object perform( - Parameters inputParameters, Map connectionParameters, - Parameters extensions, ActionContext actionContext) throws Exception { - - ActionContextAware actionContextAware = (ActionContextAware) actionContext; - - JobParameters jobParameters = new JobParameters( - new HashMap<>() { - { - put(CONNECTION_PARAMETERS, new JobParameter<>(connectionParameters, Map.class)); - put(DESTINATION, new JobParameter<>(extensions.getMap(DESTINATION), Map.class)); - put(INPUT_PARAMETERS, new JobParameter<>(inputParameters, Map.class)); - - if (actionContextAware.getInstanceId() != null) { - put(INSTANCE_ID, new JobParameter<>(actionContextAware.getInstanceId(), Long.class)); - } - - if (actionContextAware.getInstanceWorkflowId() != null) { - put( - INSTANCE_WORKFLOW_ID, - new JobParameter<>(actionContextAware.getInstanceWorkflowId(), Long.class)); - } - - put(JOB_ID, new JobParameter<>(actionContextAware.getJobId(), Long.class)); - put(SOURCE, new JobParameter<>(extensions.getMap(SOURCE), Map.class)); - put(TENANT_ID, new JobParameter<>(TenantContext.getCurrentTenantId(), String.class)); - put( - DEV_ENVIRONMENT, - new JobParameter<>(actionContextAware.isDevEnvironment(), Boolean.class)); - - if (actionContextAware.getType() != null) { - put(TYPE, new JobParameter<>(String.valueOf(actionContextAware.getType()), String.class)); - } - } - }); - - JobExecution jobExecution = jobLauncher.run(job, jobParameters); - - List failureExceptions = jobExecution.getFailureExceptions(); - - if (!failureExceptions.isEmpty()) { - throw new RuntimeException( - failureExceptions - .stream() - .map(Throwable::getMessage) - .collect(Collectors.joining(","))); - } - - return Map.of( - "endTime", jobExecution.getEndTime(), - "status", jobExecution.getStatus(), - "startTime", jobExecution.getStartTime()); - } - } } diff --git a/server/libs/modules/components/data-stream/src/main/java/com/bytechef/component/datastream/action/definition/SyncActionDefinition.java b/server/libs/modules/components/data-stream/src/main/java/com/bytechef/component/datastream/action/definition/SyncActionDefinition.java new file mode 100644 index 00000000000..3feec0b45f3 --- /dev/null +++ b/server/libs/modules/components/data-stream/src/main/java/com/bytechef/component/datastream/action/definition/SyncActionDefinition.java @@ -0,0 +1,119 @@ +/* + * 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.datastream.action.definition; + +import static com.bytechef.component.datastream.constant.DataStreamConstants.CONNECTION_PARAMETERS; +import static com.bytechef.component.datastream.constant.DataStreamConstants.DESTINATION; +import static com.bytechef.component.datastream.constant.DataStreamConstants.DEV_ENVIRONMENT; +import static com.bytechef.component.datastream.constant.DataStreamConstants.INPUT_PARAMETERS; +import static com.bytechef.component.datastream.constant.DataStreamConstants.INSTANCE_ID; +import static com.bytechef.component.datastream.constant.DataStreamConstants.INSTANCE_WORKFLOW_ID; +import static com.bytechef.component.datastream.constant.DataStreamConstants.JOB_ID; +import static com.bytechef.component.datastream.constant.DataStreamConstants.SOURCE; +import static com.bytechef.component.datastream.constant.DataStreamConstants.TENANT_ID; +import static com.bytechef.component.datastream.constant.DataStreamConstants.TYPE; + +import com.bytechef.component.definition.ActionContext; +import com.bytechef.component.definition.ActionDefinition; +import com.bytechef.component.definition.Parameters; +import com.bytechef.platform.component.definition.AbstractActionDefinitionWrapper; +import com.bytechef.platform.component.definition.ActionContextAware; +import com.bytechef.platform.component.definition.MultipleConnectionsPerformFunction; +import com.bytechef.platform.component.definition.ParameterConnection; +import com.bytechef.platform.tenant.TenantContext; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; +import org.springframework.batch.core.Job; +import org.springframework.batch.core.JobExecution; +import org.springframework.batch.core.JobParameter; +import org.springframework.batch.core.JobParameters; +import org.springframework.batch.core.launch.JobLauncher; + +public class SyncActionDefinition extends AbstractActionDefinitionWrapper { + + private final Job job; + private final JobLauncher jobLauncher; + + public SyncActionDefinition(ActionDefinition actionDefinition, Job job, JobLauncher jobLauncher) { + super(actionDefinition); + + this.job = job; + this.jobLauncher = jobLauncher; + } + + @Override + public Optional getPerform() { + return Optional.of((MultipleConnectionsPerformFunction) this::perform); + } + + protected Object perform( + Parameters inputParameters, Map connectionParameters, + Parameters extensions, ActionContext actionContext) throws Exception { + + ActionContextAware actionContextAware = (ActionContextAware) actionContext; + + JobParameters jobParameters = new JobParameters( + new HashMap<>() { + { + put(CONNECTION_PARAMETERS, new JobParameter<>(connectionParameters, Map.class)); + put(DESTINATION, new JobParameter<>(extensions.getMap(DESTINATION), Map.class)); + put(INPUT_PARAMETERS, new JobParameter<>(inputParameters, Map.class)); + + if (actionContextAware.getInstanceId() != null) { + put(INSTANCE_ID, new JobParameter<>(actionContextAware.getInstanceId(), Long.class)); + } + + if (actionContextAware.getInstanceWorkflowId() != null) { + put( + INSTANCE_WORKFLOW_ID, + new JobParameter<>(actionContextAware.getInstanceWorkflowId(), Long.class)); + } + + put(JOB_ID, new JobParameter<>(actionContextAware.getJobId(), Long.class)); + put(SOURCE, new JobParameter<>(extensions.getMap(SOURCE), Map.class)); + put(TENANT_ID, new JobParameter<>(TenantContext.getCurrentTenantId(), String.class)); + put( + DEV_ENVIRONMENT, + new JobParameter<>(actionContextAware.isDevEnvironment(), Boolean.class)); + + if (actionContextAware.getType() != null) { + put(TYPE, new JobParameter<>(String.valueOf(actionContextAware.getType()), String.class)); + } + } + }); + + JobExecution jobExecution = jobLauncher.run(job, jobParameters); + + List failureExceptions = jobExecution.getFailureExceptions(); + + if (!failureExceptions.isEmpty()) { + throw new RuntimeException( + failureExceptions + .stream() + .map(Throwable::getMessage) + .collect(Collectors.joining(","))); + } + + return Map.of( + "endTime", jobExecution.getEndTime(), + "status", jobExecution.getStatus(), + "startTime", jobExecution.getStartTime()); + } +} diff --git a/server/libs/modules/components/llm/amazon-bedrock/src/main/java/com/bytechef/component/amazon/bedrock/action/AmazonBedrockAnthropic2ChatAction.java b/server/libs/modules/components/llm/amazon-bedrock/src/main/java/com/bytechef/component/amazon/bedrock/action/AmazonBedrockAnthropic2ChatAction.java index ca1f691f106..89df649ef0d 100644 --- a/server/libs/modules/components/llm/amazon-bedrock/src/main/java/com/bytechef/component/amazon/bedrock/action/AmazonBedrockAnthropic2ChatAction.java +++ b/server/libs/modules/components/llm/amazon-bedrock/src/main/java/com/bytechef/component/amazon/bedrock/action/AmazonBedrockAnthropic2ChatAction.java @@ -36,15 +36,13 @@ import static com.bytechef.component.llm.constant.LLMConstants.TOP_P; import static com.bytechef.component.llm.constant.LLMConstants.TOP_P_PROPERTY; +import com.bytechef.component.amazon.bedrock.constant.AmazonBedrockConstants; import com.bytechef.component.definition.ActionContext; import com.bytechef.component.definition.ComponentDsl.ModifiableActionDefinition; import com.bytechef.component.definition.Parameters; import com.bytechef.component.definition.TypeReference; import com.bytechef.component.llm.Chat; -import com.bytechef.component.llm.util.LLMUtils; import com.fasterxml.jackson.databind.ObjectMapper; -import java.util.Arrays; -import java.util.stream.Collectors; import org.springframework.ai.bedrock.anthropic.AnthropicChatOptions; import org.springframework.ai.bedrock.anthropic.BedrockAnthropicChatModel; import org.springframework.ai.bedrock.anthropic.api.AnthropicChatBedrockApi; @@ -65,13 +63,7 @@ public class AmazonBedrockAnthropic2ChatAction { .label("Model") .description("ID of the model to use.") .required(true) - .options( - LLMUtils.getEnumOptions( - Arrays.stream(AnthropicChatBedrockApi.AnthropicChatModel.values()) - .collect( - Collectors.toMap( - AnthropicChatBedrockApi.AnthropicChatModel::getName, - AnthropicChatBedrockApi.AnthropicChatModel::getName, (f, s) -> f)))), + .options(AmazonBedrockConstants.ANTHROPIC2_MODELS), MESSAGES_PROPERTY, integer(MAX_TOKENS) .label("Max Tokens") @@ -89,11 +81,13 @@ public class AmazonBedrockAnthropic2ChatAction { private AmazonBedrockAnthropic2ChatAction() { } - public static Object perform(Parameters inputParameters, Parameters connectionParameters, ActionContext context) { + public static Object perform( + Parameters inputParameters, Parameters connectionParameters, ActionContext context) { + return CHAT.getResponse(inputParameters, connectionParameters, context); } - private static final Chat CHAT = new Chat() { + public static final Chat CHAT = new Chat() { @Override public ChatModel createChatModel(Parameters inputParameters, Parameters connectionParameters) { diff --git a/server/libs/modules/components/llm/amazon-bedrock/src/main/java/com/bytechef/component/amazon/bedrock/action/AmazonBedrockAnthropic3ChatAction.java b/server/libs/modules/components/llm/amazon-bedrock/src/main/java/com/bytechef/component/amazon/bedrock/action/AmazonBedrockAnthropic3ChatAction.java index f6f0e9f671e..b4aa152a5dd 100644 --- a/server/libs/modules/components/llm/amazon-bedrock/src/main/java/com/bytechef/component/amazon/bedrock/action/AmazonBedrockAnthropic3ChatAction.java +++ b/server/libs/modules/components/llm/amazon-bedrock/src/main/java/com/bytechef/component/amazon/bedrock/action/AmazonBedrockAnthropic3ChatAction.java @@ -36,15 +36,13 @@ import static com.bytechef.component.llm.constant.LLMConstants.TOP_P; import static com.bytechef.component.llm.constant.LLMConstants.TOP_P_PROPERTY; +import com.bytechef.component.amazon.bedrock.constant.AmazonBedrockConstants; import com.bytechef.component.definition.ActionContext; import com.bytechef.component.definition.ComponentDsl.ModifiableActionDefinition; import com.bytechef.component.definition.Parameters; import com.bytechef.component.definition.TypeReference; import com.bytechef.component.llm.Chat; -import com.bytechef.component.llm.util.LLMUtils; import com.fasterxml.jackson.databind.ObjectMapper; -import java.util.Arrays; -import java.util.stream.Collectors; import org.springframework.ai.bedrock.anthropic3.Anthropic3ChatOptions; import org.springframework.ai.bedrock.anthropic3.BedrockAnthropic3ChatModel; import org.springframework.ai.bedrock.anthropic3.api.Anthropic3ChatBedrockApi; @@ -65,13 +63,7 @@ public class AmazonBedrockAnthropic3ChatAction { .label("Model") .description("ID of the model to use.") .required(true) - .options( - LLMUtils.getEnumOptions( - Arrays.stream(Anthropic3ChatBedrockApi.AnthropicChatModel.values()) - .collect( - Collectors.toMap( - Anthropic3ChatBedrockApi.AnthropicChatModel::getName, - Anthropic3ChatBedrockApi.AnthropicChatModel::getName, (f, s) -> f)))), + .options(AmazonBedrockConstants.ANTHROPIC3_MODELS), MESSAGES_PROPERTY, integer(MAX_TOKENS) .label("Max Tokens") @@ -89,11 +81,13 @@ public class AmazonBedrockAnthropic3ChatAction { private AmazonBedrockAnthropic3ChatAction() { } - public static Object perform(Parameters inputParameters, Parameters connectionParameters, ActionContext context) { + public static Object perform( + Parameters inputParameters, Parameters connectionParameters, ActionContext context) { + return CHAT.getResponse(inputParameters, connectionParameters, context); } - private static final Chat CHAT = new Chat() { + public static final Chat CHAT = new Chat() { @Override public ChatModel createChatModel(Parameters inputParameters, Parameters connectionParameters) { diff --git a/server/libs/modules/components/llm/amazon-bedrock/src/main/java/com/bytechef/component/amazon/bedrock/action/AmazonBedrockCohereChatAction.java b/server/libs/modules/components/llm/amazon-bedrock/src/main/java/com/bytechef/component/amazon/bedrock/action/AmazonBedrockCohereChatAction.java index c980b70a413..48290f4a94d 100644 --- a/server/libs/modules/components/llm/amazon-bedrock/src/main/java/com/bytechef/component/amazon/bedrock/action/AmazonBedrockCohereChatAction.java +++ b/server/libs/modules/components/llm/amazon-bedrock/src/main/java/com/bytechef/component/amazon/bedrock/action/AmazonBedrockCohereChatAction.java @@ -45,6 +45,7 @@ import static com.bytechef.component.llm.constant.LLMConstants.TOP_P; import static com.bytechef.component.llm.constant.LLMConstants.TOP_P_PROPERTY; +import com.bytechef.component.amazon.bedrock.constant.AmazonBedrockConstants; import com.bytechef.component.definition.ActionContext; import com.bytechef.component.definition.ComponentDsl.ModifiableActionDefinition; import com.bytechef.component.definition.Parameters; @@ -74,14 +75,7 @@ public class AmazonBedrockCohereChatAction { .label("Model") .description("ID of the model to use.") .required(true) - .options( - LLMUtils.getEnumOptions( - Arrays.stream( - CohereChatBedrockApi.CohereChatModel.values()) - .collect( - Collectors.toMap( - CohereChatBedrockApi.CohereChatModel::getName, - CohereChatBedrockApi.CohereChatModel::getName, (f, s) -> f)))), + .options(AmazonBedrockConstants.COHERE_MODELS), MESSAGES_PROPERTY, RESPONSE_FORMAT_PROPERTY, RESPONSE_SCHEMA_PROPERTY, @@ -129,11 +123,13 @@ public class AmazonBedrockCohereChatAction { private AmazonBedrockCohereChatAction() { } - public static Object perform(Parameters inputParameters, Parameters connectionParameters, ActionContext context) { + public static Object perform( + Parameters inputParameters, Parameters connectionParameters, ActionContext context) { + return CHAT.getResponse(inputParameters, connectionParameters, context); } - private static final Chat CHAT = new Chat() { + public static final Chat CHAT = new Chat() { @Override public ChatModel createChatModel(Parameters inputParameters, Parameters connectionParameters) { diff --git a/server/libs/modules/components/llm/amazon-bedrock/src/main/java/com/bytechef/component/amazon/bedrock/action/AmazonBedrockJurassic2ChatAction.java b/server/libs/modules/components/llm/amazon-bedrock/src/main/java/com/bytechef/component/amazon/bedrock/action/AmazonBedrockJurassic2ChatAction.java index 7b6cf4fc6ae..140e3e4db96 100644 --- a/server/libs/modules/components/llm/amazon-bedrock/src/main/java/com/bytechef/component/amazon/bedrock/action/AmazonBedrockJurassic2ChatAction.java +++ b/server/libs/modules/components/llm/amazon-bedrock/src/main/java/com/bytechef/component/amazon/bedrock/action/AmazonBedrockJurassic2ChatAction.java @@ -52,10 +52,7 @@ import com.bytechef.component.definition.Parameters; import com.bytechef.component.definition.TypeReference; import com.bytechef.component.llm.Chat; -import com.bytechef.component.llm.util.LLMUtils; import com.fasterxml.jackson.databind.ObjectMapper; -import java.util.Arrays; -import java.util.stream.Collectors; import org.springframework.ai.bedrock.jurassic2.BedrockAi21Jurassic2ChatModel; import org.springframework.ai.bedrock.jurassic2.BedrockAi21Jurassic2ChatOptions; import org.springframework.ai.bedrock.jurassic2.api.Ai21Jurassic2ChatBedrockApi; @@ -73,13 +70,7 @@ public class AmazonBedrockJurassic2ChatAction { .label("Model") .description("ID of the model to use.") .required(true) - .options( - LLMUtils.getEnumOptions( - Arrays.stream(Ai21Jurassic2ChatBedrockApi.Ai21Jurassic2ChatModel.values()) - .collect( - Collectors.toMap( - Ai21Jurassic2ChatBedrockApi.Ai21Jurassic2ChatModel::getName, - Ai21Jurassic2ChatBedrockApi.Ai21Jurassic2ChatModel::getName, (f, s) -> f)))), + .options(), MESSAGES_PROPERTY, RESPONSE_FORMAT_PROPERTY, RESPONSE_SCHEMA_PROPERTY, @@ -109,11 +100,13 @@ public class AmazonBedrockJurassic2ChatAction { private AmazonBedrockJurassic2ChatAction() { } - public static Object perform(Parameters inputParameters, Parameters connectionParameters, ActionContext context) { + public static Object perform( + Parameters inputParameters, Parameters connectionParameters, ActionContext context) { + return CHAT.getResponse(inputParameters, connectionParameters, context); } - private static final Chat CHAT = new Chat() { + public static final Chat CHAT = new Chat() { @Override public ChatModel createChatModel(Parameters inputParameters, Parameters connectionParameters) { diff --git a/server/libs/modules/components/llm/amazon-bedrock/src/main/java/com/bytechef/component/amazon/bedrock/action/AmazonBedrockLlamaChatAction.java b/server/libs/modules/components/llm/amazon-bedrock/src/main/java/com/bytechef/component/amazon/bedrock/action/AmazonBedrockLlamaChatAction.java index 61d71f99733..562264e28f6 100644 --- a/server/libs/modules/components/llm/amazon-bedrock/src/main/java/com/bytechef/component/amazon/bedrock/action/AmazonBedrockLlamaChatAction.java +++ b/server/libs/modules/components/llm/amazon-bedrock/src/main/java/com/bytechef/component/amazon/bedrock/action/AmazonBedrockLlamaChatAction.java @@ -32,14 +32,12 @@ import static com.bytechef.component.llm.constant.LLMConstants.TOP_P; import static com.bytechef.component.llm.constant.LLMConstants.TOP_P_PROPERTY; +import com.bytechef.component.amazon.bedrock.constant.AmazonBedrockConstants; import com.bytechef.component.definition.ActionContext; import com.bytechef.component.definition.ComponentDsl.ModifiableActionDefinition; import com.bytechef.component.definition.Parameters; import com.bytechef.component.llm.Chat; -import com.bytechef.component.llm.util.LLMUtils; import com.fasterxml.jackson.databind.ObjectMapper; -import java.util.Arrays; -import java.util.stream.Collectors; import org.springframework.ai.bedrock.llama.BedrockLlamaChatModel; import org.springframework.ai.bedrock.llama.BedrockLlamaChatOptions; import org.springframework.ai.bedrock.llama.api.LlamaChatBedrockApi; @@ -60,14 +58,7 @@ public class AmazonBedrockLlamaChatAction { .label("Model") .description("ID of the model to use.") .required(true) - .options( - LLMUtils.getEnumOptions( - Arrays.stream(LlamaChatBedrockApi.LlamaChatModel.values()) - .collect( - Collectors.toMap( - LlamaChatBedrockApi.LlamaChatModel::getName, - LlamaChatBedrockApi.LlamaChatModel::getName, - (f, s) -> f)))), + .options(AmazonBedrockConstants.LLAMA_MODELS), MESSAGES_PROPERTY, RESPONSE_FORMAT_PROPERTY, RESPONSE_SCHEMA_PROPERTY, @@ -80,7 +71,9 @@ public class AmazonBedrockLlamaChatAction { private AmazonBedrockLlamaChatAction() { } - public static Object perform(Parameters inputParameters, Parameters connectionParameters, ActionContext context) { + public static Object perform( + Parameters inputParameters, Parameters connectionParameters, ActionContext context) { + return CHAT.getResponse(inputParameters, connectionParameters, context); } diff --git a/server/libs/modules/components/llm/amazon-bedrock/src/main/java/com/bytechef/component/amazon/bedrock/action/AmazonBedrockTitanChatAction.java b/server/libs/modules/components/llm/amazon-bedrock/src/main/java/com/bytechef/component/amazon/bedrock/action/AmazonBedrockTitanChatAction.java index 14074fd5a8e..62430aff658 100644 --- a/server/libs/modules/components/llm/amazon-bedrock/src/main/java/com/bytechef/component/amazon/bedrock/action/AmazonBedrockTitanChatAction.java +++ b/server/libs/modules/components/llm/amazon-bedrock/src/main/java/com/bytechef/component/amazon/bedrock/action/AmazonBedrockTitanChatAction.java @@ -34,15 +34,13 @@ import static com.bytechef.component.llm.constant.LLMConstants.TOP_P; import static com.bytechef.component.llm.constant.LLMConstants.TOP_P_PROPERTY; +import com.bytechef.component.amazon.bedrock.constant.AmazonBedrockConstants; import com.bytechef.component.definition.ActionContext; import com.bytechef.component.definition.ComponentDsl.ModifiableActionDefinition; import com.bytechef.component.definition.Parameters; import com.bytechef.component.definition.TypeReference; import com.bytechef.component.llm.Chat; -import com.bytechef.component.llm.util.LLMUtils; import com.fasterxml.jackson.databind.ObjectMapper; -import java.util.Arrays; -import java.util.stream.Collectors; import org.springframework.ai.bedrock.titan.BedrockTitanChatModel; import org.springframework.ai.bedrock.titan.BedrockTitanChatOptions; import org.springframework.ai.bedrock.titan.api.TitanChatBedrockApi; @@ -63,14 +61,7 @@ public class AmazonBedrockTitanChatAction { .label("Model") .description("ID of the model to use.") .required(true) - .options( - LLMUtils.getEnumOptions( - Arrays.stream(TitanChatBedrockApi.TitanChatModel.values()) - .collect( - Collectors.toMap( - TitanChatBedrockApi.TitanChatModel::getName, - TitanChatBedrockApi.TitanChatModel::getName, - (f, s) -> f)))), + .options(AmazonBedrockConstants.TITAN_MODELS), MESSAGES_PROPERTY, RESPONSE_FORMAT_PROPERTY, RESPONSE_SCHEMA_PROPERTY, @@ -84,11 +75,13 @@ public class AmazonBedrockTitanChatAction { private AmazonBedrockTitanChatAction() { } - public static Object perform(Parameters inputParameters, Parameters connectionParameters, ActionContext context) { + public static Object perform( + Parameters inputParameters, Parameters connectionParameters, ActionContext context) { + return CHAT.getResponse(inputParameters, connectionParameters, context); } - private static final Chat CHAT = new Chat() { + public static final Chat CHAT = new Chat() { @Override public ChatModel createChatModel(Parameters inputParameters, Parameters connectionParameters) { diff --git a/server/libs/modules/components/llm/amazon-bedrock/src/main/java/com/bytechef/component/amazon/bedrock/constant/AmazonBedrockConstants.java b/server/libs/modules/components/llm/amazon-bedrock/src/main/java/com/bytechef/component/amazon/bedrock/constant/AmazonBedrockConstants.java index d42503d6e6c..db884363866 100644 --- a/server/libs/modules/components/llm/amazon-bedrock/src/main/java/com/bytechef/component/amazon/bedrock/constant/AmazonBedrockConstants.java +++ b/server/libs/modules/components/llm/amazon-bedrock/src/main/java/com/bytechef/component/amazon/bedrock/constant/AmazonBedrockConstants.java @@ -16,6 +16,17 @@ package com.bytechef.component.amazon.bedrock.constant; +import com.bytechef.component.definition.Option; +import com.bytechef.component.llm.util.LLMUtils; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; +import org.springframework.ai.bedrock.anthropic.api.AnthropicChatBedrockApi; +import org.springframework.ai.bedrock.cohere.api.CohereChatBedrockApi; +import org.springframework.ai.bedrock.jurassic2.api.Ai21Jurassic2ChatBedrockApi; +import org.springframework.ai.bedrock.llama.api.LlamaChatBedrockApi; +import org.springframework.ai.bedrock.titan.api.TitanChatBedrockApi; + /** * @author Monika Domiter * @author Marko Kriskovic @@ -32,6 +43,46 @@ public final class AmazonBedrockConstants { public static final String SECRET_ACCESS_KEY = "secretKey"; public static final String TRUNCATE = "truncate"; + public static final List> ANTHROPIC2_MODELS = LLMUtils + .getEnumOptions(Arrays.stream(AnthropicChatBedrockApi.AnthropicChatModel.values()) + .collect( + Collectors.toMap( + AnthropicChatBedrockApi.AnthropicChatModel::getName, + AnthropicChatBedrockApi.AnthropicChatModel::getName, (f, s) -> f))); + + public static final List> ANTHROPIC3_MODELS = LLMUtils.getEnumOptions( + Arrays.stream(AnthropicChatBedrockApi.AnthropicChatModel.values()) + .collect( + Collectors.toMap( + AnthropicChatBedrockApi.AnthropicChatModel::getName, + AnthropicChatBedrockApi.AnthropicChatModel::getName, (f, s) -> f))); + public static final List> COHERE_MODELS = LLMUtils + .getEnumOptions(Arrays.stream(CohereChatBedrockApi.CohereChatModel.values()) + .collect( + Collectors.toMap( + CohereChatBedrockApi.CohereChatModel::getName, + CohereChatBedrockApi.CohereChatModel::getName, (f, s) -> f))); + public static final List> JURASSIC2_MODELS = LLMUtils + .getEnumOptions(Arrays.stream(Ai21Jurassic2ChatBedrockApi.Ai21Jurassic2ChatModel.values()) + .collect( + Collectors.toMap( + Ai21Jurassic2ChatBedrockApi.Ai21Jurassic2ChatModel::getName, + Ai21Jurassic2ChatBedrockApi.Ai21Jurassic2ChatModel::getName, (f, s) -> f))); + public static final List> LLAMA_MODELS = LLMUtils + .getEnumOptions(Arrays.stream(LlamaChatBedrockApi.LlamaChatModel.values()) + .collect( + Collectors.toMap( + LlamaChatBedrockApi.LlamaChatModel::getName, + LlamaChatBedrockApi.LlamaChatModel::getName, + (f, s) -> f))); + public static final List> TITAN_MODELS = LLMUtils + .getEnumOptions(Arrays.stream(TitanChatBedrockApi.TitanChatModel.values()) + .collect( + Collectors.toMap( + TitanChatBedrockApi.TitanChatModel::getName, + TitanChatBedrockApi.TitanChatModel::getName, + (f, s) -> f))); + private AmazonBedrockConstants() { } } diff --git a/server/libs/modules/components/llm/anthropic/src/main/java/com/bytechef/component/anthropic/action/AnthropicChatAction.java b/server/libs/modules/components/llm/anthropic/src/main/java/com/bytechef/component/anthropic/action/AnthropicChatAction.java index c1cdbc78eaa..ac1bf119e98 100644 --- a/server/libs/modules/components/llm/anthropic/src/main/java/com/bytechef/component/anthropic/action/AnthropicChatAction.java +++ b/server/libs/modules/components/llm/anthropic/src/main/java/com/bytechef/component/anthropic/action/AnthropicChatAction.java @@ -35,14 +35,12 @@ import static com.bytechef.component.llm.constant.LLMConstants.TOP_P; import static com.bytechef.component.llm.constant.LLMConstants.TOP_P_PROPERTY; +import com.bytechef.component.anthropic.constant.AnthropicConstants; import com.bytechef.component.definition.ActionContext; import com.bytechef.component.definition.ComponentDsl.ModifiableActionDefinition; import com.bytechef.component.definition.Parameters; import com.bytechef.component.definition.TypeReference; import com.bytechef.component.llm.Chat; -import com.bytechef.component.llm.util.LLMUtils; -import java.util.Arrays; -import java.util.stream.Collectors; import org.springframework.ai.anthropic.AnthropicChatModel; import org.springframework.ai.anthropic.AnthropicChatOptions; import org.springframework.ai.anthropic.api.AnthropicApi; @@ -62,12 +60,7 @@ public class AnthropicChatAction { .label("Model") .description("ID of the model to use.") .required(true) - .options( - LLMUtils.getEnumOptions( - Arrays.stream(AnthropicApi.ChatModel.values()) - .collect( - Collectors.toMap( - AnthropicApi.ChatModel::getValue, AnthropicApi.ChatModel::getValue, (f, s) -> f)))), + .options(AnthropicConstants.MODELS), MESSAGES_PROPERTY, integer(MAX_TOKENS) .label("Max Tokens") @@ -89,7 +82,7 @@ public static Object perform(Parameters inputParameters, Parameters connectionPa return CHAT.getResponse(inputParameters, connectionParameters, context); } - private static final Chat CHAT = new Chat() { + public static final Chat CHAT = new Chat() { @Override public ChatModel createChatModel(Parameters inputParameters, Parameters connectionParameters) { diff --git a/server/libs/modules/components/llm/anthropic/src/main/java/com/bytechef/component/anthropic/constant/AnthropicConstants.java b/server/libs/modules/components/llm/anthropic/src/main/java/com/bytechef/component/anthropic/constant/AnthropicConstants.java new file mode 100644 index 00000000000..c50b63205cb --- /dev/null +++ b/server/libs/modules/components/llm/anthropic/src/main/java/com/bytechef/component/anthropic/constant/AnthropicConstants.java @@ -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.anthropic.constant; + +import com.bytechef.component.definition.Option; +import com.bytechef.component.llm.util.LLMUtils; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; +import org.springframework.ai.anthropic.api.AnthropicApi; + +/** + * @author Ivica Cardic + */ +public class AnthropicConstants { + public static final List> MODELS = LLMUtils + .getEnumOptions(Arrays.stream(AnthropicApi.ChatModel.values()) + .collect( + Collectors.toMap( + AnthropicApi.ChatModel::getValue, AnthropicApi.ChatModel::getValue, (f, s) -> f))); +} diff --git a/server/libs/modules/components/llm/azure-openai/src/main/java/com/bytechef/component/azure/openai/action/AzureOpenAIChatAction.java b/server/libs/modules/components/llm/azure-openai/src/main/java/com/bytechef/component/azure/openai/action/AzureOpenAIChatAction.java index 73118194a6a..66d461ed309 100644 --- a/server/libs/modules/components/llm/azure-openai/src/main/java/com/bytechef/component/azure/openai/action/AzureOpenAIChatAction.java +++ b/server/libs/modules/components/llm/azure-openai/src/main/java/com/bytechef/component/azure/openai/action/AzureOpenAIChatAction.java @@ -90,11 +90,12 @@ public class AzureOpenAIChatAction { private AzureOpenAIChatAction() { } - public static Object perform(Parameters inputParameters, Parameters connectionParameters, ActionContext context) { + public static Object perform( + Parameters inputParameters, Parameters connectionParameters, ActionContext context) { return CHAT.getResponse(inputParameters, connectionParameters, context); } - private static final Chat CHAT = new Chat() { + public static final Chat CHAT = new Chat() { @Override public ChatModel createChatModel(Parameters inputParameters, Parameters connectionParameters) { diff --git a/server/libs/modules/components/llm/groq/src/main/java/com/bytechef/component/groq/action/GroqChatAction.java b/server/libs/modules/components/llm/groq/src/main/java/com/bytechef/component/groq/action/GroqChatAction.java index fcc22124479..43fe4e792aa 100644 --- a/server/libs/modules/components/llm/groq/src/main/java/com/bytechef/component/groq/action/GroqChatAction.java +++ b/server/libs/modules/components/llm/groq/src/main/java/com/bytechef/component/groq/action/GroqChatAction.java @@ -90,7 +90,7 @@ public static Object perform(Parameters inputParameters, Parameters connectionPa return CHAT.getResponse(inputParameters, connectionParameters, context); } - private static final Chat CHAT = new Chat() { + public static final Chat CHAT = new Chat() { @Override public ChatModel createChatModel(Parameters inputParameters, Parameters connectionParameters) { diff --git a/server/libs/modules/components/llm/mistral/src/main/java/com/bytechef/component/mistral/action/MistralChatAction.java b/server/libs/modules/components/llm/mistral/src/main/java/com/bytechef/component/mistral/action/MistralChatAction.java index 83b28c31cce..a03aca41d04 100644 --- a/server/libs/modules/components/llm/mistral/src/main/java/com/bytechef/component/mistral/action/MistralChatAction.java +++ b/server/libs/modules/components/llm/mistral/src/main/java/com/bytechef/component/mistral/action/MistralChatAction.java @@ -43,9 +43,7 @@ import com.bytechef.component.definition.Parameters; import com.bytechef.component.definition.TypeReference; import com.bytechef.component.llm.Chat; -import com.bytechef.component.llm.util.LLMUtils; -import java.util.Arrays; -import java.util.stream.Collectors; +import com.bytechef.component.mistral.constant.MistralConstants; import org.springframework.ai.chat.model.ChatModel; import org.springframework.ai.chat.prompt.ChatOptions; import org.springframework.ai.mistralai.MistralAiChatModel; @@ -65,12 +63,7 @@ public class MistralChatAction { .label("Model") .description("ID of the model to use.") .required(true) - .options(LLMUtils.getEnumOptions( - Arrays.stream( - MistralAiApi.ChatModel.values()) - .collect( - Collectors.toMap( - MistralAiApi.ChatModel::getValue, MistralAiApi.ChatModel::getValue, (f, s) -> f)))), + .options(MistralConstants.MODELS), MESSAGES_PROPERTY, RESPONSE_FORMAT_PROPERTY, RESPONSE_SCHEMA_PROPERTY, @@ -90,11 +83,13 @@ public class MistralChatAction { private MistralChatAction() { } - public static Object perform(Parameters inputParameters, Parameters connectionParameters, ActionContext context) { + public static Object perform( + Parameters inputParameters, Parameters connectionParameters, ActionContext context) { + return CHAT.getResponse(inputParameters, connectionParameters, context); } - private static final Chat CHAT = new Chat() { + public static final Chat CHAT = new Chat() { @Override public ChatModel createChatModel(Parameters inputParameters, Parameters connectionParameters) { diff --git a/server/libs/modules/components/llm/mistral/src/main/java/com/bytechef/component/mistral/constant/MistralConstants.java b/server/libs/modules/components/llm/mistral/src/main/java/com/bytechef/component/mistral/constant/MistralConstants.java index cc9ea907305..89fbc96de5c 100644 --- a/server/libs/modules/components/llm/mistral/src/main/java/com/bytechef/component/mistral/constant/MistralConstants.java +++ b/server/libs/modules/components/llm/mistral/src/main/java/com/bytechef/component/mistral/constant/MistralConstants.java @@ -16,6 +16,13 @@ package com.bytechef.component.mistral.constant; +import com.bytechef.component.definition.Option; +import com.bytechef.component.llm.util.LLMUtils; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; +import org.springframework.ai.mistralai.api.MistralAiApi; + /** * @author Monika Domiter */ @@ -23,6 +30,12 @@ public final class MistralConstants { public static final String SAFE_PROMPT = "safePrompt"; + public static final List> MODELS = LLMUtils + .getEnumOptions(Arrays.stream(MistralAiApi.ChatModel.values()) + .collect( + Collectors.toMap( + MistralAiApi.ChatModel::getValue, MistralAiApi.ChatModel::getValue, (f, s) -> f))); + private MistralConstants() { } } diff --git a/server/libs/modules/components/llm/nvidia/src/main/java/com/bytechef/component/nvidia/action/NVIDIAChatAction.java b/server/libs/modules/components/llm/nvidia/src/main/java/com/bytechef/component/nvidia/action/NVIDIAChatAction.java index 77fefd938b1..fda9d3f3d29 100644 --- a/server/libs/modules/components/llm/nvidia/src/main/java/com/bytechef/component/nvidia/action/NVIDIAChatAction.java +++ b/server/libs/modules/components/llm/nvidia/src/main/java/com/bytechef/component/nvidia/action/NVIDIAChatAction.java @@ -90,7 +90,7 @@ public static Object perform(Parameters inputParameters, Parameters connectionPa return CHAT.getResponse(inputParameters, connectionParameters, context); } - private static final Chat CHAT = new Chat() { + public static final Chat CHAT = new Chat() { @Override public ChatModel createChatModel(Parameters inputParameters, Parameters connectionParameters) { diff --git a/server/libs/modules/components/llm/openai/src/main/java/com/bytechef/component/openai/action/OpenAIChatAction.java b/server/libs/modules/components/llm/openai/src/main/java/com/bytechef/component/openai/action/OpenAIChatAction.java index 43842f322a5..8ccc81c77ee 100644 --- a/server/libs/modules/components/llm/openai/src/main/java/com/bytechef/component/openai/action/OpenAIChatAction.java +++ b/server/libs/modules/components/llm/openai/src/main/java/com/bytechef/component/openai/action/OpenAIChatAction.java @@ -48,9 +48,7 @@ import com.bytechef.component.definition.Parameters; import com.bytechef.component.definition.TypeReference; import com.bytechef.component.llm.Chat; -import com.bytechef.component.llm.util.LLMUtils; -import java.util.Arrays; -import java.util.stream.Collectors; +import com.bytechef.component.openai.constant.OpenAIConstants; import org.springframework.ai.chat.model.ChatModel; import org.springframework.ai.chat.prompt.ChatOptions; import org.springframework.ai.openai.OpenAiChatModel; @@ -71,12 +69,7 @@ public class OpenAIChatAction { .label("Model") .description("ID of the model to use.") .required(true) - .options( - LLMUtils.getEnumOptions( - Arrays.stream(OpenAiApi.ChatModel.values()) - .collect( - Collectors.toMap( - OpenAiApi.ChatModel::getValue, OpenAiApi.ChatModel::getValue, (f, s) -> f)))), + .options(OpenAIConstants.MODELS), MESSAGES_PROPERTY, RESPONSE_FORMAT_PROPERTY, RESPONSE_SCHEMA_PROPERTY, @@ -95,11 +88,13 @@ public class OpenAIChatAction { private OpenAIChatAction() { } - public static Object perform(Parameters inputParameters, Parameters connectionParameters, ActionContext context) { - return CHAT.getResponse(inputParameters, connectionParameters, context); + public static Object perform( + Parameters inputParameters, Parameters connectionParameters, ActionContext actionContext) { + + return CHAT.getResponse(inputParameters, connectionParameters, actionContext); } - private static final Chat CHAT = new Chat() { + public static final Chat CHAT = new Chat() { @Override public ChatModel createChatModel(Parameters inputParameters, Parameters connectionParameters) { diff --git a/server/libs/modules/components/llm/openai/src/main/java/com/bytechef/component/openai/constant/OpenAIConstants.java b/server/libs/modules/components/llm/openai/src/main/java/com/bytechef/component/openai/constant/OpenAIConstants.java index 17f247f8c14..27876d05547 100644 --- a/server/libs/modules/components/llm/openai/src/main/java/com/bytechef/component/openai/constant/OpenAIConstants.java +++ b/server/libs/modules/components/llm/openai/src/main/java/com/bytechef/component/openai/constant/OpenAIConstants.java @@ -16,6 +16,13 @@ package com.bytechef.component.openai.constant; +import com.bytechef.component.definition.Option; +import com.bytechef.component.llm.util.LLMUtils; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; +import org.springframework.ai.openai.api.OpenAiApi; + /** * @author Monika Domiter * @author Marko Kriskovic @@ -24,6 +31,12 @@ public final class OpenAIConstants { public static final String QUALITY = "quality"; + public static final List> MODELS = LLMUtils + .getEnumOptions(Arrays.stream(OpenAiApi.ChatModel.values()) + .collect( + Collectors.toMap( + OpenAiApi.ChatModel::getValue, OpenAiApi.ChatModel::getValue, (f, s) -> f))); + private OpenAIConstants() { } } diff --git a/server/libs/modules/components/llm/vertex/gemini/src/main/java/com/bytechef/component/vertex/gemini/action/VertexGeminiChatAction.java b/server/libs/modules/components/llm/vertex/gemini/src/main/java/com/bytechef/component/vertex/gemini/action/VertexGeminiChatAction.java index cb0d6660e7e..5cb846d0152 100644 --- a/server/libs/modules/components/llm/vertex/gemini/src/main/java/com/bytechef/component/vertex/gemini/action/VertexGeminiChatAction.java +++ b/server/libs/modules/components/llm/vertex/gemini/src/main/java/com/bytechef/component/vertex/gemini/action/VertexGeminiChatAction.java @@ -44,10 +44,8 @@ import com.bytechef.component.definition.Parameters; import com.bytechef.component.definition.TypeReference; import com.bytechef.component.llm.Chat; -import com.bytechef.component.llm.util.LLMUtils; +import com.bytechef.component.vertex.gemini.constant.VertexGeminiConstants; import com.google.cloud.vertexai.VertexAI; -import java.util.Arrays; -import java.util.stream.Collectors; import org.springframework.ai.chat.model.ChatModel; import org.springframework.ai.chat.prompt.ChatOptions; import org.springframework.ai.vertexai.gemini.VertexAiGeminiChatModel; @@ -66,15 +64,7 @@ public class VertexGeminiChatAction { .label("Model") .description("ID of the model to use.") .required(true) - .options( - LLMUtils.getEnumOptions( - Arrays.stream( - VertexAiGeminiChatModel.ChatModel.values()) - .collect( - Collectors.toMap( - VertexAiGeminiChatModel.ChatModel::getValue, - VertexAiGeminiChatModel.ChatModel::getValue, - (f, s) -> f)))), + .options(VertexGeminiConstants.MODELS), MESSAGES_PROPERTY, RESPONSE_FORMAT_PROPERTY, RESPONSE_SCHEMA_PROPERTY, @@ -96,11 +86,13 @@ public class VertexGeminiChatAction { private VertexGeminiChatAction() { } - public static Object perform(Parameters inputParameters, Parameters connectionParameters, ActionContext context) { + public static Object perform( + Parameters inputParameters, Parameters connectionParameters, ActionContext context) { + return CHAT.getResponse(inputParameters, connectionParameters, context); } - private static final Chat CHAT = new Chat() { + public static final Chat CHAT = new Chat() { @Override public ChatModel createChatModel(Parameters inputParameters, Parameters connectionParameters) { diff --git a/server/libs/modules/components/llm/vertex/gemini/src/main/java/com/bytechef/component/vertex/gemini/constant/VertexGeminiConstants.java b/server/libs/modules/components/llm/vertex/gemini/src/main/java/com/bytechef/component/vertex/gemini/constant/VertexGeminiConstants.java index 860dd5ae028..564d6c43e62 100644 --- a/server/libs/modules/components/llm/vertex/gemini/src/main/java/com/bytechef/component/vertex/gemini/constant/VertexGeminiConstants.java +++ b/server/libs/modules/components/llm/vertex/gemini/src/main/java/com/bytechef/component/vertex/gemini/constant/VertexGeminiConstants.java @@ -16,6 +16,13 @@ package com.bytechef.component.vertex.gemini.constant; +import com.bytechef.component.definition.Option; +import com.bytechef.component.llm.util.LLMUtils; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; +import org.springframework.ai.vertexai.gemini.VertexAiGeminiChatModel; + /** * @author Monika Domiter * @author Marko Kriskovic @@ -25,6 +32,14 @@ public final class VertexGeminiConstants { public static final String LOCATION = "location"; public static final String PROJECT_ID = "projectId"; + public static final List> MODELS = LLMUtils.getEnumOptions( + Arrays.stream(VertexAiGeminiChatModel.ChatModel.values()) + .collect( + Collectors.toMap( + VertexAiGeminiChatModel.ChatModel::getValue, + VertexAiGeminiChatModel.ChatModel::getValue, + (f, s) -> f))); + private VertexGeminiConstants() { } } diff --git a/server/libs/modules/components/llm/watsonx/src/main/java/com/bytechef/component/watsonx/action/WatsonxChatAction.java b/server/libs/modules/components/llm/watsonx/src/main/java/com/bytechef/component/watsonx/action/WatsonxChatAction.java index 8496b7ab19b..1a790009aa7 100644 --- a/server/libs/modules/components/llm/watsonx/src/main/java/com/bytechef/component/watsonx/action/WatsonxChatAction.java +++ b/server/libs/modules/components/llm/watsonx/src/main/java/com/bytechef/component/watsonx/action/WatsonxChatAction.java @@ -105,7 +105,7 @@ public static Object perform(Parameters inputParameters, Parameters connectionPa return CHAT.getResponse(inputParameters, connectionParameters, context); } - private static final Chat CHAT = new Chat() { + public static final Chat CHAT = new Chat() { @Override public ChatModel createChatModel(Parameters inputParameters, Parameters connectionParameters) { diff --git a/server/libs/modules/components/script/src/main/java/com/bytechef/component/script/action/ScriptJavaAction.java b/server/libs/modules/components/script/src/main/java/com/bytechef/component/script/action/ScriptJavaAction.java index 6c6c1b468b9..6f2ea330b8e 100644 --- a/server/libs/modules/components/script/src/main/java/com/bytechef/component/script/action/ScriptJavaAction.java +++ b/server/libs/modules/components/script/src/main/java/com/bytechef/component/script/action/ScriptJavaAction.java @@ -31,7 +31,7 @@ import static com.bytechef.platform.component.definition.ScriptComponentDefinition.SCRIPT; import com.bytechef.component.definition.Property; -import com.bytechef.component.script.definition.ScriptActionDefinition; +import com.bytechef.component.script.action.definition.ScriptActionDefinition; import com.bytechef.component.script.engine.PolyglotEngine; /** diff --git a/server/libs/modules/components/script/src/main/java/com/bytechef/component/script/action/ScriptJavaScriptAction.java b/server/libs/modules/components/script/src/main/java/com/bytechef/component/script/action/ScriptJavaScriptAction.java index a6cd868cdc2..054891f37c8 100644 --- a/server/libs/modules/components/script/src/main/java/com/bytechef/component/script/action/ScriptJavaScriptAction.java +++ b/server/libs/modules/components/script/src/main/java/com/bytechef/component/script/action/ScriptJavaScriptAction.java @@ -31,7 +31,7 @@ import static com.bytechef.platform.component.definition.ScriptComponentDefinition.SCRIPT; import com.bytechef.component.definition.Property; -import com.bytechef.component.script.definition.ScriptActionDefinition; +import com.bytechef.component.script.action.definition.ScriptActionDefinition; import com.bytechef.component.script.engine.PolyglotEngine; /** diff --git a/server/libs/modules/components/script/src/main/java/com/bytechef/component/script/action/ScriptPythonAction.java b/server/libs/modules/components/script/src/main/java/com/bytechef/component/script/action/ScriptPythonAction.java index 703091eb19d..56045c76bc1 100644 --- a/server/libs/modules/components/script/src/main/java/com/bytechef/component/script/action/ScriptPythonAction.java +++ b/server/libs/modules/components/script/src/main/java/com/bytechef/component/script/action/ScriptPythonAction.java @@ -31,7 +31,7 @@ import static com.bytechef.platform.component.definition.ScriptComponentDefinition.SCRIPT; import com.bytechef.component.definition.Property; -import com.bytechef.component.script.definition.ScriptActionDefinition; +import com.bytechef.component.script.action.definition.ScriptActionDefinition; import com.bytechef.component.script.engine.PolyglotEngine; /** diff --git a/server/libs/modules/components/script/src/main/java/com/bytechef/component/script/action/ScriptRAction.java b/server/libs/modules/components/script/src/main/java/com/bytechef/component/script/action/ScriptRAction.java index 638e77cba21..fbf17adbb1c 100644 --- a/server/libs/modules/components/script/src/main/java/com/bytechef/component/script/action/ScriptRAction.java +++ b/server/libs/modules/components/script/src/main/java/com/bytechef/component/script/action/ScriptRAction.java @@ -31,7 +31,7 @@ import static com.bytechef.platform.component.definition.ScriptComponentDefinition.SCRIPT; import com.bytechef.component.definition.Property; -import com.bytechef.component.script.definition.ScriptActionDefinition; +import com.bytechef.component.script.action.definition.ScriptActionDefinition; import com.bytechef.component.script.engine.PolyglotEngine; /** diff --git a/server/libs/modules/components/script/src/main/java/com/bytechef/component/script/action/ScriptRubyAction.java b/server/libs/modules/components/script/src/main/java/com/bytechef/component/script/action/ScriptRubyAction.java index 5a8025b6512..cf834e0f57b 100644 --- a/server/libs/modules/components/script/src/main/java/com/bytechef/component/script/action/ScriptRubyAction.java +++ b/server/libs/modules/components/script/src/main/java/com/bytechef/component/script/action/ScriptRubyAction.java @@ -31,7 +31,7 @@ import static com.bytechef.platform.component.definition.ScriptComponentDefinition.SCRIPT; import com.bytechef.component.definition.Property.ControlType; -import com.bytechef.component.script.definition.ScriptActionDefinition; +import com.bytechef.component.script.action.definition.ScriptActionDefinition; import com.bytechef.component.script.engine.PolyglotEngine; /** diff --git a/server/libs/modules/components/script/src/main/java/com/bytechef/component/script/definition/ScriptActionDefinition.java b/server/libs/modules/components/script/src/main/java/com/bytechef/component/script/action/definition/ScriptActionDefinition.java similarity index 97% rename from server/libs/modules/components/script/src/main/java/com/bytechef/component/script/definition/ScriptActionDefinition.java rename to server/libs/modules/components/script/src/main/java/com/bytechef/component/script/action/definition/ScriptActionDefinition.java index c8656d2be2f..16d8741746e 100644 --- a/server/libs/modules/components/script/src/main/java/com/bytechef/component/script/definition/ScriptActionDefinition.java +++ b/server/libs/modules/components/script/src/main/java/com/bytechef/component/script/action/definition/ScriptActionDefinition.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.bytechef.component.script.definition; +package com.bytechef.component.script.action.definition; import com.bytechef.component.definition.ActionContext; import com.bytechef.component.definition.ActionDefinition; diff --git a/server/libs/platform/platform-component/platform-component-api/src/main/java/com/bytechef/platform/component/definition/AIComponentDefinition.java b/server/libs/platform/platform-component/platform-component-api/src/main/java/com/bytechef/platform/component/definition/AIComponentDefinition.java new file mode 100644 index 00000000000..35c6ba5d4a0 --- /dev/null +++ b/server/libs/platform/platform-component/platform-component-api/src/main/java/com/bytechef/platform/component/definition/AIComponentDefinition.java @@ -0,0 +1,28 @@ +/* + * 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.platform.component.definition; + +/** + * @author Ivica Cardic + */ +public interface AIComponentDefinition extends PlatformComponentDefinition { + + /** + * + */ + String AI_TEXT_ANALYSIS = "aiTextAnalysis"; +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 50a4c7d7fea..8b7401c9acb 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -219,6 +219,7 @@ include("server:libs:platform:platform-workflow:platform-workflow-execution:plat include("server:libs:modules:components:accelo") include("server:libs:modules:components:active-campaign") include("server:libs:modules:components:affinity") +include("server:libs:modules:components:ai:ai-text-analysis") include("server:libs:modules:components:airtable") include("server:libs:modules:components:aitable") include("server:libs:modules:components:app-event")