```
feat(api): 添加万川平台模型配置获取和同步功能 - 新增 getWanchuanModelConfig 函数,按模型编码获取平台模型配置 - 新增 syncWanchuanModelToSettings 函数,从万川平台拉取模型配置并写入后端 AI 设置 - 支持按用途分多个模型编码(generic/vision/voice)分别同步配置 - 配置失败时跳过对应字段,不影响其他模型同步 feat(settings): 重构AI模型配置界面支持多模块分组 - 将AI配置按话题分析、报告生成、视觉、语音四个模块分组展示 - 每个模块独立配置接口地址、密钥和模型名称 - 添加从万川平台获取配置的按钮和同步功能 - 优化配置状态指示和错误提示信息 refactor(config): 扩展AI配置支持独立的语音视觉报告网关 - 新增 voice_base_url/voice_api_key 配置项 - 新增 vision_base_url/vision_api_key 配置项 - 新增 summary_base_url/summary_api_key 配置项 - 留空时回退到 ai_base_url/ai_api_key 兼容单网关场景 refactor(http): 统一使用共享HTTP客户端减少连接开销 - 替换各处 httpx.AsyncClient 为 shared_client - 在 lifespan 中正确关闭共享客户端资源 - 优化 get_current_wxid 和 health 检查中的HTTP请求 refactor(ai): 按用途缓存AI客户端支持不同网关配置 - 重构 get_openai_client 支持按(base_url, api_key)缓存 - 新增 get_client_for 函数按用途获取对应客户端 - 支持语音、视觉、报告等不同用途使用独立网关和密钥 ```
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import aiosqlite
|
||||
import asyncio
|
||||
import httpx
|
||||
import logging
|
||||
import time
|
||||
from pathlib import Path
|
||||
from config import settings
|
||||
from services.http_client import shared_client
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -44,35 +44,35 @@ async def get_current_wxid(force: bool = False):
|
||||
return _resolved_wxid
|
||||
# 重新解析当前 wxid
|
||||
base = settings.chatlog_base_url
|
||||
async with httpx.AsyncClient(trust_env=False, timeout=10.0) as client:
|
||||
try:
|
||||
r = await client.get(f"{base}/api/v1/chatlog", params={"talker": "filehelper", "limit": 100, "time": "1970-01-01,2099-12-31", "format": "json"})
|
||||
if r.status_code == 200:
|
||||
data = r.json()
|
||||
for msg in data.get("items", []):
|
||||
if msg.get("isSelf"):
|
||||
_resolved_wxid = msg.get("sender")
|
||||
_wxid_last_resolved = time.time()
|
||||
return _resolved_wxid
|
||||
except Exception:
|
||||
pass
|
||||
client = shared_client()
|
||||
try:
|
||||
r = await client.get(f"{base}/api/v1/chatlog", params={"talker": "filehelper", "limit": 100, "time": "1970-01-01,2099-12-31", "format": "json"}, timeout=10.0)
|
||||
if r.status_code == 200:
|
||||
data = r.json()
|
||||
for msg in data.get("items", []):
|
||||
if msg.get("isSelf"):
|
||||
_resolved_wxid = msg.get("sender")
|
||||
_wxid_last_resolved = time.time()
|
||||
return _resolved_wxid
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
r = await client.get(f"{base}/api/v1/chatroom", params={"limit": 10, "format": "json"})
|
||||
if r.status_code == 200:
|
||||
rooms = r.json().get("items", [])
|
||||
for room in rooms:
|
||||
room_id = room.get("name")
|
||||
r2 = await client.get(f"{base}/api/v1/chatlog", params={"talker": room_id, "limit": 50, "time": "1970-01-01,2099-12-31", "format": "json"})
|
||||
if r2.status_code == 200:
|
||||
data2 = r2.json()
|
||||
for msg in data2.get("items", []):
|
||||
if msg.get("isSelf"):
|
||||
_resolved_wxid = msg.get("sender")
|
||||
_wxid_last_resolved = time.time()
|
||||
return _resolved_wxid
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
r = await client.get(f"{base}/api/v1/chatroom", params={"limit": 10, "format": "json"}, timeout=10.0)
|
||||
if r.status_code == 200:
|
||||
rooms = r.json().get("items", [])
|
||||
for room in rooms:
|
||||
room_id = room.get("name")
|
||||
r2 = await client.get(f"{base}/api/v1/chatlog", params={"talker": room_id, "limit": 50, "time": "1970-01-01,2099-12-31", "format": "json"}, timeout=10.0)
|
||||
if r2.status_code == 200:
|
||||
data2 = r2.json()
|
||||
for msg in data2.get("items", []):
|
||||
if msg.get("isSelf"):
|
||||
_resolved_wxid = msg.get("sender")
|
||||
_wxid_last_resolved = time.time()
|
||||
return _resolved_wxid
|
||||
except Exception:
|
||||
pass
|
||||
if force:
|
||||
reset_wxid_cache()
|
||||
return "default"
|
||||
@@ -85,6 +85,10 @@ async def update_db_path(force: bool = False):
|
||||
log.info(f"Switching database to {new_path}")
|
||||
_current_db_path = new_path
|
||||
await init_db(new_path)
|
||||
# 账号切换:清掉 chatlog 客户端的 contact 库路径与头像缓存,避免显示上一个账号的头像。
|
||||
# 局部导入避免潜在的模块循环引用。
|
||||
from services.chatlog_client import chatlog_client
|
||||
chatlog_client.reset_account_cache()
|
||||
return _current_db_path
|
||||
|
||||
def get_active_db_path():
|
||||
|
||||
Reference in New Issue
Block a user