Welcome to Tech Mastery, your expert source for insights into technology and digital strategy. Explore topics like Adobe Experience Manager, AWS, Azure, generative AI, and advanced marketing strategies. Delve into MACH architecture, Jamstack, modern software practices, DevOps, and SEO. Our blog is ideal for tech professionals and enthusiasts eager to stay ahead in digital innovations, from Content Management to Digital Asset Management and beyond.
You may get the following error while using the AEM mail action to send the details captured through an AEM form(form built based on AEM foundation or core form components)
org.apache.sling.auth.core.AuthUtil isRedirectValid: Redirect target must not be an URL
This error can happen in multiple scenarios; some are below
Defining the external page as the Thank you page for the form - AEM Mail Servlet won't support external URLs as the thank you page due to security restriction
Defining the internal AEM page with complete URL, including protocol and domain - Even though the AEM page sites inside the AEM, as you specified the full URL, the mail servlet treat the URL as external.
Mismatch in the etc. map configuration - The etc. map configuration will help you to map the content path to the complete URLs - domain mapping with shortened URL based on your setup; if your etc. map configuration is enabled with the upper case for the domain names(e.g., www.Test.com), then you will see this issue even though only the content path specified as the thank you page. The reason is the Mail servlet URL comparison is case sensitive, even though the form URL and the thank you page URL are enabled through the same domain.
Apache Sling :: Connection Timeout Agent provides a Java agent that uses the instrumentation API to add connect and read timeouts to connections made via HTTP or HTTPs. It only applies these timeouts if none were set explicitly.
Connection Timeout Agent:
The agent is intended as an additional layer of control when running untrusted client code that may make calls without explicitly setting timeouts. Setting timeouts in client code is always recommended rather than relying on this agent.
It currently supports setting timeouts for HTTP connections done using:
I am using the snapshot version for testing with Connect timeout as 20 secs and Read time out as 60 secs (Copy org.apache.sling.connection-timeout-agent-1.0.3-SNAPSHOT-jar-with-dependencies.jar next to the AEM jar file)
Yes, the connection started failing every time; it started working without any issue when I set 20 seconds as the Connection timeout and 60 seconds as the read timeout.
org.apache.http.conn.ConnectTimeoutException: Connectto api.openai.com:443 [api.openai.com/, api.openai.com/] failed: connect timed out
The configurations can be monitored through JMX — org.apache.sling.cta
The AMS started enabling the connection timeout agent for the customers hosted on the AMS platform — The default connectiontimeout will be set to 20 seconds, and the default read timeout will be set to 60 seconds. But you can work with the AMS team to adjust the timeout values based on your custom need. The agent can be configured in on-prem/custom cloud-hosted versions of AEM if required.
I assume AEM as Cloud Services by default enabled with the Connection Time out agent — These timeout values are 10 seconds for connect calls and 60 seconds for read calls for connections. Refer to AEM as a Cloud Service Development Guidelines | Adobe Experience Manager (Outgoing HTTP Connections) for more details; not sure if the customers can adjust the global timeout values.
Anyhow recommended to always set the connection and read time outs in the code as the global configurations can lead to different issues.
ChatGPT is an AI language model developed by OpenAI, capable of generating human-like text based on input. The model is trained on a large corpus of text data and can generate responses to questions, summarize long texts, write stories, and much more.
The OpenAI API can integrate AI models with different systems.
AEM already enables some of the Generative AI capabilities like — Content Creation, Summarization, rewriting, etc., also Adobe Integrate Adobe Firefly (a range of creative AI models to AEM DAM) to simplify content creation and management. I will explain this in more detail in another post.
Integrating AEM with ChatGPT empowers content authors to easily create content that meets the SEO requirements, e.g., create a title/description for a page, create a story on a topic, summarize the content, etc.; the ChatGPT generated content can be optimized further based on the need.
In this post, let us see how to integrate AEM with ChatGPT to empower the authors with content authoring.
As a first step, enable a servlet connecting the chatgpt model with the user prompt and returning the response.
Change the gpt model based on your need, gpt-3.5-turbo is the latest model currently available for API access; the model details can be found Models — OpenAI API
The ‘role’ can take one of three values: ‘system’, ‘user’ or the ‘assistant’.
These roles help define the context of the conversation; even you can specify the previous conversation context by adding messages with different roles, user — the message sent by the user, and assistant — the response from API.
Not mandatory to specify all the roles; I have used only the user role to generate the response; you can use other roles to give more context to the conversation.
max_tokens — specifies the maximum number of tokens the API should generate in response to a prompt. Tokens are the individual words and punctuation marks that make up the text. Adjust the max_tokens based on your prompts and the expected response.
Replace <Open API Token> in the servlet with the actual token; ensure the token is secured, and you can keep the token as an OSGI configuration.
The API is billed based on the token usage; some free tokens are enabled for initial API testing; after that, you should enable the billing details to use the API.
The servlet can be invoked from components, pages, or toolbars to generate the required content.
In this post lets us see how to add a button on the title component edit toolbar to integrate with the above servlet to generate the content whenever required — the condition on the action can be changed to enable the chatgpt action on all the components or specific components (also the servlet can be invoked in multiple other ways).
Create a client library under your project with the below JS and add cq.authoring.editor.sites.page.hook for the categories.
var chatgptAction = new Granite.author.ui.ToolbarAction({ name: ACTION_NAME, icon: ACTION_ICON, text: ACTION_TITLE, execute: function (editable) { showDialog(); }, condition: function (editable) { return editable && editable.type ==="chatgptintegration/components/title"; }, isNonMulti: true, });
channel.on("cq-layer-activated", function (event) { if (event.layer ==="Edit") { Granite.author.EditorFrame.editableToolbar.registerAction("CHATGPT", chatgptAction); } });
function showDialog() { // Create the dialog var dialog = new Coral.Dialog().set({ id: 'chatgptDialog', header: { innerHTML: 'GenerateContent through ChatGPT' }, content: { innerHTML: '<form class="coral-Form coral-Form--vertical"><section class="coral-Form-fieldset"><div class="coral-Form-fieldwrapper"><textarea is="coral-textarea"class="coral-Form-field" placeholder="Enter your prompt" id="textarea1" name="name"></textarea></div><div class="coral-Form-fieldwrapper"><textarea is="coral-textarea"class="coral-Form-field" placeholder="Result will be displayed here" id="textarea2" name="name"></textarea></div></section></form>' }, footer: { innerHTML: '<button is="coral-button" variant="primary">Generate</button><button is="coral-button" variant="primary" coral-close>Close</button>' } });
// Add an event listener to the submit button dialog.footer.querySelector("button").addEventListener("click", function () { var textarea1Value = dialog.content.querySelector("#textarea1").value; var servletUrl ="/bin/chat?prompt="+ encodeURIComponent(textarea1Value);
// Send a request to the servlet var xhr = new XMLHttpRequest(); xhr.open("GET", servletUrl); xhr.onreadystatechange = function () { if (xhr.readyState ===XMLHttpRequest.DONE&& xhr.status ===200) { dialog.content.querySelector("#textarea2").value = xhr.responseText; } }; xhr.send(); });
// Open the dialog document.body.appendChild(dialog); dialog.show(); } })(jQuery, jQuery(document), this);
js.txt
#base=js ToolbarAction.CHATGPT.js
Now the Title component edit toolbar displays the chatgpt actions.
Clicking on the action will display the dialog to generate the required content through the chatgpt integration.
Enter the prompt for generating the content and Click on Generate button.
Now the authors can use the chatgpt integration to perform the different content operations through ChatGPT —Generate the content, Summarize, generate a title, generate a description, etc.; modify the content based on the business context.
AEM already enables some of the Generative AI capabilities like — Content Creation, Summarization, rewriting, etc., also Adobe Integrate Adobe Firefly (a range of creative AI models to AEM DAM) to simplify content creation and management. I will explain this in more detail in another post.