This project is an intelligent AI agent that understands natural language questions related to e-commerce metrics and returns accurate answers by generating and executing SQL queries on a local database. It uses a locally hosted LLaMA 3 model via Ollama, integrates with FastAPI, and supports streamed responses for a live typing effect.
• Natural Language to SQL: Converts plain English questions into valid SQL queries using a local LLaMA 3 model via Ollama.
• FastAPI Backend: Serves endpoints to receive questions and return results in real time.
• SQLite3 Database: Lightweight and efficient storage for e-commerce metrics.
• Live Typing Effect: Streaming responses simulate human typing for natural interaction.
• cURL + JQ Demo Support: Easily test endpoints from terminal with clean JSON formatting.
• Modular Design: Clean separation of concerns between LLM generation, SQL execution, and API serving.
E-commerce_ai_agent/
├── .venv/ # Python virtual environment
├── .gitignore # Git ignore config
├── README.md # Project documentation
├── Product-Level *.xlsx # Source Excel datasets
├── load_data_to_db.py # Script to load Excel files into SQLite
├── ecommerce.db # Generated SQLite database
├── llama_sql_generator.py # Converts questions into SQL using LLaMA 3
├── llama_sql_executor.py # (Optional) For modular SQL execution
├── api_server.py # FastAPI backend with /ask and /stream endpoints
├── test_database_queries.py # (Optional) Manual SQL query tester
git clone https://github.com/gokularaman-c/E-commerce-ai-agent.git
cd E-commerce-ai-agent
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
If requirements.txt is not present, manually install:
pip install fastapi uvicorn requests sqlite3
ollama run llama3
python load_data_to_db.py
uvicorn api_server:app --reload
⸻
- What is my total sales?
- Calculate the RoAS (Return on Ad Spend).
- Which product had the highest CPC?
- Show total ad spend per month.
- What is the average CTR by month?
- List top 5 products by ad sales.
- How many clicks did each product receive?
- Which product had the lowest RoAS?
- What is the total number of impressions?
- Show top 3 products with highest total sales.
🛠 Tech Stack
Component | Technology |
---|---|
LLM | LLaMA 3 via Ollama |
Backend | FastAPI |
Database | SQLite3 |
API Testing | cURL, Swagger UI |
JSON Parsing | jq (for terminal output) |
Dataset Format | Excel (.xlsx → SQLite) |