Skip to content
This repository was archived by the owner on Mar 29, 2026. It is now read-only.

feat: Add ModelsLab LLM for text-to-SQL#1097

Open
adhikjoshi wants to merge 1 commit into
vanna-ai:mainfrom
adhikjoshi:m
Open

feat: Add ModelsLab LLM for text-to-SQL#1097
adhikjoshi wants to merge 1 commit into
vanna-ai:mainfrom
adhikjoshi:m

Conversation

@adhikjoshi

Copy link
Copy Markdown

feat: Add ModelsLab LLM integration

Summary

Adds ModelsLab as a new LLM integration in
src/vanna/integrations/modelslab/, giving Vanna users access to ModelsLab's
uncensored Llama-based models for SQL generation, explanation, and chart code.

ModelsLab's chat API is fully OpenAI-compatible, so ModelsLabLlmService
extends OpenAILlmService and inherits all streaming, tool-calling, and
structured-output features — zero code duplication.


Files changed

File Change
src/vanna/integrations/modelslab/__init__.py NEW: Package init & exports
src/vanna/integrations/modelslab/llm.py NEW: ModelsLabLlmService(OpenAILlmService)
tests/integrations/test_modelslab_llm.py NEW: 12 unit tests

Usage

import vanna
from vanna.integrations.modelslab import ModelsLabLlmService
from vanna.integrations.chromadb import ChromaDBVectorStore  # or your store

vn = vanna.create_client(
    llm=ModelsLabLlmService(
        model="llama-3.1-70b-uncensored",   # optional, default: 8b
        api_key="YOUR_MODELSLAB_API_KEY",   # or set MODELSLAB_API_KEY env var
    ),
    vector_store=ChromaDBVectorStore(),
)

# Train on your schema
vn.train(ddl="CREATE TABLE orders (id INT, amount DECIMAL, created_at DATE)")

# Generate SQL
sql = await vn.generate_sql("Show me monthly revenue for 2024")
print(sql)
# SELECT DATE_TRUNC('month', created_at) AS month,
#        SUM(amount) AS revenue
# FROM orders
# WHERE created_at BETWEEN '2024-01-01' AND '2024-12-31'
# GROUP BY 1 ORDER BY 1

Implementation

# src/vanna/integrations/modelslab/llm.py

class ModelsLabLlmService(OpenAILlmService):
    def __init__(self, model=None, api_key=None, base_url=None, **kwargs):
        resolved_api_key = api_key or os.getenv("MODELSLAB_API_KEY")
        if not resolved_api_key:
            raise ValueError("... set MODELSLAB_API_KEY ...")
        super().__init__(
            model=model or os.getenv("MODELSLAB_MODEL") or "llama-3.1-8b-uncensored",
            api_key=resolved_api_key,
            base_url=base_url or os.getenv("MODELSLAB_BASE_URL")
                     or "https://modelslab.com/api/uncensored-chat/v1",
            **kwargs,
        )

Supported models

Model Context Notes
llama-3.1-8b-uncensored (default) 128K Fast
llama-3.1-70b-uncensored 128K Higher quality

Environment variables

Variable Description
MODELSLAB_API_KEY API key (required)
MODELSLAB_MODEL Model ID override (optional)
MODELSLAB_BASE_URL Endpoint URL override (optional)

Testing

pip install pytest pytest-asyncio
pytest tests/integrations/test_modelslab_llm.py -v
# 12 tests — all pass

Checklist

  • New directory src/vanna/integrations/modelslab/ following existing structure
  • ModelsLabLlmService extends OpenAILlmService (no code duplication)
  • API key from arg OR MODELSLAB_API_KEY env var; clear error when missing
  • Model and base URL also configurable via env vars
  • __init__.py with __all__ exports
  • Unit tests covering: inheritance, init, default/custom model, API key
    (arg + env + missing), base URL (arg + env + default), constants

About ModelsLab

ModelsLab provides API access to uncensored Llama,
Flux, SDXL, video, audio, and 3D models. Their uncensored LLMs are useful for
Vanna when SQL generation requires reasoning about sensitive data topics without
content filters.

API docs: docs.modelslab.com
API keys: modelslab.com/api-keys

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant