Skip to main content

ModelGPT

LLM-powered AutoML. Describe your dataset, pick a task — ModelGPT asks an LLM to design, tune, and fit the best model for you. Works with OpenAI, Anthropic, Groq, Ollama, and any other LiteLLM-supported provider.

from modelgpt import ModelGPT

mg = ModelGPT(model="gpt-4o-mini", api_key="sk-...")
model = mg.fit(X_train, y_train, task="regression")
predictions = model.predict(X_test)

How it works

Your data  ──▶  Dataset summary  ──▶  LLM prompt
                                          │
                                          ▼
                                 LLM generates Python
                                 (ensemble + CV tuning)
                                          │
                                          ▼
                                   Sandboxed execution
                            (subprocess isolation, timeout=120s,
                            crash & resource containment)
                                          │
                             ┌────────────┴────────────┐
                             ▼                         ▼
                       Fitted model           Error? retry (→ LLM
                       returned               sees error, self-corrects)
                                                       │
                                              Max retries hit?
                                                       ▼
                                              Safe fallback model

ModelGPT feeds the LLM a structured dataset summary (shape, dtypes, missing values, target statistics, class distribution). The LLM returns raw Python that uses cross-validated hyperparameter search and an ensemble method. That code runs in a controlled namespace with X and y already bound. If it fails, the error is sent back to the LLM for self-correction — up to max_retries times. If every retry fails, ModelGPT falls back to a safe, well-tuned GradientBoosting model so .fit() never crashes your pipeline.


Installation

Install the base package plus whichever backend you want to use:

pip install modelgpt[openai]      # OpenAI (gpt-4o, gpt-4o-mini, …)
pip install modelgpt[anthropic]   # Anthropic (claude-haiku-4-5, claude-opus-4-5, …)
pip install modelgpt[groq]        # Groq (fast + free tier)
pip install modelgpt[ollama]      # Ollama (local, no API key needed)
pip install modelgpt[all]         # everything including xgboost, lightgbm, catboost

Quickstart

OpenAI

from modelgpt import ModelGPT

mg = ModelGPT(model="gpt-4o-mini", api_key="sk-...")
model = mg.fit(X_train, y_train, task="regression", metric="RMSE")
predictions = model.predict(X_test)

Anthropic

mg = ModelGPT(model="claude-haiku-4-5", api_key="sk-ant-...")
model = mg.fit(X_train, y_train, task="classification", metric="AUC")

Groq

mg = ModelGPT(model="groq/llama3-70b-8192", api_key="gsk_...")
model = mg.fit(X_train, y_train, task="classification")

Ollama (local, no API key)

# First: install Ollama (https://ollama.com/download), then:
ollama pull qwen2.5-coder:7b
ollama serve
mg = ModelGPT(model="ollama/qwen2.5-coder:7b")
model = mg.fit(X_train, y_train, task="regression")

Using environment variables instead of passing api_key

export OPENAI_API_KEY="sk-..."
export ANTHROPIC_API_KEY="sk-ant-..."
export GROQ_API_KEY="gsk_..."
mg = ModelGPT(model="gpt-4o-mini")   # picks up key from env automatically

API Reference

ModelGPT(model, api_key, max_retries, verbose)

Parameter Type Default Description
model str "gpt-4o-mini" Any LiteLLM model string (see examples above)
api_key str | None None API key for the backend. If None, reads from environment variable
max_retries int 3 How many times to retry + self-correct on code execution failure
verbose bool True Print generated code and progress to stdout

.fit(X, y, task, metric)

Parameter Type Default Description
X pd.DataFrame — Feature matrix
y pd.Series — Target vector
task str "regression" "regression" or "classification"
metric str | None None Metric hint passed to the LLM (e.g. "RMSE", "AUC", "F1")

Returns a fitted sklearn-compatible model with a .predict() method.


Choosing a model

Larger and more capable models tend to generate better, more reliable code. Here are some good options ranked by capability:

Provider Model string Notes
OpenAI "gpt-4o" Best results
OpenAI "gpt-4o-mini" Fast, cheap, good default
Anthropic "claude-opus-4-5" Excellent code generation
Anthropic "claude-haiku-4-5" Fast and affordable
Groq "groq/llama3-70b-8192" Very fast, free tier available
Ollama "ollama/qwen2.5-coder:7b" Local, fully private
Ollama "ollama/qwen2.5-coder:32b" Local, best quality

Tips for better results

Tell the LLM which metric matters. The metric argument is forwarded directly into the prompt:

model = mg.fit(X_train, y_train, task="regression", metric="RMSE")
model = mg.fit(X_train, y_train, task="classification", metric="AUC")

Increase retries for hard tasks. If the LLM frequently generates broken code, raise max_retries:

mg = ModelGPT(model="gpt-4o-mini", max_retries=5)

Inspect what was generated. With verbose=True (the default) the full generated code is printed. You can copy it, tweak it, and re-run it manually.

Fallback is always safe. If every retry fails, ModelGPT automatically falls back to a well-tuned GradientBoostingRegressor / GradientBoostingClassifier, so .fit() never crashes your pipeline.

Install the boosting extras for the best LLM-generated models:

pip install modelgpt[boosting]   # adds xgboost, lightgbm, catboost

Project structure

modelGPT/
├── modelgpt/
│   ├── __init__.py          # Public API
│   └── modelgpt.py          # Core ModelGPT class
├── tests/                   # Test suite
├── example/
│   └── example_usage.py     # Quickstart demo (diabetes dataset)
├── pyproject.toml
└── README.md

Requirements

  • Python ≥ 3.10
  • litellm, pandas, scikit-learn, numpy (installed automatically)
  • An API key for your chosen backend or Ollama running locally

License

MIT

Metadata

Release files for modelgpt 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for modelgpt 0.2.2
File Size Uploaded Provenance
modelgpt-0.2.2.tar.gz 15.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for modelgpt 0.2.2
File Interpreter ABI Platform
modelgpt-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 25.6 kB

Release files / modelgpt-0.2.2.tar.gz

Download URL modelgpt-0.2.2.tar.gz
Size 15.9 kB
Tags Source
SHA-256 checksum
How to use checksums
b7399f9f45fa6c908ef0ca33affdfb3bd73516021dcf8f24fa29cda1b68eab58
BLAKE2b-256 checksum
How to use checksums
a58ace6676333384fe1f097b2af196de892c7d5a4848baffb3d586cd0ecf866a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.0

Release files / modelgpt-0.2.2-py3-none-any.whl

Download URL modelgpt-0.2.2-py3-none-any.whl
Size 9.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cae50f554f4a49948f3c02b053d518638df6d265fbc20920db757de58792271e
BLAKE2b-256 checksum
How to use checksums
f5bc617090648af2d915e5eab0de17c115d8f17236214167eb79f715e878946a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.0

Security for modelgpt 0.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page