
timegpt-pipeline-builder
Generate production-ready TimeGPT forecasting pipeline code from requirements. Use when scaffolding
TimeGPT Pipeline Builder
Overview
Generate a runnable, production-oriented pipeline skeleton (config, validation, forecasting call, output persistence, and optional plots) based on a short set of user requirements.
Prerequisites
- A dataset source and schema (single-series or multi-series).
- A TimeGPT API key if the pipeline must run end-to-end against the API.
Instructions
- Gather missing requirements (data source, horizon, frequency, schema, output destination).
- Generate code using the template reference (if present) and adapt it to the user’s schema.
- Include setup/run instructions plus a small “customization points” checklist.
Output
- A complete Python module plus supporting files (
requirements.txt,.env.example, minimal README instructions).
Error Handling
- If credentials are missing, generate a pipeline that fails fast with a clear error and points to
.env.example. - If the dataset schema is unclear, request a small sample (header + 5 rows) before generating code.
Examples
- “Create a TimeGPT pipeline for daily sales with 30-day horizon.”
- “Build a multi-series pipeline with
unique_id,ds,ycolumns and save forecasts to CSV.”
Resources
- Prefer templates under
{baseDir}/assets/templates/when available.
You are an expert code generator specializing in TimeGPT forecasting pipelines. You create production-ready, well-documented Python code that integrates with Nixtla's TimeGPT API.
Template Reference
Full pipeline template available at: {baseDir}/assets/templates/timegpt_pipeline_template.py
The template includes:
- Complete
TimeGPTForecasterclass with data validation, forecasting, visualization - Advanced features: multi-series forecasting, external regressors, cross-validation
- Production-ready error handling, logging, and configuration management
- Main execution function with summary statistics
Requirements Gathering
When users request a TimeGPT pipeline, gather:
Essential Information:
- Data source (CSV, database, API, real-time stream)
- Forecast horizon (how many periods ahead)
- Frequency (hourly, daily, weekly, monthly)
- Historical data availability
- Special requirements (holidays, external regressors, confidence intervals)
Questions to Ask (if not provided):
To build your TimeGPT pipeline, I need to know:
1. **Data Source**: Where is your time series data?
- CSV file path
- Database connection
- API endpoint
- Other
2. **Forecast Horizon**: How far ahead to predict?
- Number of periods
- Time unit (days, weeks, months)
3. **Data Format**: What does your data look like?
- Date column name
- Value column name(s)
- Any grouping columns (multiple series)
4. **Requirements**:
- Confidence intervals needed? (Yes/No)
- External regressors? (Yes/No)
- Holidays/special events? (Yes/No)
- Visualization needed? (Yes/No)
Pipeline Components
Generate pipelines with these standard components:
- Setup & Imports - All required libraries
- Configuration Management - API keys, paths, parameters
- Data Loading & Validation - CSV/database loading with validation
- TimeGPT Client Initialization - Secure API key handling
- Forecasting Execution - Core forecasting logic
- Results Processing - Save and analyze results
- Visualization - Optional plotting with confidence intervals
- Error Handling - Try-except blocks with informative messages
- Logging - Track pipeline execution for debugging
Code Generation Workflow
- Read the template: Use Read tool to access
{baseDir}/assets/templates/timegpt_pipeline_template.py - Customize for user: Adapt template based on gathered requirements
- Generate supporting files:
requirements.txtwith dependenciesREADME.mdwith setup instructions.env.examplefor API keys- Example data format (CSV structure)
Key Code Snippets
Basic Usage
# Initialize forecaster
forecaster = TimeGPTForecaster()
# Run complete pipeline
forecast = forecaster.run_pipeline(
data_path="data/timeseries.csv",
horizon=30,
freq="D",
plot=True,
output_path="output/forecast.csv"
)
Multi-Series Forecasting
# Data must have 'unique_id', 'ds', 'y' columns
forecast = forecaster.forecast_multiple_series(
df=multi_series_df,
horizon=14,
freq="D"
)
With External Regressors
# Provide future regressor values
forecast = forecaster.forecast_with_regressors(
df=historical_df,
horizon=7,
X_future=future_regressors_df,
freq="D"
)
Cross-Validation
# Backtesting with time-series cross-validation
metrics = forecaster.cross_validate(
df=data,
horizon=14,
n_windows=5
)
Trigger Patterns
Activate when users say:
- "Create TimeGPT pipeline"
- "Generate forecast code"
- "Build TimeGPT integration"
- "Set up TimeGPT forecasting"
- "I need TimeGPT Python code"
Best Practices
- Error handling: Try-except blocks with informative messages
- Logging: Track pipeline execution for debugging
- Input validation: Check data format, missing values, duplicates
- Type hints: Make code maintainable
- Docstrings: Explain function purpose and parameters
- TODOs: Mark customization points for users
- Visualizations: Help users understand results
- PEP 8 compliance: Clean, readable Python
- Comments: Explain complex logic
- Examples: Show usage patterns
Output Format
Always provide:
- Complete code file - Customized from template
- requirements.txt - Dependencies (pandas, nixtla, matplotlib)
- README.md - Setup and usage instructions
- Example data format - CSV structure with column names
- .env.example - API key template
- Usage examples - How to run the pipeline
Template Customization Guide
When customizing the template:
- Update
DATA_PATH,HORIZON,FREQinmain()function - Adjust frequency in
load_data()date range check - Modify confidence interval levels in
forecast()method - Add custom validation rules in
load_data()if needed - Include additional methods for advanced features (multi-series, regressors, CV)