Package lumis.portal.ai.openai
Class OpenAiManager
- java.lang.Object
-
- lumis.portal.ai.openai.OpenAiManager
-
- All Implemented Interfaces:
IAiManagerSPI
public class OpenAiManager extends java.lang.Object implements IAiManagerSPI
ImplementsIAiManagerSPI
using OpenAI services.- Since:
- 16.0.0
- Version:
- $Revision: 26156 $ $Date: 2024-01-13 10:26:46 -0300 (Sat, 13 Jan 2024) $
-
-
Field Summary
-
Fields inherited from interface lumis.portal.ai.IAiManagerSPI
PROPERTY_AI_ENABLED
-
-
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 ofOpenAiApi
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 theAiConfig
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
-
Methods inherited from interface lumis.portal.ai.IAiManagerSPI
isAiEnabled
-
-
-
-
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 interfaceIAiManagerSPI
-
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 interfaceIAiManagerSPI
-
isAvailable
public boolean isAvailable()
Description copied from interface:IAiManagerSPI
Returns whether this AI Manager is available to be used.- Specified by:
isAvailable
in interfaceIAiManagerSPI
- Returns:
true
if this manager is available for use,false
if it is not, probably due to missing configuration.
-
onConfigurationUpdate
public void onConfigurationUpdate()
Description copied from interface:IAiManagerSPI
Called when theAiConfig
is updated.- Specified by:
onConfigurationUpdate
in interfaceIAiManagerSPI
-
getOpenAiApi
public com.theokanning.openai.client.OpenAiApi getOpenAiApi()
Returns an instance ofOpenAiApi
for accessing OpenAI API.- Returns:
- the
OpenAiApi
instance to use. - Throws:
java.lang.IllegalStateException
- if theOpenAiApi
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 interfaceIAiManagerSPI
- 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 interfaceIAiManagerSPI
- 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 interfaceIAiManagerSPI
- 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.
-
generateEmbeddings
public java.util.List<java.lang.Float> generateEmbeddings(java.lang.String text) throws PortalException
Description copied from interface:IAiManagerSPI
Generates embeddings for the given text.- Specified by:
generateEmbeddings
in interfaceIAiManagerSPI
- Parameters:
text
- the text.- Returns:
- the embeddings.
- Throws:
PortalException
-
-