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.SlingAllMethodsServlet
Servlet providing services related to templating. Exports the methods ofAITemplatingService
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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
AITemplatingServlet.Method
-
Field Summary
Fields Modifier and Type Field Description protected com.google.gson.Gson
gson
static String
PARAM_ADDITIONAL_PROMPT
Parameter that gives an additional prompt to add to the AI request.static String
PARAM_ADDITIONAL_URLS
Parameter that gives additional URLs or paths to pages with background information to provide data to the AI.static String
PARAM_BACKGROUND_INFORMATION
Parameter that gives additional background information to provide data to the AI (not a prompt!).static String
PARAM_RESOURCE_PATH
Parameter 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 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
-
-
-
-
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:
doPost
in classorg.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
-
-