mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 00:08:25 +00:00
feat(core): optionally populate development AI providers (#6779)
* feat(core): optionally populate an instance OpenAI provider * refactor(core): keep OpenAI population configuration in dev settings * chore(core): remove development population tests * feat(core): populate OpenAI with a low-cost model * feat(core): optionally populate an Anthropic provider and model * fix(dev): forward AI population settings to Docker backend * docs: explain AI provider populate key files in the dev env examples --------- Co-authored-by: peter_baserow <peter@baserow.io>
This commit is contained in:
1 parent
0a1e6ad46b
commit
8166af55d4
5 files changed
+73
No files matched your search
@@ -22,6 +22,11 @@ COMPOSE_PROFILES=optional
|
||||
# BASEROW_ASSISTANT_PHOENIX_URL=http://phoenix:6006
|
||||
# Only needed when pointing at an auth-enabled (team) Phoenix instance:
|
||||
# BASEROW_ASSISTANT_PHOENIX_API_KEY=
|
||||
# AI providers created by populate_test_data from files that contain only the API
|
||||
# key. Paths are inside the backend container; ./backend is mounted at
|
||||
# /baserow/backend and backend/.local/ is gitignored. See settings/dev.py.
|
||||
# BASEROW_DEV_POPULATE_OPENAI_API_KEY_FILE=/baserow/backend/.local/openai-key
|
||||
# BASEROW_DEV_POPULATE_ANTHROPIC_API_KEY_FILE=/baserow/backend/.local/anthropic-key
|
||||
# Inbound email receiver (mox) for the "Start workflow by email" automation
|
||||
# trigger, SMTP published on localhost:2025. Setting both variables below makes
|
||||
# `just dc-dev up` enable the "inbound-email" profile and start the receiver
|
||||
|
||||
@@ -176,6 +176,15 @@ EMAIL_PORT=1025
|
||||
# Run celery tasks synchronously (no separate worker needed)
|
||||
# CELERY_TASK_ALWAYS_EAGER=true
|
||||
|
||||
# =============================================================================
|
||||
# Optional: AI providers created by populate_test_data
|
||||
# =============================================================================
|
||||
# Absolute paths to untracked files that contain only the API key. Each provider
|
||||
# is created once, when absent, without any network call. See settings/dev.py.
|
||||
# backend/.local/ is gitignored and also visible to the Docker dev backend.
|
||||
# BASEROW_DEV_POPULATE_OPENAI_API_KEY_FILE=/absolute/path/to/backend/.local/openai-key
|
||||
# BASEROW_DEV_POPULATE_ANTHROPIC_API_KEY_FILE=/absolute/path/to/backend/.local/anthropic-key
|
||||
|
||||
# =============================================================================
|
||||
# Media files (path relative to the backend folder)
|
||||
# =============================================================================
|
||||
|
||||
@@ -18,6 +18,23 @@ BUILDER_PREVIEW_HANDOFF_TTL_SECONDS = 5 * 60
|
||||
BASEROW_WEBHOOKS_MAX_CONSECUTIVE_TRIGGER_FAILURES = 4
|
||||
BASEROW_WEBHOOKS_MAX_RETRIES_PER_CALL = 4
|
||||
|
||||
# Optional development-only AI provider/model creation during populate_test_data.
|
||||
# Set either/both variables to absolute paths to untracked UTF-8 API key files
|
||||
# (chmod 600). Example: BASEROW_DEV_POPULATE_OPENAI_API_KEY_FILE=/path/to/openai-key
|
||||
# Each file must contain only the key: its whole content, stripped of surrounding
|
||||
# whitespace, is stored as the API key. Unset/empty means opt out for that provider. Existing instance providers are
|
||||
# preserved; otherwise unreadable/empty files fail population. Creates low-cost
|
||||
# gpt-5.6-luna (OpenAI) or claude-haiku-5-5 (Anthropic) models without discovery,
|
||||
# testing, or network calls. Docker dev passes these variables to the backend;
|
||||
# use paths inside the container and mount the key files read-only via a local
|
||||
# Compose override when they are outside the existing bind mounts.
|
||||
BASEROW_DEV_POPULATE_OPENAI_API_KEY_FILE = os.getenv(
|
||||
"BASEROW_DEV_POPULATE_OPENAI_API_KEY_FILE", ""
|
||||
)
|
||||
BASEROW_DEV_POPULATE_ANTHROPIC_API_KEY_FILE = os.getenv(
|
||||
"BASEROW_DEV_POPULATE_ANTHROPIC_API_KEY_FILE", ""
|
||||
)
|
||||
|
||||
INSTALLED_APPS.insert(0, "daphne") # noqa: F405
|
||||
INSTALLED_APPS += ["django_extensions"] # noqa: F405
|
||||
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
from pathlib import Path
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.core.management import CommandError
|
||||
from django.db import transaction
|
||||
|
||||
from baserow.core.ai_provider.handler import AIProviderHandler
|
||||
from baserow.core.ai_provider.models import AIProviderConfig
|
||||
from baserow.core.handler import CoreHandler
|
||||
from baserow.core.models import Workspace, WorkspaceUser
|
||||
from baserow.core.user.exceptions import UserAlreadyExist
|
||||
@@ -11,6 +17,9 @@ User = get_user_model()
|
||||
|
||||
@transaction.atomic
|
||||
def load_test_data():
|
||||
"""Populate development users, workspaces, and optional instance AI providers."""
|
||||
|
||||
load_test_ai_providers()
|
||||
print("Add basic users...")
|
||||
user_handler = UserHandler()
|
||||
|
||||
@@ -82,3 +91,34 @@ def load_test_data():
|
||||
user=member,
|
||||
defaults=dict(permissions="MEMBER", order=j + 2),
|
||||
)
|
||||
|
||||
|
||||
def load_test_ai_providers():
|
||||
"""Create opted-in instance providers and models once, without network calls."""
|
||||
|
||||
for provider_type, model_identifier in (
|
||||
("openai", "gpt-5.6-luna"),
|
||||
("anthropic", "claude-haiku-5-5"),
|
||||
):
|
||||
setting_name = f"BASEROW_DEV_POPULATE_{provider_type.upper()}_API_KEY_FILE"
|
||||
key_file = getattr(settings, setting_name, "")
|
||||
if (
|
||||
not key_file
|
||||
or AIProviderConfig.objects.filter(
|
||||
workspace__isnull=True, provider_type=provider_type
|
||||
).exists()
|
||||
):
|
||||
continue
|
||||
|
||||
try:
|
||||
api_key = Path(key_file).read_text(encoding="utf-8").strip()
|
||||
except (OSError, UnicodeError):
|
||||
raise CommandError(f"Cannot read {setting_name}.") from None
|
||||
if not api_key:
|
||||
raise CommandError(f"{setting_name} must not be empty.")
|
||||
|
||||
AIProviderHandler.create_provider(
|
||||
provider_type,
|
||||
api_key=api_key,
|
||||
models_data=[{"model_identifier": model_identifier}],
|
||||
)
|
||||
@@ -26,6 +26,8 @@ services:
|
||||
environment:
|
||||
- OAUTHLIB_INSECURE_TRANSPORT
|
||||
- BASEROW_BACKEND_DEBUGGER_ENABLED
|
||||
- BASEROW_DEV_POPULATE_OPENAI_API_KEY_FILE
|
||||
- BASEROW_DEV_POPULATE_ANTHROPIC_API_KEY_FILE
|
||||
- BASEROW_BACKEND_DEBUGGER_PORT=${BASEROW_BACKEND_DEBUGGER_PORT:-5678}
|
||||
- BASEROW_DANGEROUS_SILKY_ANALYZE_QUERIES
|
||||
- BASEROW_ENABLE_SILK
|
||||
|
||||
Reference in new issue
Block a user