Skip to content

Commit

Permalink
null check and dynamic query input
Browse files Browse the repository at this point in the history
  • Loading branch information
vivonk committed Apr 15, 2024
1 parent 21e53e4 commit 7687bbf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"Description": "Provide additional instructions for the AI model as system prompt",
"subtitle": "Provide additional instructions for the AI model as system prompt",
"configProperty": "actionConfiguration.formData.systemPrompt.data",
"controlType": "INPUT_TEXT",
"controlType": "QUERY_DYNAMIC_INPUT_TEXT",
"placeholderText": "Write some text or use {{ }} to reference a dynamic text value",
"initialValue": "",
"isRequired": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"Description": "Provide additional instructions for the AI model as system prompt",
"subtitle": "Provide additional instructions for the AI model as system prompt",
"configProperty": "actionConfiguration.formData.systemPrompt.data",
"controlType": "INPUT_TEXT",
"controlType": "QUERY_DYNAMIC_INPUT_TEXT",
"placeholderText": "Write some text or use {{ }} to reference a dynamic text value",
"initialValue": "",
"isRequired": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.Map;

import static com.appsmith.server.constants.ce.FieldNameCE.PACKAGE_NAME;
Expand Down Expand Up @@ -56,13 +56,8 @@ public void moveAnthropicLegacyModelsInQueries() {
return;
}
String pluginId = plugin.getId();
List<NewAction> anthropicActions =
mongoTemplate.find(Query.query(Criteria.where(PLUGIN_ID).is(pluginId)), NewAction.class);
if (anthropicActions.isEmpty()) {
log.info("No Anthropic actions found");
return;
}
anthropicActions.forEach(this::updateAction);
mongoTemplate.stream(Query.query(Criteria.where(PLUGIN_ID).is(pluginId)), NewAction.class)
.forEach(this::updateAction);
}

private void updateAction(NewAction action) {
Expand All @@ -82,16 +77,21 @@ private void updateAction(NewAction action) {
.setActionConfiguration(updateActionConfiguration(publishedActionConfiguration));
}
}

mongoTemplate.save(action);
}

private ActionConfiguration updateActionConfiguration(ActionConfiguration actionConfiguration) {
Map<String, Object> formData = actionConfiguration.getFormData();
if (formData == null || formData.isEmpty()) {
return actionConfiguration;
}
if (formData.containsKey(CHAT_MODEL)) {
Map<String, String> chatModelData = (Map<String, String>) formData.get(CHAT_MODEL);
if (chatModelData == null) {
return actionConfiguration;
}
String chatModel = chatModelData.get("data");
if (LEGACY_TO_NEXT_MODELS.containsKey(chatModel)) {
if (StringUtils.hasText(chatModel) && LEGACY_TO_NEXT_MODELS.containsKey(chatModel)) {
chatModelData.put("data", LEGACY_TO_NEXT_MODELS.get(chatModel));
}
}
Expand Down

0 comments on commit 7687bbf

Please sign in to comment.