AI pet Personality Quiz: revealing your pet’s unique traits - createIT

Get a free advice now!

    Pick the topic

    Developer OutsourcingWeb developingApp developingDigital MarketingeCommerce systemseEntertainment systems

    Thank you for your message. It has been sent.

    Tags

    AI pet Personality Quiz: revealing your pet’s unique traits

    AI pet Personality Quiz: revealing your pet’s unique traits

    Challenge: Deciphering intricate pet behaviors and personalities

    Solution: An AI-driven quiz offering tailored personality profiles to demystify pet quirks

    Pets, especially cats and dogs, have always been a source of joy and mystery for their owners. From a cat’s unpredictable antics to a dog’s boundless energy, every pet is a world of its own. The AI Pet Personality Quiz dives deep into this world, using state-of-the-art AI to offer a fun, insightful, and interactive experience for pet owners.

    List of features

    1. Powered by OpenAI’s GPT-4: The plugin uses one of the most advanced language models available to generate insightful pet personality profiles.
    2. Intuitive questions: The quiz contains a set of questions designed to capture the essence of a pet’s behavior and characteristics.
    3. Detailed personality profiles: Based on the answers, the AI generates a comprehensive profile that dives deep into the pet’s personality.
    4. Social media sharing: Users can share quiz url on various social media platforms, driving engagement and virality.
    5. Background scheduling: The plugin utilizes the action-scheduler to generate personality descriptions in the background, ensuring optimal website performance.
    6. Custom post type: The plugin introduces a custom post type, allowing for easy management of AI-generated pet personalities.
    A table with text gradually appearing

    Technical details

    The AI Pet Personality Quiz is a WordPress plugin. It’s an intricate system that seamlessly integrates advanced AI capabilities into your website, providing users with an engaging and unique experience. Let’s delve deeper into the technical aspects that make this plugin tick.

    1. OpenAI Integration:

    • OpenAI GPT-4: At the core of our plugin lies the powerful GPT-4 model from OpenAI. This model is responsible for generating the detailed pet personality profiles based on the scores calculated from the quiz.
    • Efficient API usage: To ensure cost efficiency, the plugin is designed to store generated personality profiles. This means that after the initial generation of a personality profile, the plugin will not make redundant calls to the OpenAI API, saving on costs.

    2. Custom post type:

    • The plugin introduces a custom post type named aipetpersonality. This is where all the AI-generated pet personalities are stored.

    3. Background processing:

    • Action Scheduler integration: The plugin uses Action Scheduler to manage background tasks. This ensures that the process of generating new personality profiles doesn’t hinder the user experience.
    • Scheduled generation: New personality profiles are not generated in real-time. Instead, they’re scheduled to be generated in the background, ensuring that the frontend remains fast and efficient.

    4. Quiz configuration:

    • The quiz is driven by a configuration object named $ai_quiz_config. This object is easily customizable, allowing you to add new types of pets, questions, and scoring systems.

    5. Shortcode integration:

    • To display the quiz on any post or page, the plugin provides a simple shortcode: [aipetpersonality_form quiz_topic=”cat”]. This shortcode renders the quiz, and it’s both responsive and stylish right out of the box.

    6. Dynamic results generation:

    • When a user submits the quiz, their answers are processed, and a score is calculated. This score is then matched with a personality profile range, and the corresponding profile is fetched and displayed.
    • The AJAX technology ensures that this entire process happens without reloading the page.

    7. Social media integration:

    • After completing the quiz, users have an option to share quiz page on various social media platforms. This not only enhances user engagement but also promotes the quiz to a wider audience.

    1. Building the prompt for OpenAI

    The primary function responsible for this is aipetpersonality_generatePrompt. The purpose of this function is to dynamically craft a prompt that instructs OpenAI’s GPT-4 model on what kind of content to produce.

    Code example:

    function aipetpersonality_generatePrompt($score, $quiz_topic) {
        global $ai_quiz_config;
        $rangeDescriptions = [];
        $quiz_about = $ai_quiz_config['quizzes'][$quiz_topic]['quiz_about'];
    
        foreach ($ai_quiz_config['quizzes'][$quiz_topic]['score_ranges'] as $range => $desc) {
            $rangeDescriptions[] = "Score {$range}: {$desc} ,";
        }
    
        $rangeText = implode("\n", $rangeDescriptions);
    
        return <<<PROMPT
    Based on the following personality range grouping:
    {$rangeText} .
    
    Describe {$quiz_about} personality for {$score}, following the structure below:
    
    ... [table structure] ...
    
    PROMPT;
    }

    Real-life Example:

    Let’s say our quiz topic is “dog” (personality quiz) and the score range is “3-5”. The $ai_quiz_config might look something like this:

    $ai_quiz_config = [
        'quizzes' => [
            'dog' => [
                'quiz_about' => 'dog',
                'score_ranges' => [
                    '-5 to -3' => 'Couch Potato Pooch',
                    '-2 to 2' => 'Easy-Going Buddy',
                    '3 to 5' => 'Energetic Explorer',
                    '6 to 10' => 'Alpha Leader'
                ]
            ]
        ]
    ];

    Given the above, our prompt would be constructed as:

    Based on the following personality range grouping:
    Score -5 to -3: Couch Potato Pooch,
    Score -2 to 2: Easy-Going Buddy,
    Score 3 to 5: Energetic Explorer,
    Score 6 to 10: Alpha Leader .

    Describe a dog personality for 3-5, following the structure below:

    … [table structure] …

    2. Fetching data from the OpenAI API:

    The function aipetpersonality_get_description interacts with the OpenAI API, passing the constructed prompt to get the desired description.

    Code Example:

    function aipetpersonality_get_description($quiz_topic, $score_range) {
        $yourApiKey = get_option('openai_api_key');
        $client = OpenAI::client($yourApiKey);
        $final_prompt = aipetpersonality_generatePrompt($score_range, $quiz_topic);
    
        try {
            $response = $client->chat()->create([
                'model' => 'gpt-4',
                'messages' => [
                    ['role' => 'user', 'content' => $final_prompt],
                ],
                'max_tokens' => 3000,
                'temperature' => 1
            ]);
    
            return $response->choices[0]->message->content;
    
        } catch (Exception $e) {
            // Handle errors
        }
    
        return false;
    }

    3. Saving the generated data:

    Once the description is fetched from the OpenAI API, it is saved as a WordPress custom post type item.

    Code example:

    function aipetpersonality_daily_generate_callback($item) {
        $quiz_topic = sanitize_text_field($item['quiz_topic']);
        $score_range = sanitize_text_field($item['score_range']);
        $title = "{$quiz_topic} {$score_range}";
    
        $description = aipetpersonality_get_description($quiz_topic, $score_range);
    
        if (!$description) {
            return;
        }
    
        wp_insert_post(array(
            'post_title' => $title,
            'post_content' => $description,
            'post_type' => 'aipetpersonality',
            'post_status' => 'publish'
        ));
    }

    In summary, the plugin automates the process of creating unique and structured pet personality descriptions. The prompt construction is flexible, allowing different quizzes and score ranges to be catered for. This ensures diverse and accurate content generation, which is then saved in WordPress for users to access.

    WordPress dashboard

    Installation and setup

    1. Installation

    • In the plugin directory, run:
    composer update
    • Activate the ‘AI Pet Personality Quiz’ plugin via the WordPress admin dashboard under ‘Plugins’.

    2. Configuration:

    • In the plugin’s settings in the WordPress dashboard (Settings / AI Pet Personality Quiz Settings), input your OpenAI API key in the designated field.

    3. Usage:

    • Insert the shortcode (e.g., [aipetpersonality_form quiz_topic=”cat”]) in any post or page to display the plugin’s functionality.

    With these steps, the plugin will be operational, leveraging OpenAI to generate pet personality descriptions based on quiz results.

    Generating pet profiles

    The plugin employs a scheduling system to generate pet personality descriptions on a daily basis. These scheduled tasks ensure that your site continually updates with new content without manual intervention.

    1. Triggering manually:

    If you wish to trigger the job outside of its scheduled time:

    • Navigate to the ‘Scheduled Actions’ section in the WordPress dashboard (Tools / Scheduled Actions).
    • Find the aipetpersonality_daily_generate action.
    • Click ‘Run’ to execute it manually.

    2. What the scheduled job does:

    Upon execution, the job:

    1. Checks for any personality descriptions not yet generated based on quiz topics and score ranges.
    2. Constructs a prompt to request a description from OpenAI.
    3. Fetches the description using the OpenAI API.
    4. Saves the newly generated description as a post of type ‘aipetpersonality’.

    Supported pets

    The AI Pet Personality Quiz plugin is designed with versatility in mind, catering to a variety of beloved pets. Here’s a list of pets currently supported:

    • Dogs 🐶: Man’s best friend, with a diverse range of personalities.
    • Cats 🐱: Mysterious and independent, each cat has its unique charm.
    • Hamsters 🐹: Small in size but big in personality.
    • Horses 🐴: Majestic creatures with a spirit of their own.
    • Rabbits 🐰: Gentle and playful, each rabbit has its own quirks.
    An image with several boxes with text and pictures of animal profiles

    Assessing pet personality: the algorithm

    Understanding the unique personality of your pet can be both intriguing and useful. The AI Pet Personality Quiz is designed to provide insights into your pet’s behavior, preferences, and quirks. Here’s how the system evaluates pet personalities:

    1. Questionnaire design

    The first step involves designing a comprehensive questionnaire. Each question aims to unravel a specific aspect of your pet’s personality. For instance:

    – How does your pet react to strangers?

    – How often does your pet play with toys?

    – Does your pet prefer staying indoors or exploring the outdoors?

    2. Scoring mechanism

    Each response is associated with a certain number of points. For example:

    Always calm around strangers: 5 points

    Occasionally wary: 3 points

    Always agitated: 1 point

    The total score is the sum of the points from all the answers.

    3. Score ranges and personality profiles

    Once the total score is calculated, it’s mapped to predefined score ranges, each corresponding to a distinct personality profile. These ranges are defined in the ai_quiz_config configuration. For instance:

    Score 1-10: “The Adventurous Explorer”

    Score 11-20: “The Playful Mischief-maker”

    Score 21-30: “The Calm Observer”

    4. Personality profile descriptions

    Based on the score range your pet falls into, a detailed profile is generated. This profile is not just a label; it’s a comprehensive description with traits like attitude, energy level, favorite toy, etc. For each trait, the AI provides a description tailored to the score range.

    Example:

    For a cat with a score between 11-20 (“The Playful Mischief-maker”):

    Attitude: Curious and always up to some fun.

    Energy Level: High – always ready to play!

    Favorite Toy: Feather wands.

    Summary: The AI Pet Personality Quiz uses a combination of well-thought-out questions, a robust scoring mechanism, and advanced AI modeling to provide a detailed and accurate personality profile for your beloved pet.

    Storing and rendering data: markdown to HTML

    Our WordPress plugin leverages the concise nature of markdown to store the generated pet personality profiles. Markdown allows for easy-to-read text that still retains formatting commands, making it a perfect medium for saving and manipulating these profiles.

    When a user accesses a pet personality profile, the plugin converts the stored markdown into HTML on-the-fly. This ensures that the user is presented with a beautifully formatted and structured profile, enhancing the user experience.

    WordPress dashboard

    Get involved!

    For those interested in taking a closer look under the hood:

    A webpage with a form including selectable text and an image of a dog chasing after a bone
    Comments
    0 response

    Add comment

    Your email address will not be published. Required fields are marked *

    Popular news

    How to Get and Use the ChatGPT API
    • Dev Tips and Tricks

    How to Get and Use the ChatGPT API

    April 25, 2024 by createIT
    eCommerce growth – is your business ready?
    • Services
    • Trends

    eCommerce growth – is your business ready?

    April 8, 2024 by createIT
    Digital marketing without third-party cookies – new rules
    • Technology
    • Trends

    Digital marketing without third-party cookies – new rules

    February 21, 2024 by createIT
    eCommerce healthcheck
    • Services
    • Trends

    eCommerce healthcheck

    January 24, 2024 by createIT
    Live Visitor Count in WooCommerce with SSE
    • Dev Tips and Tricks

    Live Visitor Count in WooCommerce with SSE

    December 12, 2023 by createIT
    Calculate shipping costs programmatically in WooCommerce
    • Dev Tips and Tricks

    Calculate shipping costs programmatically in WooCommerce

    December 11, 2023 by createIT
    Designing a cookie consent modal certified by TCF IAB
    • Dev Tips and Tricks

    Designing a cookie consent modal certified by TCF IAB

    December 7, 2023 by createIT

    Technology
    Be on the same page as the rest of the industry.

    Contact us