Class OpenAiManager

  • All Implemented Interfaces:
    IAiManagerSPI

    public class OpenAiManager
    extends java.lang.Object
    implements IAiManagerSPI
    Implements IAiManagerSPI using OpenAI services.
    Since:
    16.0.0
    Version:
    $Revision: 26587 $ $Date: 2024-08-26 21:09:17 -0300 (Mon, 26 Aug 2024) $
    • Constructor Summary

      Constructors 
      Constructor Description
      OpenAiManager()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void destroy()
      Destroys this manager.
      java.util.List<java.lang.Float> generateEmbeddings​(java.lang.String text)
      Generates embeddings for the given text.
      com.theokanning.openai.client.OpenAiApi getOpenAiApi()
      Returns an instance of OpenAiApi for accessing OpenAI API.
      void init()
      Initializes this manager.
      boolean isAvailable()
      Returns whether this AI Manager is available to be used.
      void onConfigurationUpdate()
      Called when the AiConfig is updated.
      java.util.concurrent.CompletableFuture<java.lang.String> requestEditHtml​(java.lang.String inputHtml, java.lang.String instruction)
      Request AI to edit a HTML code according to the given instructions.
      java.util.concurrent.CompletableFuture<java.lang.String> requestEditHtmlText​(java.lang.String inputHtml, java.lang.String instruction)
      Request AI to edit the text inside a HTML code according to the given instructions.
      java.util.concurrent.CompletableFuture<java.lang.String> requestEditText​(java.lang.String inputText, java.lang.String instruction)
      Request AI to edit a text according to the given instructions.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • OpenAiManager

        public OpenAiManager()
    • Method Detail

      • init

        public void init()
        Description copied from interface: IAiManagerSPI
        Initializes this manager. This method is expected to be called during the LumisXP boot process.
        Specified by:
        init in interface IAiManagerSPI
      • destroy

        public void destroy()
        Description copied from interface: IAiManagerSPI
        Destroys this manager. This method frees resources used by this manager. This manager must not be used after this. This method is expected to be called during the LumisXP shutdown process.
        Specified by:
        destroy in interface IAiManagerSPI
      • isAvailable

        public boolean isAvailable()
        Description copied from interface: IAiManagerSPI
        Returns whether this AI Manager is available to be used.
        Specified by:
        isAvailable in interface IAiManagerSPI
        Returns:
        true if this manager is available for use, false if it is not, probably due to missing configuration.
      • getOpenAiApi

        public com.theokanning.openai.client.OpenAiApi getOpenAiApi()
        Returns an instance of OpenAiApi for accessing OpenAI API.
        Returns:
        the OpenAiApi instance to use.
        Throws:
        java.lang.IllegalStateException - if the OpenAiApi is not available to use.
        Since:
        16.0.0
      • requestEditText

        public java.util.concurrent.CompletableFuture<java.lang.String> requestEditText​(java.lang.String inputText,
                                                                                        java.lang.String instruction)
                                                                                 throws PortalException
        Description copied from interface: IAiManagerSPI
        Request AI to edit a text according to the given instructions.
        Specified by:
        requestEditText in interface IAiManagerSPI
        Parameters:
        inputText - the text to edit.
        Returns:
        a future that will contain the resulting edited text.
        Throws:
        PortalException - if the operation could not be executed.
      • requestEditHtml

        public java.util.concurrent.CompletableFuture<java.lang.String> requestEditHtml​(java.lang.String inputHtml,
                                                                                        java.lang.String instruction)
                                                                                 throws PortalException
        Description copied from interface: IAiManagerSPI
        Request AI to edit a HTML code according to the given instructions.
        Specified by:
        requestEditHtml in interface IAiManagerSPI
        Parameters:
        inputHtml - the HTML code to edit.
        Returns:
        a future that will contain the resulting edited HTML code.
        Throws:
        PortalException - if the operation could not be executed.
      • requestEditHtmlText

        public java.util.concurrent.CompletableFuture<java.lang.String> requestEditHtmlText​(java.lang.String inputHtml,
                                                                                            java.lang.String instruction)
                                                                                     throws PortalException
        Description copied from interface: IAiManagerSPI
        Request AI to edit the text inside a HTML code according to the given instructions. Note that the underlying implementation may not give AI details about the HTML, so instructions that are not only about the text and that depends on the HTML structure may fail.
        Specified by:
        requestEditHtmlText in interface IAiManagerSPI
        Parameters:
        inputHtml - the HTML code to edit.
        Returns:
        a future that will contain the resulting edited HTML code.
        Throws:
        PortalException - if the operation could not be executed.