feat: 支持Matrix access_token登录,配置AI模型接口
This commit is contained in:
@@ -14,7 +14,7 @@ import logging
|
||||
from datetime import datetime
|
||||
import os
|
||||
|
||||
from models import init_db, get_db, User, Conversation, Message, SystemConfig
|
||||
from models import init_db, get_db, SessionLocal, User, Conversation, Message, SystemConfig
|
||||
from services import ai_service, ConversationService, matrix_bot
|
||||
|
||||
# 配置日志
|
||||
@@ -379,7 +379,15 @@ async def update_config(data: dict, db: Session = Depends(get_db)):
|
||||
|
||||
db.commit()
|
||||
|
||||
# 如果更新了Matrix配置,重新连接
|
||||
# 根据配置类型执行相应操作
|
||||
if key.startswith('ai_'):
|
||||
# 更新AI服务配置
|
||||
configs = {c.key: c.value for c in db.query(SystemConfig).all()}
|
||||
api_base = configs.get('ai_api_base', 'http://192.168.2.17:19007/v1')
|
||||
api_key = configs.get('ai_api_key', 'xxxx')
|
||||
model = configs.get('ai_model', 'auto')
|
||||
ai_service.update_config(api_base, api_key, model)
|
||||
|
||||
if key.startswith('matrix_') and matrix_bot.is_running:
|
||||
await matrix_bot.disconnect()
|
||||
await matrix_bot.init_from_config()
|
||||
@@ -440,6 +448,18 @@ async def startup():
|
||||
init_db()
|
||||
logger.info("数据库初始化完成")
|
||||
|
||||
# 从数据库加载AI配置
|
||||
db = SessionLocal()
|
||||
try:
|
||||
configs = {c.key: c.value for c in db.query(SystemConfig).all()}
|
||||
api_base = configs.get('ai_api_base', 'http://192.168.2.17:19007/v1')
|
||||
api_key = configs.get('ai_api_key', 'xxxx')
|
||||
model = configs.get('ai_model', 'auto')
|
||||
ai_service.update_config(api_base, api_key, model)
|
||||
logger.info(f"AI配置已加载: {api_base}, model={model}")
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
# 初始化Matrix Bot
|
||||
await matrix_bot.init_from_config()
|
||||
if matrix_bot.is_running:
|
||||
|
||||
Reference in New Issue
Block a user