Skip to content

Commit

Permalink
#29381 removing the async calls on ia actionlets
Browse files Browse the repository at this point in the history
  • Loading branch information
jdotcms committed Jul 29, 2024
1 parent c36af68 commit b9d2a39
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public List<WorkflowActionletParameter> getParameters() {
"<br>and the keys of the json object will be used to update the content fields.", "", false),
overwriteParameter,
new WorkflowActionletParameter(OpenAIParams.OPEN_AI_PROMPT.key, "The prompt that will be sent to the AI", "We need an attractive search result in Google. Return a json object that includes the fields \"pageTitle\" for a meta title of less than 55 characters and \"metaDescription\" for the meta description of less than 300 characters using this content:\\n\\n${fieldContent}\\n\\n", true),
new WorkflowActionletParameter(OpenAIParams.RUN_DELAY.key, "Update the content asynchronously, after X seconds. O means run in-process", "5", true),
new WorkflowActionletParameter(OpenAIParams.MODEL.key, "The AI model to use, defaults to " + ConfigService.INSTANCE.config().getConfig(AppKeys.MODEL), ConfigService.INSTANCE.config().getConfig(AppKeys.MODEL), false),
new WorkflowActionletParameter(OpenAIParams.TEMPERATURE.key, "The AI temperature for the response. Between .1 and 2.0. Defaults to " + ConfigService.INSTANCE.config().getConfig(AppKeys.COMPLETION_TEMPERATURE), ConfigService.INSTANCE.config().getConfig(AppKeys.COMPLETION_TEMPERATURE), false)
);
Expand All @@ -58,22 +57,9 @@ public String getHowTo() {

@Override
public void executeAction(WorkflowProcessor processor, Map<String, WorkflowActionClassParameter> params) throws WorkflowActionFailureException {
int delay = Try.of(() -> Integer.parseInt(params.get(OpenAIParams.RUN_DELAY.key).getValue())).getOrElse(5);

Runnable task = new AsyncWorkflowRunnerWrapper(new OpenAIContentPromptRunner(processor, params));
if (delay > 0) {
OpenAIThreadPool.schedule(task, delay , TimeUnit.SECONDS);
final SystemMessageBuilder message = new SystemMessageBuilder().setMessage("Content being generated in the background")
.setLife(3000)
.setType(MessageType.SIMPLE_MESSAGE)
.setSeverity(MessageSeverity.SUCCESS);

SystemMessageEventUtil.getInstance().pushMessage(message.create(), List.of(processor.getUser().getUserId()));
} else {
task.run();
}


final Runnable task = new OpenAIContentPromptRunner(processor, params);
task.run();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,9 @@ public String getHowTo() {
@Override
public void executeAction(WorkflowProcessor processor, Map<String, WorkflowActionClassParameter> params) throws WorkflowActionFailureException {

int delay = Try.of(() -> Integer.parseInt(params.get(OpenAIParams.RUN_DELAY.key).getValue())).getOrElse(5);

Runnable task = new AsyncWorkflowRunnerWrapper(new OpenAIGenerateImageRunner(processor, params));
if (delay > 0) {
OpenAIThreadPool.schedule(task, delay, TimeUnit.SECONDS);
final SystemMessageBuilder message = new SystemMessageBuilder().setMessage("Image being generated in the background").setLife(3000).setType(MessageType.SIMPLE_MESSAGE).setSeverity(MessageSeverity.SUCCESS);

SystemMessageEventUtil.getInstance().pushMessage(message.create(), List.of(processor.getUser().getUserId()));
} else {
task.run();
}
final Runnable task = new OpenAIGenerateImageRunner(processor, params);
task.run();
}


Expand Down

0 comments on commit b9d2a39

Please sign in to comment.