#!/usr/bin/env python3 """初始化配置""" import sys sys.path.insert(0, '/home/xian/.openclaw/workspace-coder/works/ai-chat') from models import SessionLocal, SystemConfig, init_db # 初始化数据库 init_db() db = SessionLocal() # 配置AI模型 configs = [ {'key': 'ai_api_base', 'value': 'http://192.168.2.17:19007/v1', 'description': 'AI模型API地址'}, {'key': 'ai_api_key', 'value': 'xxxx', 'description': 'AI模型API Key'}, {'key': 'ai_model', 'value': 'auto', 'description': 'AI模型名称'}, # 配置Matrix Bot {'key': 'matrix_homeserver', 'value': 'http://matrix.tphai.com', 'description': 'Matrix服务器地址'}, {'key': 'matrix_username', 'value': '@tester:matrix.tphai.com', 'description': 'Matrix Bot用户名'}, {'key': 'matrix_access_token', 'value': 'syt_dGVzdGVy_eMwWfezCXSyBgHzvkmly_4dWFtM', 'description': 'Matrix Bot Access Token'}, ] for config in configs: existing = db.query(SystemConfig).filter(SystemConfig.key == config['key']).first() if existing: existing.value = config['value'] existing.description = config['description'] else: db.add(SystemConfig(**config)) db.commit() print("配置已写入数据库") # 显示配置 for c in db.query(SystemConfig).all(): print(f"{c.key}: {c.value}") db.close()