ChatGPT - Optimize Product Feed
📌 Purpose
This script enhances product feed data using OpenAI's GPT models, generating structured titles, descriptions, highlights, and attributes like color or material. It uses data from feed rows, meta descriptions, and product images to produce SEO-ready content.
It is designed for use within Alli Workflows, enabling automated and scalable product content enrichment for eCommerce and marketing.
🧩 Environment Variables
Required
|| Variable Name || Description ||
| OPENAI_API_KEY
| Your OpenAI API key. Accepts api_key
as a fallback. |
| PRODUCT_FEED
| Full path to the input .csv
file with product data. |
| OUTPUT_FEED
| Destination path to save the enriched .csv
output. |
Optional
|| Variable Name || Description ||
| CUSTOMER_PERSONA
| A description of your brand’s average customer to guide tone and style. |
| KEYWORDS
| Comma-separated list of keywords to weave into the content. |
| MAIN_IMAGE
| The column name containing image URLs (used for base64 image enhancement). |
| MAIN_KEY
| Unique identifier for each row. Defaults to SKU
. |
🚀 Script Workflow
Read Input
Loads CSV from
PRODUCT_FEED
Infers schema roles using OpenAI (optional)
Process Rows
For each row:
Build prompt using feed data, persona, keywords
Fetch meta description from product URL
Fetch base64 of product image (if available)
Generate AI Output
Calls
gpt-4o
with promptParses JSON response
Adds fields like title, highlights, reasoning, etc.
Write Output
Saves all enriched rows to
OUTPUT_FEED
Logs failed rows to
error_rows.csv
Prints a preview of the first 5 rows
📤 Output Fields
|| Field || Description ||
| SKU
| From MAIN_KEY
(or SKU
) |
| run_date
| Date script was run |
| ai_model
| Model used (gpt-4o
) |
| structured_title
| Cleaned and enhanced product title |
| ai_short_title
| Brief, search-friendly product title |
| structured_description
| Long-form, SEO-ready description |
| ai_product_highlights
| Bulleted list of product highlights |
| ai_product_type
| Inferred product category |
| ai_color
| Inferred product color |
| ai_material
| Inferred material |
| ai_pattern
| Inferred pattern or texture |
| ai_reasoning
| Explanation of how/why the content was generated |
🧠 Features
🔁 Retry logic with
tenacity
for resilient API and web requests🧠 Auto schema inference using OpenAI
📸 Visual analysis of product images using base64
⚡ Fast batch processing with
ThreadPoolExecutor
🔗 Use Cases
Google Shopping feed optimization
Amazon or eCommerce site product content
SEO-focused PDP (Product Detail Page) generation
Generating AI-enriched marketing content
⚠️ Notes
Ensure product URLs and image links are accessible by the script
Any rows that fail to process are saved to
error_rows.csv
Script attempts to fix malformed JSON returned by the AI
✅ Alli Workflows Best Practices
Use a file-cleaning task (e.g. null removal) before this step
Organize variables using environment groups for reusability
Review
OUTPUT_FEED
anderror_rows.csv
in downstream logic
🧪 Sample Output Preview
First 5 rows of the output: SKU run_date ai_model structured_title ai_short_title ... ABC123 2025-06-24 gpt-4o ... ... ... DEF456 2025-06-24 gpt-4o ... ... ...