An AI Strapi Plugin (@genai/gemini-content-generator) to generate content using Gen AI in Strapi
Introduction
The @genai/gemini-content-generator
is a Strapi plugin designed to automate and enhance content creation using Google Gemini AI. This blog details the technical implementation, architecture, and publishing workflow of the plugin.
Strapi Plugin: https://github.com/suryakand/gemeni-content-generator-plugin
Example Strapi Project: There is an example GitHub Strapi project strapi-genai-plugin-example to showcase the use of plugin. Clone the repository and dollow the steps in the example project to see the plugin demo.
Project Structure
The plugin follows the standard Strapi plugin architecture:
admin/
— React-based UI for Strapi admin panel integrationserver/
— Node.js backend logic for Strapi plugin API and servicesdist/
— Compiled output for publishing
Key Features
- Content Generation: Uses Google Gemini AI to generate and suggest content for Strapi collections.
- Admin UI: Seamless integration with Strapi admin panel for easy content generation and management.
- Configurable: API keys and settings are managed via environment variables for security and flexibility.
Implementation Details
1. Google Gemini AI Integration
The plugin leverages the @google/generative-ai
npm package to interact with Gemini AI APIs. The backend service in server/
handles API requests, authentication, and error handling.
// Example: server/services/gemini.js
const { GoogleGenerativeAI } = require('@google/generative-ai');
const gemini = new GoogleGenerativeAI(process.env.GEMINI_API_KEY);
module.exports = {
async generateContent(prompt) {
return await gemini.generate({ prompt });
},
};
2. Strapi Admin Panel Extension
The admin/
directory contains React components that extend the Strapi admin UI. These components provide buttons and forms for triggering content generation and displaying results.
- Uses Strapi Design System for consistent UI
- Handles async requests to the backend service
3. Plugin Configuration
Configuration is managed via environment variables and Strapi's plugin settings. Sensitive data like API keys are never committed to the repo, thanks to .env
and .dockerignore
rules.
GEMINI_API_KEY=your-google-gemini-api-key
Publishing & CI/CD
The project includes a GitHub Actions workflow for automated publishing:
- On every push to
main
, the workflow:- Bumps the version
- Tags the release
- Publishes to npm
- Creates a GitHub release
Using the plugin
Installation
npm install @genai-cms/gemini-content-generator
Enable Plugin
Add the plugin to your config/plugins.js
or config/plugins.ts
:
module.exports = {
'gemeni-content-generator': {
enabled: true
},
};
Creating a Gemini API Key
- Visit the Google AI Studio and sign in with your Google account.
- Click on "Create API key" and follow the prompts.
- Copy the generated API key.
- Add the API key to your .env file as shown below:
GEMINI_API_KEY=<YOUR GEMENI API KEY>
Usage
After the plugin installation and configuration, you can access the Text AI
field under CUSTOM
fields tab. You can use this field to generate content for your collection types using the Google Gemini AI service. Below screenshot shows the custom Text AI
.
For more details, refer to the plugin documentation or the Strapi marketplace page.
Example Strapi Project
There is an example GitHub Strapi project strapi-genai-plugin-example to showcase the use of plugin. Clone the repository and dollow the steps in the example project to see the plugin demo.
Sample Screen
Create new collection type in Strapi
Add fields (custom and regular) to the collection
Create new entry in newly created collection
Use the custom "Text AI" field to generate content using a prompt
Conclusion
The @genai/gemini-content-generator
plugin brings the power of Google Gemini AI to Strapi, making content creation faster and smarter. With a robust architecture, clean admin UI, and automated publishing, it's ready for production use and open-source collaboration.
No comments:
Post a Comment