Class GenericOaiPromptServiceHandler
- All Implemented Interfaces:
IPromptServiceHandler<GenericOaiConnectionConfig, GenericOaiQueryConfig>, PromptServiceHandlerMixin_JsonConfig<GenericOaiConnectionConfig, GenericOaiQueryConfig>
IPromptServiceHandler implementation for the Generic OAI prompt service.- Since:
- 8.5.0
-
Method Summary
Modifier and TypeMethodDescriptioncomputeQueryInput(IPromptComputeQueryInputParams<GenericOaiConnectionConfig, GenericOaiQueryConfig> params) Given a prompt query, computes the input parameters required to execute the query.computeQueryOutput(IPromptComputeQueryOutputParams<GenericOaiConnectionConfig, GenericOaiQueryConfig> params) Given a prompt query, computes the output parameters that will be returned by theexecutePromptQuerymethod.executePromptQuery(IPromptExecutionParams<GenericOaiConnectionConfig, GenericOaiQueryConfig> params) Executes a prompt query using the given parameters, and returns the result of the query.Gets the class of the connection configuration type parameter.Gets the version of the connection configuration class.Returns the class of the bean that should be used when editing the properties of a prompt connection.This method must return the path to the XHTML page for the custom user interface of a prompt connection.Retrieves the message localizer for custom messages, such as localized messages for the configuration UI.Gets the class of the query configuration type parameter.Gets the version of the query configuration class.Returns the class of the bean that should be used when editing the properties of a prompt query.This method must return the path to the XHTML page for the custom user interface of a prompt query.getType()The technical type of this prompt service.Gets the key for the display description of this type of prompt service, such as "A prompt service that uses OpenAI's GPT-3 model to generate text responses."Gets the display name of this type of prompt service, such as "OpenAI GPT-3" or "Stable Diffusion".Gets the icon that should be used to represent this prompt service, such as in the backend menu.Tests the given prompt service connection to see if it is valid and can be used to execute queries.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface PromptServiceHandlerMixin_JsonConfig
deserializeConnectionConfig, deserializeQueryConfig, newEmptyConnectionConfig, newEmptyQueryConfig, postProcessConnectionConfig, postProcessQueryConfig, preProcessConnectionConfig, preProcessQueryConfig, serializeConnectionConfig, serializeQueryConfig, updateConnectionConfig, updateQueryConfig
-
Method Details
-
computeQueryInput
public IPromptComputeQueryInputRetVal computeQueryInput(IPromptComputeQueryInputParams<GenericOaiConnectionConfig, GenericOaiQueryConfig> params) Description copied from interface:IPromptServiceHandlerGiven a prompt query, computes the input parameters required to execute the query. The engine will provide the parameters to theexecutePromptQuerymethod. The input parameter descriptors are also used for documentation purposes or to generate a user interface for the prompt query workflow action.- Specified by:
computeQueryInputin interfaceIPromptServiceHandler<GenericOaiConnectionConfig, GenericOaiQueryConfig>- Parameters:
params- Parameters to the computation, such as the prompt query.- Returns:
- The list of descriptors for the input of the query.
-
computeQueryOutput
public IPromptComputeQueryOutputRetVal computeQueryOutput(IPromptComputeQueryOutputParams<GenericOaiConnectionConfig, GenericOaiQueryConfig> params) Description copied from interface:IPromptServiceHandlerGiven a prompt query, computes the output parameters that will be returned by theexecutePromptQuerymethod. The output parameter descriptors are e.g. used for documentation purposes; or by the prompt query workflow action to determine which output parameters are available after executing the prompt query.- Specified by:
computeQueryOutputin interfaceIPromptServiceHandler<GenericOaiConnectionConfig, GenericOaiQueryConfig>- Parameters:
params- Parameters to the computation, such as the prompt query.- Returns:
- The list of descriptors for the output of the query.
-
executePromptQuery
public IPromptExecutionRetVal executePromptQuery(IPromptExecutionParams<GenericOaiConnectionConfig, GenericOaiQueryConfig> params) throws PromptExecutionException Description copied from interface:IPromptServiceHandlerExecutes a prompt query using the given parameters, and returns the result of the query.This method is given a value for each parameter as defined by
IPromptServiceHandler.computeQueryInput(IPromptComputeQueryInputParams). The prompt engine ensures all required parameters are present. Optional input parameter may be absent.This method must return a value for each output parameter as defined by
IPromptServiceHandler.computeQueryOutput(IPromptComputeQueryOutputParams). The prompt engine will check that required parameters are present. Optional output parameters may be absent.- Specified by:
executePromptQueryin interfaceIPromptServiceHandler<GenericOaiConnectionConfig, GenericOaiQueryConfig>- Parameters:
params- The parameters for the execution, such as the connection and query configuration, and the values for each input parameter.- Returns:
- The result of the prompt query execution, with the values for each output parameter.
- Throws:
PromptExecutionException- If the execution fails due to some reason, e.g. due to a network error or when the quota limit was exceeded. You should throw one of the subclasses of this exception to indicate the appropriate reason of the failure.ExecutionFailedExceptionis the generic fallback if no more specific exception is available.
-
getConnectionConfigClass
Description copied from interface:IPromptServiceHandlerGets the class of the connection configuration type parameter.The default implementation attempts to read the type of the
ConnectionConfigtype parameter via reflection. If that does not work, or you need to optimize, override this method and return the type directly.- Specified by:
getConnectionConfigClassin interfaceIPromptServiceHandler<GenericOaiConnectionConfig, GenericOaiQueryConfig>
-
getConnectionConfigVersion
Description copied from interface:PromptServiceHandlerMixin_JsonConfigGets the version of the connection configuration class. This is saved in the serialized data. Can be used to update the data if the class definition has undergone changes. If you need to update the serialized data, override theupdateConnectionConfigmethod. Defaults to theserialVersionUIDstatic field of the class, if it exists, or "1.0" otherwise.- Specified by:
getConnectionConfigVersionin interfacePromptServiceHandlerMixin_JsonConfig<GenericOaiConnectionConfig, GenericOaiQueryConfig>- Returns:
- The version of the connection configuration class, as a string.
-
getConnectionViewBeanClass
Description copied from interface:IPromptServiceHandlerReturns the class of the bean that should be used when editing the properties of a prompt connection. May be null if you do not require any bean or custom logic. When you only wish to access the properties of yourconfiguration, you do have to use a custom bean - the model is available via the expression language variablemodel. SeeIPromptServiceHandler.getConnectionViewXhtml()for further details.The default returns null, which uses no extra bean. An extra bean may not be required for simple UIs if you only need to access the properties model.
- Specified by:
getConnectionViewBeanClassin interfaceIPromptServiceHandler<GenericOaiConnectionConfig, GenericOaiQueryConfig>- Returns:
- The class of the bean to use for editing a prompt connection's configuration.
- See Also:
-
getConnectionViewXhtml
Description copied from interface:IPromptServiceHandlerThis method must return the path to the XHTML page for the custom user interface of a prompt connection. Usually the XHTML file is part of the JAR resources of the module or plugin. In this case, you should return a URL to a JAR file resource (jar:file:/...) like so:@Override public URL getConnectionViewXhtml() { return getClass().getResource("/path/to/view.xhtml"); }The contents of this XHTML page is included in the backend menu for prompt connections, already inside a form (i.e. do not add an additional
h:formas that would result in an error). You should wrap your custom UI in a naming container to ensure unique IDs that do not clash with other prompt services. Implementations may (but need not) use the components provided by thehttp://www.xima.de/taglib/xfc/prompttag library. The following is a recommended template on which you may base your UI:<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:ui="http://xmlns.jcp.org/jsf/facelets" xmlns:xp="http://www.xima.de/taglib/xfc/prompt"> <xp:ui id="CHANGE_THIS_TO_A_UNIQUE_ID"> <!-- Custom section with editors specific to your workflow element --> <xp:fieldset legend="#{msg['MyAwesomePromptService.connection.fs.base']}"> <!-- A simple input field for the API key --> <xp:apiKey id="apiKey" value="#{model.apiKey}" required="true"/> </xp:fieldset> </xp:ui> </ui:composition>The XHTML page may access the following expression language variables:
- model: The deserialized configuration of the connection.
- msg: A virtual
ResourceBundlefor the localized messages, backed by themessage localizer. Empty when that method returnsnull. For example, if the resource bundle contains the keyprompt.label, you can access the localized message via the EL expressionmsg['prompt.label'] - bean: An instance of the bean class returned by
getConnectionViewBeanClass. Will be null if that method does not define a bean class.
processandupdateattributes of a<p:ajax />):@promptUi: Resolves to the closest<xp:ui />component from thehttp://www.xima.de/taglib/xfc/prompttag library.@promptFieldset: Resolves to the closest<xp:promptFieldset />component from thehttp://www.xima.de/taglib/xfc/prompttag library.
To access the values of an enum or the constants defined by a class, consider using:
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:o="http://omnifaces.org/ui"> <o:importConstants type="my.fully.classified.path.MyEnum" var="MyEnum" loader="#{model}"/> </ui:composition>Theloaderargument is only required for plugins and ensures that the correct class loader is used that knows about the plugin class. Without the loader attribute, the above is equivalent to the PrimeFaces tag handler<p:importConstants />.- Specified by:
getConnectionViewXhtmlin interfaceIPromptServiceHandler<GenericOaiConnectionConfig, GenericOaiQueryConfig>- Returns:
- Path to the XHTML view, must noe be null. If you do return null, it will be treated as an error and an appropriate message is displayed to the user informing them that the properties panel could not be loaded.
-
getMessageLocalizer
Description copied from interface:IPromptServiceHandlerRetrieves the message localizer for custom messages, such as localized messages for the configuration UI.- Specified by:
getMessageLocalizerin interfaceIPromptServiceHandler<GenericOaiConnectionConfig, GenericOaiQueryConfig>- Returns:
- The resource bundle to use for localized messages.
-
getQueryConfigClass
Description copied from interface:IPromptServiceHandlerGets the class of the query configuration type parameter.The default implementation attempts to read the type of the
QueryConfigtype parameter via reflection. If that does not work, or you need to optimize, override this method and return the type directly.- Specified by:
getQueryConfigClassin interfaceIPromptServiceHandler<GenericOaiConnectionConfig, GenericOaiQueryConfig>
-
getQueryConfigVersion
Description copied from interface:PromptServiceHandlerMixin_JsonConfigGets the version of the query configuration class. This is saved in the serialized data. Can be used to update the data if the class definition has undergone changes. If you need to update the serialized data, override theupdateQueryConfigmethod. Defaults to theserialVersionUIDstatic field of the class, if it exists, or "1.0" otherwise.- Specified by:
getQueryConfigVersionin interfacePromptServiceHandlerMixin_JsonConfig<GenericOaiConnectionConfig, GenericOaiQueryConfig>- Returns:
- The version of the query configuration class, as a string.
-
getQueryViewBeanClass
Description copied from interface:IPromptServiceHandlerReturns the class of the bean that should be used when editing the properties of a prompt query. May benullif you do not require any bean or custom logic. When you only wish to access the properties of yourconfiguration, you do have to use a custom bean - the model is available via the expression language variablemodel. SeeIPromptServiceHandler.getQueryViewXhtml()for further details.The default returns null, which uses no extra bean. An extra bean may not be required for simple UIs if you only need to access the properties model.
- Specified by:
getQueryViewBeanClassin interfaceIPromptServiceHandler<GenericOaiConnectionConfig, GenericOaiQueryConfig>- Returns:
- The class of the bean to use for editing a prompt query's configuration.
- See Also:
-
getQueryViewXhtml
Description copied from interface:IPromptServiceHandlerThis method must return the path to the XHTML page for the custom user interface of a prompt query. Usually the XHTML file is part of the JAR resources of the module or plugin. In this case, you should return a URL to a JAR file resource (jar:file:/...) like so:@Override public URL getQueryViewXhtml() { return getClass().getResource("/path/to/view.xhtml"); }The contents of this XHTML page is included in the backend menu for prompt queries, already inside a form (i.e. do not add an additional
h:formas that would result in an error). You should wrap your custom UI in a naming container to ensure unique IDs that do not clash with other prompt services. Implementations may (but need not) use the components provided by thehttp://www.xima.de/taglib/xfc/prompttag library. The following is a recommended template on which you may base your UI:<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:ui="http://xmlns.jcp.org/jsf/facelets" xmlns:xp="http://www.xima.de/taglib/xfc/prompt"> <xp:ui id="CHANGE_THIS_TO_A_UNIQUE_ID"> <!-- Custom section for the UI of your prompt queries --> <xp:fieldset legend="#{msg['MyAwesomePromptService.prompt.fs.base']}> <!-- A simple select field for the type of the task --> <xp:task id="task" value="#{model.task}" options="#{bean.taskTypeOptions}"> <p:ajax global="false" listener="#{bean.onPromptQueryParamFieldChanged}" process="@this,@promptUi:taskConfig" update="@promptUi:taskConfig" /> </xp:task> </xp:fieldset> </xp:ui> </xp:composition>The XHTML page may access the following expression language variables:
- model: The deserialized configuration of the query.
- msg: A virtual
ResourceBundlefor the localized messages, backed by themessage localizer. Empty when that method returnsnull. For example, if the resource bundle contains the keyprompt.label, you can access the localized message via the EL expressionmsg['prompt.label'] - bean: An instance of the bean class returned by
getQueryViewBeanClass. Will be null if that method does not define a bean class.
processandupdateattributes of a<p:ajax />):@promptUi: Resolves to the closest<xp:ui />component from thehttp://www.xima.de/taglib/xfc/prompttag library.@promptFieldset: Resolves to the closest<xp:promptFieldset />component from thehttp://www.xima.de/taglib/xfc/prompttag library.
To access the values of an enum or the constants defined by a class, consider using:
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:o="http://omnifaces.org/ui"> <o:importConstants type="my.fully.classified.path.MyEnum" var="MyEnum" loader="#{model}"/> </ui:composition>Theloaderargument is only required for plugins and ensures that the correct class loader is used that knows about the plugin class. Without the loader attribute, the above is equivalent to the PrimeFaces tag handler<p:importConstants />.- Specified by:
getQueryViewXhtmlin interfaceIPromptServiceHandler<GenericOaiConnectionConfig, GenericOaiQueryConfig>- Returns:
- Path to the XHTML view, must noe be null. If you do return null, it will be treated as an error and an appropriate message is displayed to the user informing them that the properties panel could not be loaded.
-
getType
Description copied from interface:IPromptServiceHandlerThe technical type of this prompt service. Must be unique across all prompt services, including built-in and plugin services. For plugins, we recommend using a prefix to avoid clashes with built-in services and other plugin services, such as the group and artifact ID of the plugin.- Specified by:
getTypein interfaceIPromptServiceHandler<GenericOaiConnectionConfig, GenericOaiQueryConfig>- Returns:
- The type of the prompt service.
-
getTypeDisplayDescriptionKey
Description copied from interface:IPromptServiceHandlerGets the key for the display description of this type of prompt service, such as "A prompt service that uses OpenAI's GPT-3 model to generate text responses." This might be shown in the prompt service selection UI, to provide further details forIPromptServiceHandler.getTypeDisplayNameKey().The returned key will be localized via
IPromptServiceHandler.getMessageLocalizer().- Specified by:
getTypeDisplayDescriptionKeyin interfaceIPromptServiceHandler<GenericOaiConnectionConfig, GenericOaiQueryConfig>- Returns:
- The display description of the prompt service, localized for the given locale.
-
getTypeDisplayNameKey
Description copied from interface:IPromptServiceHandlerGets the display name of this type of prompt service, such as "OpenAI GPT-3" or "Stable Diffusion". Might e.g. be shown when the user select a prompt service type.The returned key will be localized via
IPromptServiceHandler.getMessageLocalizer().- Specified by:
getTypeDisplayNameKeyin interfaceIPromptServiceHandler<GenericOaiConnectionConfig, GenericOaiQueryConfig>- Returns:
- The display name of the prompt service, localized for the given locale.
-
getTypeIcon
Description copied from interface:IPromptServiceHandlerGets the icon that should be used to represent this prompt service, such as in the backend menu. The default implementation returns a default neutral icon.- Specified by:
getTypeIconin interfaceIPromptServiceHandler<GenericOaiConnectionConfig, GenericOaiQueryConfig>- Returns:
- The icon to use for this prompt service. Must not be null.
-
testConnection
public IPromptTestConnectionRetVal testConnection(IPromptTestConnectionParams<GenericOaiConnectionConfig> params) Description copied from interface:IPromptServiceHandlerTests the given prompt service connection to see if it is valid and can be used to execute queries.- Specified by:
testConnectionin interfaceIPromptServiceHandler<GenericOaiConnectionConfig, GenericOaiQueryConfig>- Parameters:
params- The parameters for the test connection, with the connection configuration and any additional data needed.- Returns:
- The result of the test connection, with the success status and any error messages.
-