Class ModifyPageReadTool
- java.lang.Object
-
- com.composum.ai.backend.slingbase.experimential.impl.ModifyPageReadTool
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
ModifyPageReadTool.ComponentProperties
static interface
ModifyPageReadTool.Config
protected static class
ModifyPageReadTool.PageProperties
-
Field Summary
Fields Modifier and Type Field Description static Pattern
PATTERN_TWO_SEPARATE_WHITESPACE
Heuristic to detect text attributes.
-
Constructor Summary
Constructors Constructor Description ModifyPageReadTool()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
activate(ModifyPageReadTool.Config config)
protected void
deactivate()
static Stream<org.apache.sling.api.resource.Resource>
descendantsStream(org.apache.sling.api.resource.Resource resource)
Returns a stream that goes through all descendants of a resource, parents come before their children.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 matchAITool.getToolDeclaration()
.boolean
isAllowedFor(org.apache.sling.api.resource.Resource resource)
Whether the tool is enabled for the given resource.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.composum.ai.backend.slingbase.experimential.AITool
makeGPTTool
-
-
-
-
Field Detail
-
PATTERN_TWO_SEPARATE_WHITESPACE
public static final Pattern PATTERN_TWO_SEPARATE_WHITESPACE
Heuristic to detect text attributes.
-
-
Method Detail
-
getName
@Nonnull public String getName(@Nullable Locale locale)
Description copied from interface:AITool
Human readable name.
-
getDescription
@Nonnull public String getDescription(@Nullable Locale locale)
Description copied from interface:AITool
Human readable description.- Specified by:
getDescription
in interfaceAITool
-
getToolName
@Nonnull public String getToolName()
Description copied from interface:AITool
Name for the purpose of calling - must matchAITool.getToolDeclaration()
.- Specified by:
getToolName
in interfaceAITool
-
getToolDeclaration
@Nonnull public String getToolDeclaration()
Description copied from interface:AITool
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 }
- Specified by:
getToolDeclaration
in interfaceAITool
- See Also:
- "https://platform.openai.com/docs/api-reference/chat/create"
-
isAllowedFor
public boolean isAllowedFor(@Nonnull org.apache.sling.api.resource.Resource resource)
Description copied from interface:AITool
Whether the tool is enabled for the given resource.- Specified by:
isAllowedFor
in interfaceAITool
-
execute
@Nonnull public String execute(@Nullable String arguments, @Nonnull org.apache.sling.api.resource.Resource resource, @Nullable com.composum.ai.backend.base.service.chat.GPTCompletionCallback.GPTToolExecutionContext context)
Description copied from interface:AITool
Executes the tool call and returns the result to present to the AI. Must only be called ifAITool.isAllowedFor(Resource)
returned true.
-
descendantsStream
@Nonnull public static Stream<org.apache.sling.api.resource.Resource> descendantsStream(@Nullable org.apache.sling.api.resource.Resource resource)
Returns a stream that goes through all descendants of a resource, parents come before their children.- Parameters:
resource
- a resource or null- Returns:
- a stream running through the resource and it's the descendants, not null
-
activate
protected void activate(ModifyPageReadTool.Config config)
-
deactivate
protected void deactivate()
-
-