Class AITemplatingServlet
- java.lang.Object
-
- javax.servlet.GenericServlet
-
- org.apache.sling.api.servlets.SlingSafeMethodsServlet
-
- org.apache.sling.api.servlets.SlingAllMethodsServlet
-
- com.composum.ai.backend.slingbase.experimential.AITemplatingServlet
-
- All Implemented Interfaces:
Serializable,javax.servlet.Servlet,javax.servlet.ServletConfig
public class AITemplatingServlet extends org.apache.sling.api.servlets.SlingAllMethodsServletServlet providing services related to templating. Exports the methods ofAITemplatingServicevia a servlet. URL is /bin/cpm/ai/experimental/templating.{methodname}.json (Apache Sling conform), POST only, returns JSON, currently only a string message telling whether it was successful. All parameters of the methods are passed HTML form style (application/x-www-form-urlencoded).- See Also:
- "10PageTemplating.md", Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classAITemplatingServlet.Method
-
Field Summary
Fields Modifier and Type Field Description protected com.google.gson.Gsongsonstatic StringPARAM_ADDITIONAL_PROMPTParameter that gives an additional prompt to add to the AI request.static StringPARAM_ADDITIONAL_URLSParameter that gives additional URLs or paths to pages with background information to provide data to the AI.static StringPARAM_BACKGROUND_INFORMATIONParameter that gives additional background information to provide data to the AI (not a prompt!).static StringPARAM_RESOURCE_PATHParameter that gives the page to transform.
-
Constructor Summary
Constructors Constructor Description AITemplatingServlet()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected StringcollectBackgroundInfoPaths(org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response, List<URI> additionalUrls)If some of the URLs are paths, we read the markdown for those pages.protected voiddoPost(org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response)protected voidreplacePromptsInResource(org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response)protected voidresetToPrompts(org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response)protected voidwriteToResponse(com.google.gson.stream.JsonWriter writer, org.apache.sling.api.SlingHttpServletResponse response, boolean success, boolean changes, String message)-
Methods inherited from class org.apache.sling.api.servlets.SlingAllMethodsServlet
doDelete, doPut, getAllowedRequestMethods, isMethodValid, mayService
-
Methods inherited from class org.apache.sling.api.servlets.SlingSafeMethodsServlet
doGeneric, doGet, doHead, doOptions, doTrace, getServletInfo, handleMethodNotImplemented, service, service
-
-
-
-
Field Detail
-
PARAM_RESOURCE_PATH
public static final String PARAM_RESOURCE_PATH
Parameter that gives the page to transform.- See Also:
- Constant Field Values
-
PARAM_ADDITIONAL_PROMPT
public static final String PARAM_ADDITIONAL_PROMPT
Parameter that gives an additional prompt to add to the AI request.- See Also:
- Constant Field Values
-
PARAM_ADDITIONAL_URLS
public static final String PARAM_ADDITIONAL_URLS
Parameter that gives additional URLs or paths to pages with background information to provide data to the AI.- See Also:
- Constant Field Values
-
PARAM_BACKGROUND_INFORMATION
public static final String PARAM_BACKGROUND_INFORMATION
Parameter that gives additional background information to provide data to the AI (not a prompt!).- See Also:
- Constant Field Values
-
gson
protected final com.google.gson.Gson gson
-
-
Method Detail
-
doPost
protected void doPost(org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response) throws javax.servlet.ServletException, IOException- Overrides:
doPostin classorg.apache.sling.api.servlets.SlingAllMethodsServlet- Throws:
javax.servlet.ServletExceptionIOException
-
replacePromptsInResource
protected void replacePromptsInResource(org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response) throws IOException- Throws:
IOException
-
collectBackgroundInfoPaths
protected String collectBackgroundInfoPaths(org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response, List<URI> additionalUrls)
If some of the URLs are paths, we read the markdown for those pages. This cannot be done in the service easily since we need the request and response objects for generating the markdown.
-
writeToResponse
protected void writeToResponse(com.google.gson.stream.JsonWriter writer, org.apache.sling.api.SlingHttpServletResponse response, boolean success, boolean changes, String message) throws IOException- Throws:
IOException
-
resetToPrompts
protected void resetToPrompts(org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response) throws IOException- Throws:
IOException
-
-