| 1 |
<?php |
| 2 |
/** |
| 3 |
* Abilities |
| 4 |
* |
| 5 |
* @package AutomatorWP\AI_Assistant\Abilities |
| 6 |
* @since 1.0.0 |
| 7 |
* @version 1.0.0 |
| 8 |
*/ |
| 9 |
// Exit if accessed directly |
| 10 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 11 |
|
| 12 |
/** |
| 13 |
* Get the system instructions |
| 14 |
* |
| 15 |
* @since 1.0.0 |
| 16 |
*/ |
| 17 |
function automatorwp_ai_assistant_get_system_instructions() { |
| 18 |
|
| 19 |
$system_instructions = array( |
| 20 |
"You are an AI assistant for AutomatorWP.", |
| 21 |
"Be helpful, precise, and professional.", |
| 22 |
"You have strict catalog restrictions due to ability parameters.", |
| 23 |
"Do not guess slugs for triggers or actions.", |
| 24 |
"Always use the listed abilities to perform tasks instead of guessing or pretending.", |
| 25 |
"Do not generate a text response after using abilities. They already return one.", |
| 26 |
); |
| 27 |
|
| 28 |
/** |
| 29 |
* Filter to override the system instructions |
| 30 |
* |
| 31 |
* @since 1.0.0 |
| 32 |
* |
| 33 |
* @param string $system_instructions |
| 34 |
* |
| 35 |
* @return string |
| 36 |
*/ |
| 37 |
return apply_filters( 'automatorwp_ai_assistant_get_system_instructions', implode( "\n", $system_instructions ) ); |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Register abilities category |
| 42 |
* |
| 43 |
* @since 1.0.0 |
| 44 |
*/ |
| 45 |
function automatorwp_ai_assistant_register_category() { |
| 46 |
if ( ! function_exists( 'wp_register_ability_category' ) ) return; |
| 47 |
|
| 48 |
wp_register_ability_category( 'automatorwp', array( |
| 49 |
'label' => __( 'AutomatorWP', 'automatorwp' ), |
| 50 |
'description' => __( 'Ability to manage, create and design AutomatorWP elements such as points, achievements and ranks using AI.', 'automatorwp' ), |
| 51 |
) ); |
| 52 |
|
| 53 |
} |
| 54 |
add_action( 'wp_abilities_api_categories_init', 'automatorwp_ai_assistant_register_category' ); |
| 55 |
|
| 56 |
/** |
| 57 |
* Get abilities |
| 58 |
* |
| 59 |
* @since 1.0.0 |
| 60 |
* |
| 61 |
* @return array |
| 62 |
*/ |
| 63 |
function automatorwp_ai_assistant_get_abilities() { |
| 64 |
|
| 65 |
$registered = wp_get_abilities(); |
| 66 |
$categories = array(); |
| 67 |
|
| 68 |
foreach( $registered as $ability => $object ) { |
| 69 |
if( strpos( $ability, 'automatorwp' ) !== false ) { |
| 70 |
$categories[$ability] = $object; |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
return $categories; |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Get abilities slugs |
| 79 |
* |
| 80 |
* @since 1.0.0 |
| 81 |
* |
| 82 |
* @return array |
| 83 |
*/ |
| 84 |
function automatorwp_ai_assistant_get_abilities_slugs() { |
| 85 |
return array_keys( automatorwp_ai_assistant_get_abilities() ); |
| 86 |
} |
| 87 |
|