Leonardo Grigorio
Workflows by Leonardo Grigorio
Query Google Sheets/CSV data through an AI agent using PostgreSQL
Want to see it in action? Watch the full breakdown here: [📺 Video Link](https://www.youtube.com/watch?v=uj_XpLSMRmk) ### **Template Description** This n8n workflow empowers you to query structured financial data from Google Sheets or CSV files using AI-generated SQL. Unlike traditional vector database solutions that falter with numerical queries, this template leverages PostgreSQL for efficient data storage and an AI agent to dynamically create optimized SQL queries from natural language inputs. #### **What It Does** - Retrieves data from Google Sheets or CSV files - Infers the data schema and builds a PostgreSQL table - Populates the table with your data - Uses an AI agent to translate natural language questions into SQL queries - Returns precise numerical results quickly and efficiently #### **Why Use This?** - No SQL knowledge required—the AI generates queries for you - Bypasses the inefficiencies and costs of vector database approaches - Scales effortlessly without overwhelming the language model - Fully free and open-source --- ### **Setup Requirements** #### **Pre-Conditions** - **PostgreSQL Database**: A running PostgreSQL instance (no specific extensions required beyond standard installation). - **Google Sheets Access**: A publicly accessible or shared Google Sheet URL with structured data (e.g., financial records). Need a starting point? Use this [Sample Google Sheet Template](insert-link-here). - **n8n Instance**: A working n8n setup with access to the Google Drive and PostgreSQL nodes. #### **Step-by-Step Instructions** 1. **Add Your Google Sheets URL** - Open the "Google Drive Trigger" node. - Replace the placeholder URL with your Google Sheet’s link. - Verify the sheet name matches your data source. 2. **Configure PostgreSQL** - Update the "PostgreSQL" nodes with your database credentials (host, database, user, password). - The workflow automatically creates and populates the table based on your data schema. 3. **Run the Workflow** - Execute the workflow manually to set up the database. - Once initialized, use the AI agent by asking questions like: - _"How much did I sell last week?"_ - _"What were the total sales for Product X in February?"_ 4. **(Optional) Automate Updates** - Add a "Schedule Trigger" node to sync your Google Sheets data with PostgreSQL on a regular basis. --- ### **How It Works** - **Schema Detection**: The workflow analyzes your Google Sheets or CSV data to infer its structure and create an appropriate PostgreSQL table. - **AI-Powered Queries**: An optimized AI agent converts your natural language questions into precise SQL queries, ensuring accurate results. - **Efficient Retrieval**: By using PostgreSQL instead of vector-based methods, this template avoids common pitfalls like slow performance or inaccurate numerical outputs. --- ### **Tips for Success** - Ensure your Google Sheet or CSV has consistent column headers for smooth schema detection. - Test with simple questions first to verify the AI agent’s query generation. - Check out the [n8n Template Submission Guidelines](insert-link-here) for more best practices.
Youtube outlier detector (find trending content based on your competitors)
[Video explanation](https://www.youtube.com/watch?v=pIfT9e-zPO0) This n8n workflow helps you identify trending videos within your niche by detecting outlier videos that significantly outperform a channel's average views. It automates the process of monitoring competitor channels, saving time and streamlining content research. ## Included in the Workflow - Automated Competitor Video Tracking Monitors videos from specified competitor channels, fetching data directly from the YouTube API. - Outlier Detection Based on Channel Averages Compares each video’s performance against the channel’s historical average to identify significant spikes in viewership. - Historical Video Data Management Stores video statistics in a PostgreSQL database, allowing the workflow to only fetch new videos and optimize API usage. - Short Video Filtering Automatically removes short videos based on duration thresholds. - Flexible Video Retrieval Fetches up to 3 months of historical data on the first run and only new videos on subsequent runs. - PostgreSQL Database Integration Includes SQL queries for database setup, video insertion, and performance analysis. - Configurable Outlier Threshold Focuses on videos published within the last two weeks with view counts at least twice the channel's average. - Data Output for Analysis Outputs best-performing videos along with their engagement metrics, making it easier to identify trending topics. ## Requirements - n8n installed on your machine or server - A valid YouTube Data API key - Access to a PostgreSQL database This workflow is intended for educational and research purposes, helping content creators gain insights into what topics resonate with audiences without manual daily monitoring.
AI YouTube trend finder based on niche
[Youtube Video](https://youtu.be/Eh5OeyrYlK8) This n8n workflow is designed to assist YouTube content creators in identifying trending topics within a specific niche. By leveraging YouTube's search and data APIs, it gathers and analyzes video performance metrics from the past two days to provide insights into what content is gaining traction. Here's how the workflow operates: 1. **Trigger Setup**: The workflow begins when a user sends a query through the `chat_message_received` node. If no niche is provided, the AI prompts the user to select or input one. 2. **AI Agent (Language Model)**: The central node utilizes a GPT-based AI agent to: - Understand the user's niche or content preferences. - Generate tailored search terms related to the niche. - Process YouTube API responses and summarize trends using insights such as common themes, tags, and audience engagement metrics (views, likes, and comments). 3. **YouTube Search**: The `youtube_search` node runs a secondary workflow to query YouTube for relevant videos published within the last two days. It retrieves basic video data such as video IDs, relevance scores, and publication dates. 4. **Video Details Retrieval**: The workflow fetches additional details for each video: - **Video Snippet**: Metadata like title, description, and tags. - **Video Statistics**: Metrics such as views, likes, and comments. - **Content Details**: Video duration, ensuring only content longer than 3 minutes and 30 seconds is analyzed. 5. **Data Processing**: - Video metadata is cleaned, sanitized, and stored in memory. - Tags, titles, and descriptions are analyzed to identify patterns and trends across multiple videos. 6. **Output**: The workflow compiles insights and presents them to the user, highlighting: - The most common themes or patterns within the niche. - URLs to trending videos and their respective channels. - Engagement statistics, helping the user understand the popularity of the content. ### Key Notes for Setup: - **API Keys**: Ensure valid YouTube API credentials are configured in the `get_videos`, `find_video_snippet`, `find_video_statistics`, and `find_video_data` nodes. - **Memory Buffer**: The `window_buffer_memory` node ensures the AI agent retains context during analysis, enhancing the quality of the generated insights. - **Search Term Customization**: The AI agent dynamically creates search terms based on the user’s niche to improve search precision. ### Use Case: This workflow is ideal for YouTubers or marketers seeking data-driven inspiration for creating content that aligns with current trends, maximizing the potential to engage their audience. ### Example Output: For the niche "digital marketing": - Trending Topic: Videos about "mental triggers" and "psychological marketing." - Tags: "SEO," "Conversion Rates," "Social Proof." - Engagement: Videos with over **200K views** and high likes/comment ratios are leading trends. - Video links: - https://www.youtube.com/watch?v=video_id1 - https://www.youtube.com/watch?v=video_id2