Class AITemplatingServlet

  • All Implemented Interfaces:
    Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

    public class AITemplatingServlet
    extends org.apache.sling.api.servlets.SlingAllMethodsServlet
    Servlet providing services related to templating. Exports the methods of AITemplatingService via 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
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      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.
      protected void doPost​(org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response)  
      protected void replacePromptsInResource​(org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response)  
      protected void resetToPrompts​(org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response)  
      protected void writeToResponse​(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
      • Methods inherited from class javax.servlet.GenericServlet

        destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletName, init, init, log, log
    • 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
    • Constructor Detail

      • AITemplatingServlet

        public AITemplatingServlet()
    • Method Detail

      • doPost

        protected void doPost​(org.apache.sling.api.SlingHttpServletRequest request,
                              org.apache.sling.api.SlingHttpServletResponse response)
                       throws javax.servlet.ServletException,
                              IOException
        Overrides:
        doPost in class org.apache.sling.api.servlets.SlingAllMethodsServlet
        Throws:
        javax.servlet.ServletException
        IOException
      • 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