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
- Powered by OpenAI’s GPT-4: The plugin uses one of the most advanced language models available to generate insightful pet personality profiles.
- Intuitive questions: The quiz contains a set of questions designed to capture the essence of a pet’s behavior and characteristics.
- Detailed personality profiles: Based on the answers, the AI generates a comprehensive profile that dives deep into the pet’s personality.
- Social media sharing: Users can share quiz url on various social media platforms, driving engagement and virality.
- Background scheduling: The plugin utilizes the action-scheduler to generate personality descriptions in the background, ensuring optimal website performance.
- Custom post type: The plugin introduces a custom post type, allowing for easy management of AI-generated pet personalities.
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.
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:
- Checks for any personality descriptions not yet generated based on quiz topics and score ranges.
- Constructs a prompt to request a description from OpenAI.
- Fetches the description using the OpenAI API.
- 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.
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.
Get involved!
For those interested in taking a closer look under the hood:
- GitHub repository: The complete source code is available on GitHub. It’s open-source and welcomes contributions. Check it out here: https://github.com/createit-dev/316-AI-Pet-Personality-Quiz
- Live Demo: Experience the quiz firsthand. Test out the AI-generated pet personalities on our demo page: https://www.createit.com/ai-demos/ai-pet-personality-quiz/