Interface AITool

  • All Known Implementing Classes:
    GetPageMarkdownAITool, SearchPageAITool

    public interface AITool
    An action the AI can perform - likely from the sidebar chat.
    See Also:
    "https://platform.openai.com/docs/guides/function-calling"
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      String execute​(String arguments, org.apache.sling.api.resource.Resource resource, com.composum.ai.backend.base.service.chat.GPTCompletionCallback.GPTToolExecutionContext context)
      Executes the tool call and returns the result to present to the AI.
      String getDescription​(Locale locale)
      Human readable description.
      String getName​(Locale locale)
      Human readable name.
      String getToolDeclaration()
      The description to use for the OpenAI tool call.
      String getToolName()
      Name for the purpose of calling - must match getToolDeclaration().
      boolean isAllowedFor​(org.apache.sling.api.resource.Resource resource)
      Whether the tool is enabled for the given resource.
      default com.composum.ai.backend.base.service.chat.GPTTool makeGPTTool​(org.apache.sling.api.resource.Resource resource, org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response)
      The form useable by GPTChatCompletionService.
    • Method Detail

      • getToolDeclaration

        @Nonnull
        String getToolDeclaration()
        The description to use for the OpenAI tool call. Will be inserted into the OpenAI tools array. E.g.:
               {
                 "type": "function",
                 "function": {
                   "name": "get_delivery_date",
                   "description": "Get the delivery date for a customer's order. Call this whenever you need to know the delivery date, for example when a customer asks 'Where is my package'",
                   "parameters": {
                     "type": "object",
                     "properties": {
                       "order_id": {
                         "type": "string",
                         "description": "The customer's order ID."
                       }
                     },
                     "required": ["order_id"],
                     "additionalProperties": false
                   }
                 },
                 "strict": true
               }
         
        See Also:
        "https://platform.openai.com/docs/api-reference/chat/create"
      • isAllowedFor

        boolean isAllowedFor​(@Nonnull
                             org.apache.sling.api.resource.Resource resource)
        Whether the tool is enabled for the given resource.
      • execute

        @Nonnull
        String execute​(@Nullable
                       String arguments,
                       @Nonnull
                       org.apache.sling.api.resource.Resource resource,
                       @Nullable
                       com.composum.ai.backend.base.service.chat.GPTCompletionCallback.GPTToolExecutionContext context)
        Executes the tool call and returns the result to present to the AI. Must only be called if isAllowedFor(Resource) returned true.
      • makeGPTTool

        @Nullable
        default com.composum.ai.backend.base.service.chat.GPTTool makeGPTTool​(@Nonnull
                                                                              org.apache.sling.api.resource.Resource resource,
                                                                              @Nonnull
                                                                              org.apache.sling.api.SlingHttpServletRequest request,
                                                                              @Nonnull
                                                                              org.apache.sling.api.SlingHttpServletResponse response)
        The form useable by GPTChatCompletionService.