Aiomatic Plugin Developer Documentation
Welcome to the developer documentation for the Aiomatic plugin. This guide provides an overview of all the filters and action hooks available for developers to customize and extend the plugin’s functionality.
Filters
Filters allow you to modify internal data of the plugin at specific points during execution. Below is a list of all available filters, along with their descriptions and usage examples.
1. aiomatic_openai_api_key
Description: Modify the OpenAI API key used for generating text.
Usage:
add_filter('aiomatic_openai_api_key', 'modify_aiomatic_api_key');
function modify_aiomatic_api_key($api_key) {
// Your custom logic to modify the API key
return $api_key;
}
Parameters:
$api_key
(string): The original OpenAI API key.
2. aiomatic_model_selection
Description: Modify the AI model used for text generation.
Usage:
add_filter('aiomatic_model_selection', 'select_custom_model');
function select_custom_model($model) {
// Your custom logic to select a different model
return $model;
}
Parameters:
$model
(string): The original AI model name.
3. aiomatic_assistant_id_custom_logic
Description: Modify the assistant ID based on custom logic.
Usage:
add_filter('aiomatic_assistant_id_custom_logic', 'custom_assistant_id_logic', 10, 3);
function custom_assistant_id_logic($assistant_id, $aicontent, $model) {
// Your custom logic to modify the assistant ID
return $assistant_id;
}
Parameters:
$assistant_id
(string): The original assistant ID.$aicontent
(mixed): The AI content or prompt.$model
(string): The AI model name.
4. aiomatic_modify_ai_query
Description: Modify the AI query before it is sent to the AI model.
Usage:
add_filter('aiomatic_modify_ai_query', 'modify_ai_query', 10, 3);
function modify_ai_query($aicontent, $model, $assistant_id) {
// Your custom logic to modify the AI query
return $aicontent;
}
Parameters:
$aicontent
(mixed): The original AI content or prompt.$model
(string): The AI model name.$assistant_id
(string): The assistant ID.
5. aiomatic_retry_count
Description: Adjust the number of retry attempts for the AI query.
Usage:
add_filter('aiomatic_retry_count', 'set_retry_count', 10, 4);
function set_retry_count($retry_count, $aicontent, $model, $assistant_id) {
// Your custom logic to set the retry count
return $retry_count;
}
Parameters:
$retry_count
(int): The original retry count.$aicontent
(mixed): The AI content or prompt.$model
(string): The AI model name.$assistant_id
(string): The assistant ID.
6. aiomatic_is_ai_query_allowed
Description: Determine if the AI query is allowed to proceed.
Usage:
add_filter('aiomatic_is_ai_query_allowed', 'check_ai_query_permission', 10, 2);
function check_ai_query_permission($is_allowed, $aicontent) {
// Your custom logic to allow or disallow the query
return $is_allowed; // Return true to allow, or a string error message to disallow
}
Parameters:
$is_allowed
(bool|string): True if allowed, or an error message string if not.$aicontent
(mixed): The AI content or prompt.
7. aiomatic_modify_ai_error
Description: Modify the error message returned when an error occurs.
Usage:
add_filter('aiomatic_modify_ai_error', 'customize_ai_error_message');
function customize_ai_error_message($error) {
// Your custom logic to modify the error message
return $error;
}
Parameters:
$error
(string): The original error message.
8. aiomatic_function_result
Description: Modify the function result before it’s processed.
Usage:
add_filter('aiomatic_function_result', 'alter_function_result', 10, 4);
function alter_function_result($function_result, $aicontent, $model, $assistant_id) {
// Your custom logic to modify the function result
return $function_result;
}
Parameters:
$function_result
(mixed): The original function result.$aicontent
(mixed): The AI content or prompt.$model
(string): The AI model name.$assistant_id
(string): The assistant ID.
9. aiomatic_user_role_adjustment
Description: Adjust the user role in the AI query.
Usage:
add_filter('aiomatic_user_role_adjustment', 'adjust_user_role', 10, 4);
function adjust_user_role($role, $aicontent, $model, $assistant_id) {
// Your custom logic to adjust the user role
return $role;
}
Parameters:
$role
(string): The original user role (e.g., ‘user’).$aicontent
(mixed): The AI content or prompt.$model
(string): The AI model name.$assistant_id
(string): The assistant ID.
10. aiomatic_user_question
Description: Modify the user’s question before it’s sent to the AI.
Usage:
add_filter('aiomatic_user_question', 'modify_user_question', 10, 4);
function modify_user_question($user_question, $role, $model, $aicontent) {
// Your custom logic to modify the user's question
return $user_question;
}
Parameters:
$user_question
(string): The original user question.$role
(string): The user role.$model
(string): The AI model name.$aicontent
(mixed): The AI content or prompt.
11. aiomatic_thread_id
Description: Modify the thread ID for the AI conversation.
Usage:
add_filter('aiomatic_thread_id', 'set_thread_id', 10, 4);
function set_thread_id($thread_id, $aicontent, $model, $assistant_id) {
// Your custom logic to set the thread ID
return $thread_id;
}
Parameters:
$thread_id
(string): The original thread ID.$aicontent
(mixed): The AI content or prompt.$model
(string): The AI model name.$assistant_id
(string): The assistant ID.
12. aiomatic_temperature
Description: Modify the temperature parameter, which controls the randomness of the AI output.
Usage:
add_filter('aiomatic_temperature', 'set_temperature', 10, 4);
function set_temperature($temperature, $aicontent, $model, $assistant_id) {
// Your custom logic to set the temperature
return $temperature;
}
Parameters:
$temperature
(float): The original temperature value.$aicontent
(mixed): The AI content or prompt.$model
(string): The AI model name.$assistant_id
(string): The assistant ID.
13. aiomatic_top_p
Description: Modify the top_p parameter, controlling the diversity of the AI output.
Usage:
add_filter('aiomatic_top_p', 'set_top_p', 10, 4);
function set_top_p($top_p, $aicontent, $model, $assistant_id) {
// Your custom logic to set the top_p value
return $top_p;
}
Parameters:
$top_p
(float): The original top_p value.$aicontent
(mixed): The AI content or prompt.$model
(string): The AI model name.$assistant_id
(string): The assistant ID.
14. aiomatic_presence_penalty
Description: Modify the presence penalty parameter, which penalizes new tokens based on whether they appear in the text so far.
Usage:
add_filter('aiomatic_presence_penalty', 'set_presence_penalty', 10, 4);
function set_presence_penalty($presence_penalty, $aicontent, $model, $assistant_id) {
// Your custom logic to set the presence penalty
return $presence_penalty;
}
Parameters:
$presence_penalty
(float): The original presence penalty value.$aicontent
(mixed): The AI content or prompt.$model
(string): The AI model name.$assistant_id
(string): The assistant ID.
15. aiomatic_frequency_penalty
Description: Modify the frequency penalty parameter, which penalizes new tokens based on their existing frequency in the text.
Usage:
add_filter('aiomatic_frequency_penalty', 'set_frequency_penalty', 10, 4);
function set_frequency_penalty($frequency_penalty, $aicontent, $model, $assistant_id) {
// Your custom logic to set the frequency penalty
return $frequency_penalty;
}
Parameters:
$frequency_penalty
(float): The original frequency penalty value.$aicontent
(mixed): The AI content or prompt.$model
(string): The AI model name.$assistant_id
(string): The assistant ID.
16. aiomatic_vision_file
Description: Modify the vision file used for AI image processing.
Usage:
add_filter('aiomatic_vision_file', 'set_vision_file', 10, 4);
function set_vision_file($vision_file, $aicontent, $model, $assistant_id) {
// Your custom logic to set the vision file
return $vision_file;
}
Parameters:
$vision_file
(string): The path to the vision file.$aicontent
(mixed): The AI content or prompt.$model
(string): The AI model name.$assistant_id
(string): The assistant ID.
17. aiomatic_embedding_namespace
Description: Modify the embedding namespace for vector embeddings.
Usage:
add_filter('aiomatic_embedding_namespace', 'set_embedding_namespace', 10, 4);
function set_embedding_namespace($embedding_namespace, $aicontent, $model, $assistant_id) {
// Your custom logic to set the embedding namespace
return $embedding_namespace;
}
Parameters:
$embedding_namespace
(string): The original embedding namespace.$aicontent
(mixed): The AI content or prompt.$model
(string): The AI model name.$assistant_id
(string): The assistant ID.
18. aiomatic_ai_functions
Description: Add or modify AI functions before they are processed.
Usage:
add_filter('aiomatic_ai_functions', 'add_custom_ai_functions');
function add_custom_ai_functions($functions) {
// Your custom logic to add or modify AI functions
return $functions;
}
Parameters:
$functions
(array|false): The original AI functions or false if none.
19. aiomatic_post_ai_functions
Description: Modify AI functions after initial processing.
Usage:
add_filter('aiomatic_post_ai_functions', 'modify_post_ai_functions');
function modify_post_ai_functions($functions) {
// Your custom logic to modify AI functions
return $functions;
}
Parameters:
$functions
(array|false): The AI functions array.
20. aiomatic_available_tokens_before_check
Description: Modify the available tokens before checking token limits.
Usage:
add_filter('aiomatic_available_tokens_before_check', 'adjust_available_tokens', 10, 4);
function adjust_available_tokens($available_tokens, $aicontent, $model, $assistant_id) {
// Your custom logic to adjust available tokens
return $available_tokens;
}
Parameters:
$available_tokens
(int): The original number of available tokens.$aicontent
(mixed): The AI content or prompt.$model
(string): The AI model name.$assistant_id
(string): The assistant ID.
21. aiomatic_should_store_data
Description: Determine whether to store data from the AI query.
Usage:
add_filter('aiomatic_should_store_data', 'decide_data_storage', 10, 4);
function decide_data_storage($store_data, $aicontent, $model, $assistant_id) {
// Your custom logic to decide data storage
return $store_data; // Return true or false
}
Parameters:
$store_data
(bool): Whether to store data.$aicontent
(mixed): The AI content or prompt.$model
(string): The AI model name.$assistant_id
(string): The assistant ID.
22. aiomatic_modify_ai_reply
Description: Modify the AI’s reply before it is returned.
Usage:
add_filter('aiomatic_modify_ai_reply', 'alter_ai_reply', 10, 2);
function alter_ai_reply($response_text, $aicontent) {
// Your custom logic to modify the AI reply
return $response_text;
}
Parameters:
$response_text
(string): The original AI reply.$aicontent
(mixed): The AI content or prompt.
23. aiomatic_final_response_text
Description: Modify the final response text after all processing.
Usage:
add_filter('aiomatic_final_response_text', 'finalize_response_text', 10, 4);
function finalize_response_text($response_text, $aicontent, $model, $assistant_id) {
// Your custom logic for the final response text
return $response_text;
}
Parameters:
$response_text
(string): The final AI response text.$aicontent
(mixed): The AI content or prompt.$model
(string): The AI model name.$assistant_id
(string): The assistant ID.
Actions
Actions allow you to execute custom code at specific points during the plugin’s execution. Below is a list of all available actions, along with their descriptions and usage examples.
1. aiomatic_on_error
Description: Triggered when an error occurs during the AI query process.
Usage:
add_action('aiomatic_on_error', 'handle_ai_error', 10, 4);
function handle_ai_error($error, $aicontent, $model, $assistant_id) {
// Your custom logic to handle the error
}
Parameters:
$error
(string): The error message.$aicontent
(mixed): The AI content or prompt that caused the error.$model
(string): The AI model name.$assistant_id
(string): The assistant ID.
2. aiomatic_on_streamed_query
Description: Triggered when a streamed query is initiated.
Usage:
add_action('aiomatic_on_streamed_query', 'on_streamed_query_start', 10, 3);
function on_streamed_query_start($aicontent, $model, $assistant_id) {
// Your custom logic for streamed queries
}
Parameters:
$aicontent
(mixed): The AI content or prompt.$model
(string): The AI model name.$assistant_id
(string): The assistant ID.
3. aiomatic_on_token_limit_warning
Description: Triggered when the available token limit is low.
Usage:
add_action('aiomatic_on_token_limit_warning', 'handle_token_limit_warning', 10, 4);
function handle_token_limit_warning($available_tokens, $aicontent, $model, $assistant_id) {
// Your custom logic when token limit is low
}
Parameters:
$available_tokens
(int): The number of available tokens remaining.$aicontent
(mixed): The AI content or prompt.$model
(string): The AI model name.$assistant_id
(string): The assistant ID.
4. aiomatic_before_vision_file_process
Description: Triggered before processing the vision file for AI image processing.
Usage:
add_action('aiomatic_before_vision_file_process', 'before_vision_file_processing', 10, 4);
function before_vision_file_processing($vision_file, $aicontent, $model, $assistant_id) {
// Your custom logic before processing the vision file
}
Parameters:
$vision_file
(string): The path to the vision file.$aicontent
(mixed): The AI content or prompt.$model
(string): The AI model name.$assistant_id
(string): The assistant ID.
5. aiomatic_before_assistant_ai_query
Description: Triggered before sending a query to the assistant AI.
Usage:
add_action('aiomatic_before_assistant_ai_query', 'before_assistant_query', 10, 15);
function before_assistant_query($token, $assistant_id, $local_assistant_id, $role, $user_question, $thread_id, $no_internet, $no_embeddings, $env, $retry_count, $embedding_namespace, $stream, $function_result, $vision_file, $file_data) {
// Your custom logic before the assistant AI query
}
Parameters:
$token
(string): The API token.$assistant_id
(string): The assistant ID.$local_assistant_id
(string): The local assistant ID.$role
(string): The user role.$user_question
(string): The user’s question.$thread_id
(string): The thread ID.$no_internet
(bool): Whether internet access is disabled.$no_embeddings
(bool): Whether embeddings are disabled.$env
(mixed): The environment settings.$retry_count
(int): The retry count.$embedding_namespace
(string): The embedding namespace.$stream
(bool): Whether streaming is enabled.$function_result
(mixed): The function result.$vision_file
(string): The vision file path.$file_data
(mixed): Additional file data.
6. aiomatic_after_assistant_ai_query
Description: Triggered after receiving a response from the assistant AI.
Usage:
add_action('aiomatic_after_assistant_ai_query', 'after_assistant_query', 10, 16);
function after_assistant_query($response_ai, $token, $assistant_id, $local_assistant_id, $role, $user_question, $thread_id, $no_internet, $no_embeddings, $env, $retry_count, $embedding_namespace, $stream, $function_result, $vision_file, $file_data) {
// Your custom logic after the assistant AI query
}
Parameters:
$response_ai
(mixed): The AI’s response.- Other parameters are the same as in
aiomatic_before_assistant_ai_query
.
7. aiomatic_before_chat_ai_query
Description: Triggered before sending a chat-based AI query.
Usage:
add_action('aiomatic_before_chat_ai_query', 'before_chat_query', 10, 23);
function before_chat_query($token, $model, $chatgpt_obj, $available_tokens, $temperature, $top_p, $presence_penalty, $frequency_penalty, $is_chat, $env, $retry_count, $finish_reason, $error, $no_internet, $no_embeddings, $functions, $stream, $vision_file, $additional_param, $user_question, $embedding_namespace, $function_result, $additional_param2, $store_data) {
// Your custom logic before the chat AI query
}
Parameters:
- A comprehensive list including all relevant variables before the chat AI query is sent.
8. aiomatic_after_chat_ai_query
Description: Triggered after receiving a response from a chat-based AI query.
Usage:
add_action('aiomatic_after_chat_ai_query', 'after_chat_query', 10, 24);
function after_chat_query($response_text, $token, $model, $chatgpt_obj, $available_tokens, $temperature, $top_p, $presence_penalty, $frequency_penalty, $is_chat, $env, $retry_count, $finish_reason, $error, $no_internet, $no_embeddings, $functions, $stream, $vision_file, $additional_param, $user_question, $embedding_namespace, $function_result, $additional_param2, $store_data) {
// Your custom logic after the chat AI query
}
Parameters:
$response_text
(string): The AI’s response.- Other parameters are the same as in
aiomatic_before_chat_ai_query
.
9. aiomatic_before_completion_ai_query
Description: Triggered before sending a completion-based AI query.
Usage:
add_action('aiomatic_before_completion_ai_query', 'before_completion_query', 10, 18);
function before_completion_query($token, $model, $aicontent, $available_tokens, $temperature, $top_p, $presence_penalty, $frequency_penalty, $is_chat, $env, $retry_count, $finish_reason, $error, $no_internet, $no_embeddings, $stream, $user_question, $embedding_namespace, $vision_file) {
// Your custom logic before the completion AI query
}
Parameters:
$token
(string): The API token.$model
(string): The AI model name.$aicontent
(mixed): The AI content or prompt.- Other relevant parameters for the completion AI query.
10. aiomatic_on_successful_response
Description: Triggered when the AI returns a successful response.
Usage:
add_action('aiomatic_on_successful_response', 'handle_successful_response', 10, 4);
function handle_successful_response($response_text, $aicontent, $model, $assistant_id) {
// Your custom logic for successful AI responses
}
Parameters:
$response_text
(string): The AI’s response.$aicontent
(mixed): The AI content or prompt.$model
(string): The AI model name.$assistant_id
(string): The assistant ID.
Notes
- Parameter Types: The parameter types are indicated in parentheses next to each parameter name.
- Hook Priority: The integer
10
in theadd_filter
andadd_action
functions represents the priority of your function execution. Lower numbers mean earlier execution. - Argument Count: The number after the priority (e.g.,
10, 3
) specifies the number of arguments your function accepts.
Conclusion
By utilizing these filters and actions, you can customize the Aiomatic plugin to better suit your needs. Whether it’s modifying the AI query parameters, handling errors, or processing the AI’s response, these hooks provide a flexible way to extend the plugin’s functionality.
For any questions or further assistance, feel free to reach out or consult the plugin’s support resources.
Happy coding!