Extending Interaction Actions
Implementing Interaction Types
Concrete implementations for generating results is done via Interaction Types and referenced with the type
option in the
configuration. To implement an interaction type, implement InteractionTypeInterface
and register class as service in
symfony container with tag pimcore.copilot.interaction_type
.
Pimcore\Bundle\PimcoreCopilotBundle\InteractionAction\OpenAiTextPrompt:
tags:
- { name: "pimcore.copilot.interaction_type" }
All tagged services are registered to a factory with service name as a key. This factory is used by Pimcore Copilot to instantiate needed interaction type implementations based on their type. Mapping between configuration and implementation is done via service name of interaction type.
Interaction type implementation also defines then what JS component to be used. A chatInteractionAdapter
is available.
More complex use cases might require more sophisticated implementations.
Implemented Sample
Implemented sample utilizes ChatGPT
for generating text and applying it to a data object data field. Sample configuration
looks as follows:
pimcore_copilot:
interaction_actions:
actions:
event_description_generation:
context_limitations: ['object_event']
search_terms: ['event description', 'generate description']
type: 'Pimcore\Bundle\PimcoreCopilotBundle\InteractionAction\OpenAiTextPrompt'
configuration:
template: |
We have an event with title {{ subject.title }} that starts at {{ subject.fromDate }} and ends at {{ subject.toDate }}.
{%% if subject.description %%}
Optimize following description and include all information: {{ subject.description | raw }}
{%% else %%}
Generate a short description for that event.
{%% endif %%}
model: 'gpt-4o'
target_field: 'description'
target_field_localized: true
icon: null
Inline Help Data
To add inline help data for your custom interaction action, you need to provide a twig template that will be used to render the help data in the UI.
Therefore, you need to implement the Pimcore\Bundle\CopilotBundle\InlineHelpData\InlineHelpDataInterface
with your custom interaction action.
The interface contains a getInlineHelpTemplateFileName
method that returns the path and name of the twig template.
Example:
public function getInlineHelpTemplateFileName(): string
{
return '@PimcoreCopilot/InlineHelp/InteractionAction/Type/open_ai_text_prompt.html.twig';
}
Result: