Class AIServlet

  • All Implemented Interfaces:
    com.composum.sling.core.service.RestrictedService, Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

    public class AIServlet
    extends com.composum.sling.core.servlet.AbstractServiceServlet
    Servlet providing the various services from the backend as servlet, which are useable for the authors.
    See Also:
    Serialized Form
    • Field Detail

      • PARAMETER_TEXT

        public static final String PARAMETER_TEXT
        Parameter to transmit a text on which ChatGPT is to operate - not as instructions but as data.
        See Also:
        Constant Field Values
      • PARAMETER_INPUT_IMAGE_PATH

        public static final String PARAMETER_INPUT_IMAGE_PATH
        Parameter to transmit a path to an image instead of a text.
        See Also:
        Constant Field Values
      • PARAMETER_PROMPT

        public static final String PARAMETER_PROMPT
        Parameter to transmit a prompt on which ChatGPT is to operate - that is, the instructions. If there is a PARAMETER_CHAT given, this is the first prompt *before* the chat - the last message of the chat is the last prompt.
        See Also:
        Constant Field Values
      • PARAMETER_CHAT

        public static final String PARAMETER_CHAT
        Parameter to transmit additional chat after PARAMETER_PROMPT. The last message of the chat is the last prompt. Format: array of serialized GPTChatMessage. E.g. [{"role":"assistant","content":"Answer 1"},{"role":"user","content":"Another question"}].
        See Also:
        Constant Field Values
      • PARAMETER_MAXWORDS

        public static final String PARAMETER_MAXWORDS
        Optional numerical parameter limiting the number of words to be generated. That might lead to cutoff or actual wordcount, depending on the operation, and is usually only quite approximate.
        See Also:
        Constant Field Values
      • PARAMETER_MAXTOKENS

        public static final String PARAMETER_MAXTOKENS
        Optional numerical parameter limiting the number of tokens (about 3/4 english word on average) to be generated. That might lead to cutoff, as this is a hard limit and ChatGPT doesn't know about that during generation. So it's advisable to specify the desired text length in the prompt, too.
        See Also:
        Constant Field Values
      • PARAMETER_PATH

        public static final String PARAMETER_PATH
        The path to a resource, given as parameter.
        See Also:
        Constant Field Values
      • RESULTKEY

        public static final String RESULTKEY
        Key for Status.data(String) - toplevel key in the servlet result.
        See Also:
        Constant Field Values
      • RESULTKEY_DESCRIPTION

        public static final String RESULTKEY_DESCRIPTION
        Key in the result that transmits the generated description.
        See Also:
        Constant Field Values
      • RESULTKEY_KEYWORDS

        public static final String RESULTKEY_KEYWORDS
        Key in the result that transmits the generated list of keywords.
        See Also:
        Constant Field Values
      • RESULTKEY_TEXT

        public static final String RESULTKEY_TEXT
        Key in the result that transmits the generated text.
        See Also:
        Constant Field Values
      • RESULTKEY_TRANSLATION

        public static final String RESULTKEY_TRANSLATION
        Key in the result that transmits a list of translations (currently only one, but might be extended later.)
        See Also:
        Constant Field Values
      • RESULTKEY_FINISHREASON

        public static final String RESULTKEY_FINISHREASON
        Used to transmit whether the response was complete (finishreason GPTFinishReason.STOP or length restriction GPTFinishReason.LENGTH). Lowercase String.
        See Also:
        Constant Field Values
      • PARAMETER_CONFIGBASEPATH

        public static final String PARAMETER_CONFIGBASEPATH
        Parameter containing the path of the page, for determining the configuration.
        See Also:
        Constant Field Values
      • SESSIONKEY_STREAMING

        public static final String SESSIONKEY_STREAMING
        Session contains a map at this key that maps the streamids to the streaming handle.
      • translationService

        protected com.composum.ai.backend.base.service.chat.GPTTranslationService translationService
      • contentCreationService

        protected com.composum.ai.backend.base.service.chat.GPTContentCreationService contentCreationService
      • markdownService

        protected com.composum.ai.backend.slingbase.ApproximateMarkdownService markdownService
      • configurationService

        protected com.composum.ai.backend.slingbase.AIConfigurationService configurationService
      • bundleContext

        protected org.osgi.framework.BundleContext bundleContext
      • gson

        protected com.google.gson.Gson gson
    • Constructor Detail

      • AIServlet

        public AIServlet()
    • Method Detail

      • getOperations

        protected com.composum.sling.core.servlet.ServletOperationSet<AIServlet.Extension,​AIServlet.Operation> getOperations()
        Specified by:
        getOperations in class com.composum.sling.core.servlet.AbstractServiceServlet
      • init

        public void init()
                  throws javax.servlet.ServletException
        Overrides:
        init in class javax.servlet.GenericServlet
        Throws:
        javax.servlet.ServletException
      • activate

        public void activate​(org.osgi.framework.BundleContext bundleContext)
      • retrieveStream

        protected EventStream retrieveStream​(String streamId,
                                             org.apache.sling.api.SlingHttpServletRequest request)