LangFuse / app.py
Chris4K's picture
pin langfuse major version 2 (#1)
afc5295 verified
raw
history blame
1.87 kB
import os
import subprocess
import secrets
import string
def generate_secure_string(length=32):
"""Generate a secure random string."""
alphabet = string.ascii_letters + string.digits
return ''.join(secrets.choice(alphabet) for _ in range(length))
def run_langfuse():
# Hardcoded configuration with dynamically generated secrets
env_vars = {
# Postgres database - using SQLite as a simple alternative
'DATABASE_URL': 'file:///data/langfuse.db',
# Dynamically generated secrets
'NEXTAUTH_URL': 'https://chris4k-langfuse.hf.space',
'NEXTAUTH_SECRET': generate_secure_string(64),
'SALT': generate_secure_string(32),
'ENCRYPTION_KEY': secrets.token_hex(32), # 64-character hex string
# Additional configuration
'HOSTNAME': '0.0.0.0',
'PORT': '3000',
# Disable signup if needed
'AUTH_DISABLE_SIGNUP': 'false',
# Optional: Initial user creation
'LANGFUSE_INIT_USER_EMAIL': 'admin@example.com',
'LANGFUSE_INIT_USER_PASSWORD': generate_secure_string(12),
}
# Pull Langfuse Docker image
subprocess.run(['docker', 'pull', 'langfuse/langfuse:2'], check=True)
# Prepare Docker run command
docker_cmd = [
'docker', 'run', '-d',
'-p', '3000:3000',
'-v', '/data:/data' # Persist data
]
# Add environment variables
for key, value in env_vars.items():
docker_cmd.extend(['-e', f'{key}={value}'])
docker_cmd.append('langfuse/langfuse:2')
# Run the container
subprocess.run(docker_cmd, check=True)
print("Langfuse is running!")
print(f"Initial admin email: {env_vars['LANGFUSE_INIT_USER_EMAIL']}")
print(f"Initial admin password: {env_vars['LANGFUSE_INIT_USER_PASSWORD']}")
if __name__ == "__main__":
run_langfuse()