Skip to content

Commit 1b35388

Browse files
committed
Use toml for config
1 parent ace1f19 commit 1b35388

File tree

6 files changed

+79
-42
lines changed

6 files changed

+79
-42
lines changed

llmstack/.env.local

Lines changed: 0 additions & 29 deletions
This file was deleted.

llmstack/base/management/commands/loadfixtures.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
13
from django.contrib.auth.models import User
24
from django.core.management import call_command
35
from django.core.management.base import BaseCommand
@@ -8,7 +10,8 @@ class Command(BaseCommand):
810

911
def handle(self, *args, **options):
1012
if not User.objects.exists():
11-
User.objects.create_superuser('admin', '', 'promptly')
13+
User.objects.create_superuser(os.getenv('ADMIN_USERNAME', 'admin'), os.getenv(
14+
'ADMIN_EMAIL', ''), os.getenv('ADMIN_PASSWORD', 'promptly'))
1215
self.stdout.write(self.style.SUCCESS('Admin user created.'))
1316

1417
try:

llmstack/cli.py

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,68 @@ def prepare_env():
1515
If it doesn't exist, creates it and returns the .env.local file path.
1616
"""
1717
if not os.path.exists('.llmstack') and not os.path.exists(os.path.join(os.path.expanduser('~'), '.llmstack')):
18+
# Create .llmstack dir in user's home dir
1819
os.mkdir(os.path.join(os.path.expanduser('~'), '.llmstack'))
1920

20-
# Copy .env.local file from installed package to ~/.llmstack/.env.local
21+
if not os.path.exists('.llmstack/config') and not os.path.exists(os.path.join(os.path.expanduser('~'), '.llmstack/config')):
22+
# Copy config.toml file from installed package to ~/.llmstack/config
2123
import shutil
22-
shutil.copyfile(os.path.join(os.path.dirname(__file__), '.env.local'), os.path.join(
23-
os.path.expanduser('~'), '.llmstack', '.env.local'))
24+
shutil.copyfile(os.path.join(os.path.dirname(__file__), 'config.toml'), os.path.join(
25+
os.path.expanduser('~'), '.llmstack', 'config'))
26+
27+
# Given this is the first time the user is running llmstack, we should
28+
# ask the user for secret key, cipher_key_salt, database_password and save it in the config file
29+
import toml
30+
import secrets
31+
config_path = os.path.join(
32+
os.path.expanduser('~'), '.llmstack', 'config')
33+
config = {}
34+
with open(config_path) as f:
35+
config = toml.load(f)
36+
config['llmstack']['secret_key'] = secrets.token_urlsafe(32)
37+
config['llmstack']['cipher_key_salt'] = secrets.token_urlsafe(32)
38+
config['llmstack']['database_password'] = secrets.token_urlsafe(32)
39+
# Ask the user for admin username, email and password
40+
sys.stdout.write(
41+
'It looks like you are running LLMStack for the first time. Please provide the following information:\n\n')
42+
43+
config['llmstack']['admin_username'] = input(
44+
'Enter admin username: (default: admin)') or 'admin'
45+
config['llmstack']['admin_email'] = input(
46+
'Enter admin email: ') or ''
47+
config['llmstack']['admin_password'] = input(
48+
'Enter admin password: (default: promptly) ') or 'promptly'
49+
config['llmstack']['default_openai_api_key'] = input(
50+
'Enter default OpenAI API key: (Leave empty to configure in settings later) ') or ''
51+
with open(config_path, 'w') as f:
52+
toml.dump(config, f)
2453

2554
# Chdir to .llmstack
2655
if not os.path.exists('.llmstack') and os.path.exists(os.path.join(os.path.expanduser('~'), '.llmstack')):
2756
os.chdir(os.path.join(os.path.expanduser('~'), '.llmstack'))
2857
elif os.path.exists('.llmstack'):
2958
os.chdir('.llmstack')
3059

31-
# Throw error if .env.local file doesn't exist
32-
if not os.path.exists('.env.local'):
60+
# Throw error if config file doesn't exist
61+
if not os.path.exists('config'):
3362
sys.exit(
34-
'ERROR: .env.local file not found. Please create one in ~/.llmstack/.env.local')
63+
'ERROR: config file not found. Please create one in ~/.llmstack/config')
3564

36-
return os.path.join('.env.local')
65+
return os.path.join('config')
3766

3867

3968
def main():
4069
"""Main entry point for the application script"""
4170

42-
# Get .env.local file path
71+
# Get config file path
4372
env_path = prepare_env()
4473

45-
# Load environment variables from .env.local file
46-
from dotenv import load_dotenv
47-
load_dotenv(env_path)
74+
# Load environment variables from config under [llmstack] section
75+
import toml
76+
with open(env_path) as f:
77+
config = toml.load(f)
78+
for key in config['llmstack']:
79+
os.environ[key.upper()] = str(config['llmstack'][key])
4880

4981
if len(sys.argv) > 1 and sys.argv[1] == 'runserver':
5082
print('Starting LLMStack')

llmstack/config.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[llmstack]
2+
llmstack_port=3000
3+
4+
# Platform default keys (optional)
5+
default_openai_api_key=""
6+
default_dreamstudio_api_key=""
7+
default_azure_openai_api_key=""
8+
default_cohere_api_key=""
9+
default_forefront_api_key=""
10+
default_elevenlabs_api_key=""
11+
12+
# Local installation
13+
default_vector_database_path="./llmstack.chromadb"
14+
default_vector_database="chroma"
15+
use_remote_job_queue="False"
16+
cache_backend="locmem.LocMemCache"
17+
database_name="./llmstack.sqlite"
18+
database_engine="sqlite3"
19+
debug="True"

poetry.lock

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ python-magic = {version = "0.4.27", allow-prereleases = true}
127127
openai = {version = "0.27.0", allow-prereleases = true}
128128
stability-sdk = {version = "0.8.4", allow-prereleases = true}
129129
anthropic = "^0.3.11"
130+
toml = "^0.10.2"
130131

131132
[tool.poetry-dynamic-versioning]
132133
enable = true

0 commit comments

Comments
 (0)