Site icon CodeRevolution Knowledge Base

Aiomatic Plugin Developer Documentation

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:


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:


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:


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:


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:


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:


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:


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:


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:


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:


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:


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:


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:


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:


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:


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:

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:


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:


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:


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:


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:


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:


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:


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:


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:


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:


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:


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:


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:


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:


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:


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:


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:


Notes

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!

Exit mobile version