Skip to content

Commit

Permalink
chore: add executeActionDTO as additional parameter to be used when c…
Browse files Browse the repository at this point in the history
…reating query for AppsmithAI plugin queries (#37631)

## Description
> Add executeActionDTO as an additional parameter when executing queries
for Appsmith AI Plugin

Fixes #37637

## Automation

/ok-to-test tags="@tag.Sanity"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/11949422399>
> Commit: 116c384
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11949422399&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Sanity`
> Spec:
> <hr>Thu, 21 Nov 2024 09:04:26 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No

---------

Co-authored-by: Nilesh Sarupriya <20905988+nsarupr@users.noreply.github.com>
  • Loading branch information
nsarupr and nsarupr authored Nov 25, 2024
1 parent baef6aa commit c55e98b
Show file tree
Hide file tree
Showing 16 changed files with 80 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public Mono<ActionExecutionResult> executeCommon(
Feature feature =
Feature.valueOf(RequestUtils.extractDataFromFormData(actionConfiguration.getFormData(), USECASE));
AiFeatureService aiFeatureService = AiFeatureServiceFactory.getAiFeatureService(feature);
Query query = aiFeatureService.createQuery(actionConfiguration, datasourceConfiguration);
Query query = aiFeatureService.createQuery(actionConfiguration, datasourceConfiguration, executeActionDTO);
AiServerRequestDTO aiServerRequestDTO = new AiServerRequestDTO(feature, query);

ActionExecutionResult actionExecutionResult = new ActionExecutionResult();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.external.plugins.services;

import com.appsmith.external.dtos.ExecuteActionDTO;
import com.appsmith.external.models.ActionConfiguration;
import com.appsmith.external.models.DatasourceConfiguration;
import com.external.plugins.dtos.Query;

public interface AiFeatureService {
Query createQuery(ActionConfiguration actionConfiguration, DatasourceConfiguration datasourceConfiguration);
Query createQuery(
ActionConfiguration actionConfiguration,
DatasourceConfiguration datasourceConfiguration,
ExecuteActionDTO executeActionDTO);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.external.plugins.services.features;

import com.appsmith.external.dtos.ExecuteActionDTO;
import com.appsmith.external.helpers.PluginUtils;
import com.appsmith.external.models.ActionConfiguration;
import com.appsmith.external.models.DatasourceConfiguration;
Expand All @@ -16,7 +17,10 @@

public class ImageCaptioningServiceImpl implements AiFeatureService {
@Override
public Query createQuery(ActionConfiguration actionConfiguration, DatasourceConfiguration datasourceConfiguration) {
public Query createQuery(
ActionConfiguration actionConfiguration,
DatasourceConfiguration datasourceConfiguration,
ExecuteActionDTO executeActionDTO) {
Map<String, Object> formData = actionConfiguration.getFormData();
validateTextInput(formData, IMAGE_CAPTIONING);
String input = PluginUtils.getDataValueSafelyFromFormData(formData, IMAGE_CAPTION_INPUT, STRING_TYPE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.external.plugins.services.features;

import com.appsmith.external.dtos.ExecuteActionDTO;
import com.appsmith.external.helpers.PluginUtils;
import com.appsmith.external.models.ActionConfiguration;
import com.appsmith.external.models.DatasourceConfiguration;
Expand All @@ -20,7 +21,10 @@

public class ImageClassificationServiceImpl implements AiFeatureService {
@Override
public Query createQuery(ActionConfiguration actionConfiguration, DatasourceConfiguration datasourceConfiguration) {
public Query createQuery(
ActionConfiguration actionConfiguration,
DatasourceConfiguration datasourceConfiguration,
ExecuteActionDTO executeActionDTO) {

Map<String, Object> formData = actionConfiguration.getFormData();
validateTextInputAndProperties(formData, IMAGE_CLASSIFICATION, List.of(LABELS));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.external.plugins.services.features;

import com.appsmith.external.dtos.ExecuteActionDTO;
import com.appsmith.external.helpers.PluginUtils;
import com.appsmith.external.models.ActionConfiguration;
import com.appsmith.external.models.DatasourceConfiguration;
Expand All @@ -20,7 +21,10 @@

public class ImageEntityExtractionServiceImpl implements AiFeatureService {
@Override
public Query createQuery(ActionConfiguration actionConfiguration, DatasourceConfiguration datasourceConfiguration) {
public Query createQuery(
ActionConfiguration actionConfiguration,
DatasourceConfiguration datasourceConfiguration,
ExecuteActionDTO executeActionDTO) {
Map<String, Object> formData = actionConfiguration.getFormData();
validateTextInputAndProperties(formData, IMAGE_ENTITY_EXTRACTION, List.of(LABELS));
String input = PluginUtils.getDataValueSafelyFromFormData(formData, IMAGE_ENTITY_INPUT, STRING_TYPE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.external.plugins.services.features;

import com.appsmith.external.dtos.ExecuteActionDTO;
import com.appsmith.external.helpers.PluginUtils;
import com.appsmith.external.models.ActionConfiguration;
import com.appsmith.external.models.DatasourceConfiguration;
Expand All @@ -20,7 +21,10 @@

public class TextClassificationServiceImpl implements AiFeatureService {
@Override
public Query createQuery(ActionConfiguration actionConfiguration, DatasourceConfiguration datasourceConfiguration) {
public Query createQuery(
ActionConfiguration actionConfiguration,
DatasourceConfiguration datasourceConfiguration,
ExecuteActionDTO executeActionDTO) {
Map<String, Object> formData = actionConfiguration.getFormData();
validateTextInputAndProperties(formData, TEXT_CLASSIFICATION, List.of(LABELS));
String input = PluginUtils.getDataValueSafelyFromFormData(formData, TEXT_CLASSIFY_INPUT, STRING_TYPE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.external.plugins.services.features;

import com.appsmith.external.dtos.ExecuteActionDTO;
import com.appsmith.external.helpers.PluginUtils;
import com.appsmith.external.models.ActionConfiguration;
import com.appsmith.external.models.DatasourceConfiguration;
Expand All @@ -20,7 +21,10 @@

public class TextEntityExtractionServiceImpl implements AiFeatureService {
@Override
public Query createQuery(ActionConfiguration actionConfiguration, DatasourceConfiguration datasourceConfiguration) {
public Query createQuery(
ActionConfiguration actionConfiguration,
DatasourceConfiguration datasourceConfiguration,
ExecuteActionDTO executeActionDTO) {
Map<String, Object> formData = actionConfiguration.getFormData();
validateTextInputAndProperties(formData, TEXT_ENTITY_EXTRACTION, List.of(LABELS));
String input = PluginUtils.getDataValueSafelyFromFormData(formData, TEXT_ENTITY_INPUT, STRING_TYPE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.external.plugins.services.features;

import com.appsmith.external.dtos.ExecuteActionDTO;
import com.appsmith.external.helpers.PluginUtils;
import com.appsmith.external.models.ActionConfiguration;
import com.appsmith.external.models.DatasourceConfiguration;
Expand All @@ -18,7 +19,10 @@

public class TextGenerationServiceImpl implements AiFeatureService {
@Override
public Query createQuery(ActionConfiguration actionConfiguration, DatasourceConfiguration datasourceConfiguration) {
public Query createQuery(
ActionConfiguration actionConfiguration,
DatasourceConfiguration datasourceConfiguration,
ExecuteActionDTO executeActionDTO) {
Map<String, Object> formData = actionConfiguration.getFormData();
validateTextInput(formData, TEXT_GENERATION);
String input = PluginUtils.getDataValueSafelyFromFormData(formData, TEXT_GENERATION_INPUT, STRING_TYPE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.external.plugins.services.features;

import com.appsmith.external.dtos.ExecuteActionDTO;
import com.appsmith.external.helpers.PluginUtils;
import com.appsmith.external.models.ActionConfiguration;
import com.appsmith.external.models.DatasourceConfiguration;
Expand All @@ -16,7 +17,10 @@

public class TextSummarizationServiceImpl implements AiFeatureService {
@Override
public Query createQuery(ActionConfiguration actionConfiguration, DatasourceConfiguration datasourceConfiguration) {
public Query createQuery(
ActionConfiguration actionConfiguration,
DatasourceConfiguration datasourceConfiguration,
ExecuteActionDTO executeActionDTO) {
Map<String, Object> formData = actionConfiguration.getFormData();
validateTextInput(formData, TEXT_SUMMARY);
String input = PluginUtils.getDataValueSafelyFromFormData(formData, TEXT_SUMMARY_INPUT, STRING_TYPE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.external.plugins.services.features;

import com.appsmith.external.dtos.ExecuteActionDTO;
import com.appsmith.external.exceptions.pluginExceptions.AppsmithPluginException;
import com.appsmith.external.models.ActionConfiguration;
import com.appsmith.external.models.DatasourceConfiguration;
Expand Down Expand Up @@ -33,7 +34,8 @@ void testCreateQuery_ValidInput() {
INSTRUCTIONS, Map.of(DATA, "Some instructions")));
actionConfiguration.setFormData(formData);

Query query = imageCaptioningService.createQuery(actionConfiguration, datasourceConfiguration);
Query query = imageCaptioningService.createQuery(
actionConfiguration, datasourceConfiguration, new ExecuteActionDTO());

assertNotNull(query);
assertEquals("Some image data", query.getInput());
Expand All @@ -53,7 +55,8 @@ void testCreateQuery_MissingImageInput() {

AppsmithPluginException exception = assertThrows(
AppsmithPluginException.class,
() -> imageCaptioningService.createQuery(actionConfiguration, datasourceConfiguration));
() -> imageCaptioningService.createQuery(
actionConfiguration, datasourceConfiguration, new ExecuteActionDTO()));

assertEquals("input is not provided", exception.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.external.plugins.services.features;

import com.appsmith.external.dtos.ExecuteActionDTO;
import com.appsmith.external.exceptions.pluginExceptions.AppsmithPluginException;
import com.appsmith.external.models.ActionConfiguration;
import com.appsmith.external.models.DatasourceConfiguration;
Expand Down Expand Up @@ -36,7 +37,8 @@ void testCreateQuery_ValidInput() {
INSTRUCTIONS, Map.of(DATA, "Some instructions")));
actionConfiguration.setFormData(formData);

Query query = imageClassificationService.createQuery(actionConfiguration, datasourceConfiguration);
Query query = imageClassificationService.createQuery(
actionConfiguration, datasourceConfiguration, new ExecuteActionDTO());

assertNotNull(query);
assertEquals("Some image data", query.getInput());
Expand All @@ -56,7 +58,8 @@ void testCreateQuery_MissingImageInput() {

AppsmithPluginException exception = assertThrows(
AppsmithPluginException.class,
() -> imageClassificationService.createQuery(actionConfiguration, datasourceConfiguration));
() -> imageClassificationService.createQuery(
actionConfiguration, datasourceConfiguration, new ExecuteActionDTO()));

assertEquals("input is not provided", exception.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.external.plugins.services.features;

import com.appsmith.external.dtos.ExecuteActionDTO;
import com.appsmith.external.exceptions.pluginExceptions.AppsmithPluginException;
import com.appsmith.external.models.ActionConfiguration;
import com.appsmith.external.models.DatasourceConfiguration;
Expand Down Expand Up @@ -36,7 +37,8 @@ void testCreateQuery_ValidInput() {
INSTRUCTIONS, Map.of(DATA, "Some instructions")));
actionConfiguration.setFormData(formData);

Query query = imageEntityExtractionService.createQuery(actionConfiguration, datasourceConfiguration);
Query query = imageEntityExtractionService.createQuery(
actionConfiguration, datasourceConfiguration, new ExecuteActionDTO());

assertNotNull(query);
assertEquals("Some image data", query.getInput());
Expand All @@ -56,7 +58,8 @@ void testCreateQuery_MissingImageInput() {

AppsmithPluginException exception = assertThrows(
AppsmithPluginException.class,
() -> imageEntityExtractionService.createQuery(actionConfiguration, datasourceConfiguration));
() -> imageEntityExtractionService.createQuery(
actionConfiguration, datasourceConfiguration, new ExecuteActionDTO()));

assertEquals("input is not provided", exception.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.external.plugins.services.features;

import com.appsmith.external.dtos.ExecuteActionDTO;
import com.appsmith.external.exceptions.pluginExceptions.AppsmithPluginException;
import com.appsmith.external.models.ActionConfiguration;
import com.appsmith.external.models.DatasourceConfiguration;
Expand Down Expand Up @@ -36,7 +37,8 @@ void testCreateQuery_ValidInput() {
INSTRUCTIONS, Map.of(DATA, "Some instructions")));
actionConfiguration.setFormData(formData);

Query query = textClassificationService.createQuery(actionConfiguration, datasourceConfiguration);
Query query = textClassificationService.createQuery(
actionConfiguration, datasourceConfiguration, new ExecuteActionDTO());

assertNotNull(query);
assertEquals("Some text", query.getInput());
Expand All @@ -56,7 +58,8 @@ void testCreateQuery_MissingTextInput() {

AppsmithPluginException exception = assertThrows(
AppsmithPluginException.class,
() -> textClassificationService.createQuery(actionConfiguration, datasourceConfiguration));
() -> textClassificationService.createQuery(
actionConfiguration, datasourceConfiguration, new ExecuteActionDTO()));

assertEquals("input is not provided", exception.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.external.plugins.services.features;

import com.appsmith.external.dtos.ExecuteActionDTO;
import com.appsmith.external.exceptions.pluginExceptions.AppsmithPluginException;
import com.appsmith.external.models.ActionConfiguration;
import com.appsmith.external.models.DatasourceConfiguration;
Expand Down Expand Up @@ -37,7 +38,8 @@ void testCreateQuery_ValidInput() {
Map.of(DATA, "Some instructions")));
actionConfiguration.setFormData(formData);

Query query = textEntityExtractionService.createQuery(actionConfiguration, datasourceConfiguration);
Query query = textEntityExtractionService.createQuery(
actionConfiguration, datasourceConfiguration, new ExecuteActionDTO());

assertNotNull(query);
assertEquals("Some text", query.getInput());
Expand All @@ -57,7 +59,8 @@ void testCreateQuery_MissingTextInput() {

AppsmithPluginException exception = assertThrows(
AppsmithPluginException.class,
() -> textEntityExtractionService.createQuery(actionConfiguration, datasourceConfiguration));
() -> textEntityExtractionService.createQuery(
actionConfiguration, datasourceConfiguration, new ExecuteActionDTO()));

assertEquals("input is not provided", exception.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.external.plugins.services.features;

import com.appsmith.external.dtos.ExecuteActionDTO;
import com.appsmith.external.exceptions.pluginExceptions.AppsmithPluginException;
import com.appsmith.external.models.ActionConfiguration;
import com.appsmith.external.models.DatasourceConfiguration;
Expand Down Expand Up @@ -27,7 +28,8 @@ void testCreateQuery_ValidInput() {
formData.put(TEXT_GENERATION, Map.of(INPUT, Map.of(DATA, "Hello, World!")));
actionConfiguration.setFormData(formData);

Query query = textGenerationService.createQuery(actionConfiguration, datasourceConfiguration);
Query query =
textGenerationService.createQuery(actionConfiguration, datasourceConfiguration, new ExecuteActionDTO());

assertNotNull(query);
assertEquals("Hello, World!", query.getInput());
Expand All @@ -45,7 +47,8 @@ void testCreateQuery_MissingTextInput() {

AppsmithPluginException exception = assertThrows(
AppsmithPluginException.class,
() -> textGenerationService.createQuery(actionConfiguration, datasourceConfiguration));
() -> textGenerationService.createQuery(
actionConfiguration, datasourceConfiguration, new ExecuteActionDTO()));

assertEquals("input is not provided", exception.getMessage());
}
Expand All @@ -62,7 +65,8 @@ void testCreateQuery_EmptyTextInput() {

AppsmithPluginException exception = assertThrows(
AppsmithPluginException.class,
() -> textGenerationService.createQuery(actionConfiguration, datasourceConfiguration));
() -> textGenerationService.createQuery(
actionConfiguration, datasourceConfiguration, new ExecuteActionDTO()));

assertEquals("input is not provided", exception.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.external.plugins.services.features;

import com.appsmith.external.dtos.ExecuteActionDTO;
import com.appsmith.external.exceptions.pluginExceptions.AppsmithPluginException;
import com.appsmith.external.models.ActionConfiguration;
import com.appsmith.external.models.DatasourceConfiguration;
Expand Down Expand Up @@ -30,7 +31,8 @@ void testCreateQuery_ValidInput() {
Map.of(INPUT, Map.of(DATA, "Some text"), INSTRUCTIONS, Map.of(DATA, "Some instructions")));
actionConfiguration.setFormData(formData);

Query query = textSummarizationService.createQuery(actionConfiguration, datasourceConfiguration);
Query query = textSummarizationService.createQuery(
actionConfiguration, datasourceConfiguration, new ExecuteActionDTO());

assertNotNull(query);
assertEquals("Some text", query.getInput());
Expand All @@ -49,7 +51,8 @@ void testCreateQuery_MissingTextInput() {

AppsmithPluginException exception = assertThrows(
AppsmithPluginException.class,
() -> textSummarizationService.createQuery(actionConfiguration, datasourceConfiguration));
() -> textSummarizationService.createQuery(
actionConfiguration, datasourceConfiguration, new ExecuteActionDTO()));

assertEquals("input is not provided", exception.getMessage());
}
Expand All @@ -66,7 +69,8 @@ void testCreateQuery_EmptyTextInput() {

AppsmithPluginException exception = assertThrows(
AppsmithPluginException.class,
() -> textSummarizationService.createQuery(actionConfiguration, datasourceConfiguration));
() -> textSummarizationService.createQuery(
actionConfiguration, datasourceConfiguration, new ExecuteActionDTO()));

assertEquals("input is not provided", exception.getMessage());
}
Expand Down

0 comments on commit c55e98b

Please sign in to comment.