Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c725aeb192 | |||
| 423f3aa717 | |||
| 2f60e30169 | |||
| 4442d5056a |
174
backend/app.py
174
backend/app.py
@@ -76,14 +76,17 @@ def init_db():
|
||||
)
|
||||
''')
|
||||
|
||||
# 搜索配置表
|
||||
# 搜索配置表(改为工具配置)
|
||||
cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS search_configs (
|
||||
CREATE TABLE IF NOT EXISTS tool_configs (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
tool_id TEXT NOT NULL UNIQUE,
|
||||
name TEXT NOT NULL,
|
||||
type TEXT NOT NULL,
|
||||
provider TEXT NOT NULL,
|
||||
api_url TEXT NOT NULL,
|
||||
api_key TEXT NOT NULL,
|
||||
api_key TEXT,
|
||||
config_json TEXT,
|
||||
max_results INTEGER DEFAULT 10,
|
||||
is_default INTEGER DEFAULT 0,
|
||||
is_active INTEGER DEFAULT 1,
|
||||
@@ -92,6 +95,25 @@ def init_db():
|
||||
)
|
||||
''')
|
||||
|
||||
# 对话配置表
|
||||
cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS chat_configs (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
config_id TEXT NOT NULL UNIQUE,
|
||||
name TEXT NOT NULL,
|
||||
llm_config_id INTEGER,
|
||||
enable_search INTEGER DEFAULT 1,
|
||||
enable_tools TEXT,
|
||||
max_history INTEGER DEFAULT 20,
|
||||
temperature REAL DEFAULT 0.7,
|
||||
system_prompt TEXT,
|
||||
is_default INTEGER DEFAULT 1,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (llm_config_id) REFERENCES llm_configs(id)
|
||||
)
|
||||
''')
|
||||
|
||||
# 系统配置表
|
||||
cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS system_configs (
|
||||
@@ -133,13 +155,21 @@ def init_db():
|
||||
'2259e33a1357460abe17919aaf81e73d.K44a8LPQTmFM5PKm', 'glm-4.5-air', 1)
|
||||
''')
|
||||
|
||||
# 初始化默认搜索配置
|
||||
cursor.execute('SELECT COUNT(*) FROM search_configs')
|
||||
# 初始化默认工具配置(搜索工具)
|
||||
cursor.execute('SELECT COUNT(*) FROM tool_configs')
|
||||
if cursor.fetchone()[0] == 0:
|
||||
cursor.execute('''
|
||||
INSERT INTO search_configs (name, provider, api_url, api_key, is_default)
|
||||
VALUES ('Tavily', 'tavily', 'https://api.tavily.com/search',
|
||||
'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', 1)
|
||||
INSERT INTO tool_configs (tool_id, name, type, provider, api_url, api_key, max_results, is_default)
|
||||
VALUES ('search', '联网搜索', 'search', 'tavily', 'https://api.tavily.com/search',
|
||||
'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', 10, 1)
|
||||
''')
|
||||
|
||||
# 初始化默认对话配置
|
||||
cursor.execute('SELECT COUNT(*) FROM chat_configs')
|
||||
if cursor.fetchone()[0] == 0:
|
||||
cursor.execute('''
|
||||
INSERT INTO chat_configs (config_id, name, llm_config_id, enable_tools, is_default)
|
||||
VALUES ('default', '默认对话配置', 1, 'search', 1)
|
||||
''')
|
||||
|
||||
# 初始化默认智能体
|
||||
@@ -185,7 +215,7 @@ def init_db():
|
||||
# 初始化管理员账户
|
||||
cursor.execute('SELECT COUNT(*) FROM admin_users')
|
||||
if cursor.fetchone()[0] == 0:
|
||||
cursor.execute('INSERT INTO admin_users (username, password_hash) VALUES (?, ?',
|
||||
cursor.execute('INSERT INTO admin_users (username, password_hash) VALUES (?, ?)',
|
||||
(ADMIN_USERNAME, ADMIN_PASSWORD_HASH))
|
||||
|
||||
conn.commit()
|
||||
@@ -391,69 +421,114 @@ def delete_agent(agent_id):
|
||||
return jsonify({'success': True})
|
||||
|
||||
|
||||
# ==================== 搜索配置管理 ====================
|
||||
# ==================== 对话配置管理 ====================
|
||||
|
||||
@app.route('/api/admin/search', methods=['GET'])
|
||||
def get_search_configs():
|
||||
"""获取搜索配置"""
|
||||
@app.route('/api/admin/chat', methods=['GET'])
|
||||
def get_chat_config():
|
||||
"""获取对话配置(只有一个默认配置)"""
|
||||
conn = get_db()
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('SELECT * FROM search_configs ORDER BY is_default DESC')
|
||||
configs = [dict(row) for row in cursor.fetchall()]
|
||||
cursor.execute('SELECT * FROM chat_configs WHERE is_default=1 LIMIT 1')
|
||||
config = cursor.fetchone()
|
||||
|
||||
if not config:
|
||||
# 如果没有配置,创建默认配置
|
||||
cursor.execute('''
|
||||
INSERT INTO chat_configs (config_id, name, llm_config_id, enable_search, enable_tools, max_history, temperature, is_default)
|
||||
VALUES ('default', '默认配置', 1, 1, 'search', 20, 0.7, 1)
|
||||
''')
|
||||
conn.commit()
|
||||
cursor.execute('SELECT * FROM chat_configs WHERE is_default=1 LIMIT 1')
|
||||
config = cursor.fetchone()
|
||||
|
||||
conn.close()
|
||||
return jsonify(configs)
|
||||
return jsonify(dict(config) if config else {})
|
||||
|
||||
|
||||
@app.route('/api/admin/search', methods=['POST'])
|
||||
def add_search_config():
|
||||
"""添加搜索配置"""
|
||||
@app.route('/api/admin/chat', methods=['PUT'])
|
||||
def update_chat_config():
|
||||
"""更新对话配置"""
|
||||
data = request.json
|
||||
conn = get_db()
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('''
|
||||
INSERT INTO search_configs (name, provider, api_url, api_key, max_results)
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
''', (data['name'], data['provider'], data['api_url'], data['api_key'],
|
||||
UPDATE chat_configs SET
|
||||
llm_config_id=?, enable_search=?, enable_tools=?, max_history=?,
|
||||
temperature=?, system_prompt=?, updated_at=CURRENT_TIMESTAMP
|
||||
WHERE is_default=1
|
||||
''', (data.get('llm_config_id', 1), data.get('enable_search', 1),
|
||||
data.get('enable_tools', 'search'), data.get('max_history', 20),
|
||||
data.get('temperature', 0.7), data.get('system_prompt', '')))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return jsonify({'success': True})
|
||||
|
||||
|
||||
# ==================== 工具配置管理 ====================
|
||||
|
||||
@app.route('/api/admin/tools', methods=['GET'])
|
||||
def get_tool_configs():
|
||||
"""获取工具配置"""
|
||||
conn = get_db()
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('SELECT * FROM tool_configs ORDER BY is_default DESC, type')
|
||||
tools = [dict(row) for row in cursor.fetchall()]
|
||||
conn.close()
|
||||
return jsonify(tools)
|
||||
|
||||
|
||||
@app.route('/api/admin/tools', methods=['POST'])
|
||||
def add_tool_config():
|
||||
"""添加工具配置"""
|
||||
data = request.json
|
||||
conn = get_db()
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('''
|
||||
INSERT INTO tool_configs (tool_id, name, type, provider, api_url, api_key, config_json, max_results)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||
''', (data['tool_id'], data['name'], data['type'], data['provider'],
|
||||
data['api_url'], data.get('api_key', ''), data.get('config_json', ''),
|
||||
data.get('max_results', 10)))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return jsonify({'success': True})
|
||||
|
||||
|
||||
@app.route('/api/admin/search/<int:id>', methods=['PUT'])
|
||||
def update_search_config(id):
|
||||
"""更新搜索配置"""
|
||||
@app.route('/api/admin/tools/<tool_id>', methods=['PUT'])
|
||||
def update_tool_config(tool_id):
|
||||
"""更新工具配置"""
|
||||
data = request.json
|
||||
conn = get_db()
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('''
|
||||
UPDATE search_configs SET name=?, provider=?, api_url=?, api_key=?, max_results=?,
|
||||
updated_at=CURRENT_TIMESTAMP WHERE id=?
|
||||
''', (data['name'], data['provider'], data['api_url'], data['api_key'],
|
||||
data.get('max_results', 10), id))
|
||||
UPDATE tool_configs SET name=?, type=?, provider=?, api_url=?, api_key=?,
|
||||
config_json=?, max_results=?, updated_at=CURRENT_TIMESTAMP WHERE tool_id=?
|
||||
''', (data['name'], data['type'], data['provider'], data['api_url'],
|
||||
data.get('api_key', ''), data.get('config_json', ''),
|
||||
data.get('max_results', 10), tool_id))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return jsonify({'success': True})
|
||||
|
||||
|
||||
@app.route('/api/admin/search/<int:id>', methods=['DELETE'])
|
||||
def delete_search_config(id):
|
||||
"""删除搜索配置"""
|
||||
@app.route('/api/admin/tools/<tool_id>', methods=['DELETE'])
|
||||
def delete_tool_config(tool_id):
|
||||
"""删除工具配置"""
|
||||
conn = get_db()
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('DELETE FROM search_configs WHERE id=?', (id,))
|
||||
cursor.execute('DELETE FROM tool_configs WHERE tool_id=?', (tool_id,))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return jsonify({'success': True})
|
||||
|
||||
|
||||
@app.route('/api/admin/search/<int:id>/default', methods=['POST'])
|
||||
def set_default_search(id):
|
||||
"""设置默认搜索"""
|
||||
@app.route('/api/admin/tools/<tool_id>/default', methods=['POST'])
|
||||
def set_default_tool(tool_id):
|
||||
"""设置默认工具"""
|
||||
conn = get_db()
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('UPDATE search_configs SET is_default=0')
|
||||
cursor.execute('UPDATE search_configs SET is_default=1 WHERE id=?', (id,))
|
||||
cursor.execute('UPDATE tool_configs SET is_default=0 WHERE type=(SELECT type FROM tool_configs WHERE tool_id=?)', (tool_id,))
|
||||
cursor.execute('UPDATE tool_configs SET is_default=1 WHERE tool_id=?', (tool_id,))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return jsonify({'success': True})
|
||||
@@ -564,14 +639,18 @@ def get_frontend_config():
|
||||
cursor.execute('SELECT * FROM llm_configs WHERE is_default=1 AND is_active=1 LIMIT 1')
|
||||
llm = cursor.fetchone()
|
||||
|
||||
# 获取默认搜索配置
|
||||
cursor.execute('SELECT * FROM search_configs WHERE is_default=1 AND is_active=1 LIMIT 1')
|
||||
search = cursor.fetchone()
|
||||
# 获取默认工具配置(搜索等)
|
||||
cursor.execute('SELECT * FROM tool_configs WHERE is_default=1 AND is_active=1')
|
||||
tools = [dict(row) for row in cursor.fetchall()]
|
||||
|
||||
# 获取所有智能体
|
||||
cursor.execute('SELECT agent_id, name, avatar, category, description, system_prompt, heat FROM agents WHERE is_active=1')
|
||||
cursor.execute('SELECT agent_id, name, avatar, category, description, system_prompt, heat, enable_search FROM agents WHERE is_active=1')
|
||||
agents = [dict(row) for row in cursor.fetchall()]
|
||||
|
||||
# 获取默认对话配置
|
||||
cursor.execute('SELECT * FROM chat_configs WHERE is_default=1 LIMIT 1')
|
||||
chat_config = cursor.fetchone()
|
||||
|
||||
# 获取系统配置
|
||||
cursor.execute('SELECT key, value FROM system_configs')
|
||||
system = {row['key']: row['value'] for row in cursor.fetchall()}
|
||||
@@ -580,11 +659,12 @@ def get_frontend_config():
|
||||
|
||||
config = {
|
||||
'llm': dict(llm) if llm else None,
|
||||
'search': dict(search) if search else None,
|
||||
'tools': tools,
|
||||
'agents': agents,
|
||||
'chat_config': dict(chat_config) if chat_config else None,
|
||||
'system': {
|
||||
'appName': system.get('app_name', 'AI助手'),
|
||||
'version': system.get('app_version', '3.5.1'),
|
||||
'version': system.get('app_version', '3.6.0'),
|
||||
'enableSearch': system.get('enable_search', 'true') == 'true',
|
||||
'guestLimits': {
|
||||
'chatSessions': int(system.get('guest_chat_sessions', '1')),
|
||||
@@ -604,8 +684,8 @@ if __name__ == '__main__':
|
||||
init_db()
|
||||
|
||||
# 启动服务
|
||||
print('🚀 AI Chat App Backend started on http://localhost:19020')
|
||||
print('📊 Admin Panel: http://localhost:19020/admin')
|
||||
print('🚀 AI Chat App Backend started on http://localhost:19021')
|
||||
print('📊 Admin Panel: http://localhost:19021/admin')
|
||||
print('👤 Default admin: admin / admin123')
|
||||
|
||||
app.run(host='0.0.0.0', port=19020, debug=True)
|
||||
app.run(host='0.0.0.0', port=19021, debug=True)
|
||||
@@ -440,9 +440,13 @@
|
||||
<span class="sidebar-icon">🤖</span>
|
||||
<span>智能体管理</span>
|
||||
</div>
|
||||
<div class="sidebar-item" data-page="search">
|
||||
<span class="sidebar-icon">🔍</span>
|
||||
<span>搜索配置</span>
|
||||
<div class="sidebar-item" data-page="chat">
|
||||
<span class="sidebar-icon">💬</span>
|
||||
<span>对话配置</span>
|
||||
</div>
|
||||
<div class="sidebar-item" data-page="tools">
|
||||
<span class="sidebar-icon">🔧</span>
|
||||
<span>工具配置</span>
|
||||
</div>
|
||||
<div class="sidebar-item" data-page="system">
|
||||
<span class="sidebar-icon">⚙️</span>
|
||||
|
||||
337
www/admin.js
337
www/admin.js
@@ -5,7 +5,8 @@ const API_BASE = '';
|
||||
let currentPage = 'stats';
|
||||
let llmConfigs = [];
|
||||
let agents = [];
|
||||
let searchConfigs = [];
|
||||
let toolConfigs = [];
|
||||
let chatConfigs = [];
|
||||
let systemConfigs = {};
|
||||
|
||||
// ==================== 登录 ====================
|
||||
@@ -86,8 +87,11 @@ async function loadPage(page) {
|
||||
case 'agents':
|
||||
await loadAgentsPage(content);
|
||||
break;
|
||||
case 'search':
|
||||
await loadSearchPage(content);
|
||||
case 'chat':
|
||||
await loadChatConfigPage(content);
|
||||
break;
|
||||
case 'tools':
|
||||
await loadToolsPage(content);
|
||||
break;
|
||||
case 'system':
|
||||
await loadSystemPage(content);
|
||||
@@ -579,42 +583,166 @@ async function deleteAgent(agentId) {
|
||||
loadPage('agents');
|
||||
}
|
||||
|
||||
// ==================== 搜索配置页面 ====================
|
||||
// ==================== 对话配置页面 ====================
|
||||
|
||||
async function loadSearchPage(content) {
|
||||
searchConfigs = await fetchAPI('/api/admin/search');
|
||||
async function loadChatConfigPage(content) {
|
||||
llmConfigs = await fetchAPI('/api/admin/llm');
|
||||
toolConfigs = await fetchAPI('/api/admin/tools');
|
||||
const chatConfig = await fetchAPI('/api/admin/chat');
|
||||
|
||||
content.innerHTML = `
|
||||
<div class="content-header">
|
||||
<h1 class="content-title">搜索配置</h1>
|
||||
<button class="add-btn" onclick="showAddSearchModal()">+ 添加配置</button>
|
||||
<h1 class="content-title">对话配置</h1>
|
||||
</div>
|
||||
|
||||
<div style="background: white; padding: 24px; border-radius: 12px;">
|
||||
<p style="color: #718096; margin-bottom: 24px;">
|
||||
此配置对所有用户的普通对话生效,修改后立即生效。
|
||||
</p>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label">LLM 配置(对话使用的大模型)</label>
|
||||
<select class="form-select" id="chatLLMConfig">
|
||||
${llmConfigs.map(l => `<option value="${l.id}" ${l.id === chatConfig.llm_config_id ? 'selected' : ''}>${l.name}</option>`).join('')}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label style="display: flex; align-items: center; gap: 8px;">
|
||||
<input type="checkbox" id="chatEnableSearch" ${chatConfig.enable_search ? 'checked' : ''} onchange="toggleEnableSearch()">
|
||||
启用联网搜索
|
||||
</label>
|
||||
<span style="color: #999; font-size: 12px; margin-top: 4px;">开启后对话可联网搜索实时信息</span>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label">可用工具(逗号分隔)</label>
|
||||
<input type="text" class="form-input" id="chatEnableTools" value="${chatConfig.enable_tools || ''}" placeholder="如:search,calculator">
|
||||
<span style="color: #999; font-size: 12px;">已配置工具: ${toolConfigs.map(t => t.tool_id).join(', ')}</span>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label">历史记录数(对话上下文)</label>
|
||||
<input type="number" class="form-input" id="chatMaxHistory" value="${chatConfig.max_history || 20}">
|
||||
<span style="color: #999; font-size: 12px;">发送给模型的对话历史条数</span>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label">Temperature(创造性)</label>
|
||||
<input type="number" class="form-input" id="chatTemperature" value="${chatConfig.temperature || 0.7}" step="0.1" min="0" max="2">
|
||||
<span style="color: #999; font-size: 12px;">0-2之间,越高越随机创造性,越低越稳定精确</span>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label">系统提示词(可选)</label>
|
||||
<textarea class="form-textarea" id="chatSystemPrompt" placeholder="全局系统提示词,对所有对话生效">${chatConfig.system_prompt || ''}</textarea>
|
||||
</div>
|
||||
|
||||
<button class="form-submit" onclick="saveChatConfig()">保存配置</button>
|
||||
</div>
|
||||
|
||||
<div style="margin-top: 24px; padding: 16px; background: white; border-radius: 12px;">
|
||||
<h3 style="margin-bottom: 16px;">参数说明</h3>
|
||||
<div style="display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px;">
|
||||
<div style="padding: 12px; background: #f5f7fa; border-radius: 8px;">
|
||||
<strong>🧠 LLM配置</strong>
|
||||
<p style="color: #718096; font-size: 12px; margin-top: 4px;">选择对话使用的大模型接口</p>
|
||||
</div>
|
||||
<div style="padding: 12px; background: #f5f7fa; border-radius: 8px;">
|
||||
<strong>🔍 启用联网搜索</strong>
|
||||
<p style="color: #718096; font-size: 12px; margin-top: 4px;">用户可在对话中开启联网搜索</p>
|
||||
</div>
|
||||
<div style="padding: 12px; background: #f5f7fa; border-radius: 8px;">
|
||||
<strong>🔧 可用工具</strong>
|
||||
<p style="color: #718096; font-size: 12px; margin-top: 4px;">对话中可使用的工具列表</p>
|
||||
</div>
|
||||
<div style="padding: 12px; background: #f5f7fa; border-radius: 8px;">
|
||||
<strong>📜 历史记录数</strong>
|
||||
<p style="color: #718096; font-size: 12px; margin-top: 4px;">发送多少条历史对话给模型</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
function toggleEnableSearch() {
|
||||
const enableSearch = document.getElementById('chatEnableSearch').checked;
|
||||
const toolsInput = document.getElementById('chatEnableTools');
|
||||
|
||||
// 自动添加/移除 search 工具
|
||||
let tools = toolsInput.value.split(',').filter(t => t.trim());
|
||||
if (enableSearch) {
|
||||
if (!tools.includes('search')) {
|
||||
tools.push('search');
|
||||
}
|
||||
} else {
|
||||
tools = tools.filter(t => t !== 'search');
|
||||
}
|
||||
toolsInput.value = tools.join(',');
|
||||
}
|
||||
|
||||
async function saveChatConfig() {
|
||||
const data = {
|
||||
llm_config_id: parseInt(document.getElementById('chatLLMConfig').value),
|
||||
enable_search: document.getElementById('chatEnableSearch').checked ? 1 : 0,
|
||||
enable_tools: document.getElementById('chatEnableTools').value,
|
||||
max_history: parseInt(document.getElementById('chatMaxHistory').value),
|
||||
temperature: parseFloat(document.getElementById('chatTemperature').value),
|
||||
system_prompt: document.getElementById('chatSystemPrompt').value
|
||||
};
|
||||
|
||||
await fetchAPI('/api/admin/chat', 'PUT', data);
|
||||
showToast('保存成功');
|
||||
loadPage('chat');
|
||||
}
|
||||
|
||||
// ==================== 工具配置页面 ====================
|
||||
|
||||
async function loadToolsPage(content) {
|
||||
toolConfigs = await fetchAPI('/api/admin/tools');
|
||||
|
||||
const toolTypes = {
|
||||
search: '搜索工具',
|
||||
calculator: '计算器',
|
||||
image: '图像生成',
|
||||
code: '代码执行',
|
||||
weather: '天气查询',
|
||||
custom: '自定义'
|
||||
};
|
||||
|
||||
content.innerHTML = `
|
||||
<div class="content-header">
|
||||
<h1 class="content-title">工具配置</h1>
|
||||
<button class="add-btn" onclick="showAddToolModal()">+ 添加工具</button>
|
||||
</div>
|
||||
|
||||
<div class="data-table">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>工具ID</th>
|
||||
<th>名称</th>
|
||||
<th>类型</th>
|
||||
<th>提供商</th>
|
||||
<th>API URL</th>
|
||||
<th>最大结果数</th>
|
||||
<th>状态</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
${searchConfigs.map(c => `
|
||||
${toolConfigs.map(t => `
|
||||
<tr>
|
||||
<td>${c.name} ${c.is_default ? '<span class="default-badge">默认</span>' : ''}</td>
|
||||
<td>${c.provider}</td>
|
||||
<td style="max-width: 200px; overflow: hidden; text-overflow: ellipsis;">${c.api_url}</td>
|
||||
<td>${c.max_results}</td>
|
||||
<td>${c.is_active ? '✅ 启用' : '❌ 禁用'}</td>
|
||||
<td>${t.tool_id} ${t.is_default ? '<span class="default-badge">默认</span>' : ''}</td>
|
||||
<td>${t.name}</td>
|
||||
<td>${toolTypes[t.type] || t.type}</td>
|
||||
<td>${t.provider}</td>
|
||||
<td style="max-width: 200px; overflow: hidden; text-overflow: ellipsis;">${t.api_url}</td>
|
||||
<td>${t.is_active ? '✅ 启用' : '❌ 禁用'}</td>
|
||||
<td>
|
||||
<div class="action-btns">
|
||||
<button class="action-btn edit" onclick="showEditSearchModal(${c.id})">编辑</button>
|
||||
${!c.is_default ? `<button class="action-btn default" onclick="setDefaultSearch(${c.id})">设为默认</button>` : ''}
|
||||
<button class="action-btn delete" onclick="deleteSearch(${c.id})">删除</button>
|
||||
<button class="action-btn edit" onclick="showEditToolModal('${t.tool_id}')">编辑</button>
|
||||
${!t.is_default ? `<button class="action-btn default" onclick="setDefaultTool('${t.tool_id}')">设为默认</button>` : ''}
|
||||
<button class="action-btn delete" onclick="deleteTool('${t.tool_id}')">删除</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -622,120 +750,172 @@ async function loadSearchPage(content) {
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div style="margin-top: 24px; padding: 16px; background: white; border-radius: 12px;">
|
||||
<h3 style="margin-bottom: 16px;">工具类型说明</h3>
|
||||
<div style="display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px;">
|
||||
<div style="padding: 12px; background: #f5f7fa; border-radius: 8px;">
|
||||
<strong>🔍 search</strong>
|
||||
<p style="color: #718096; font-size: 12px; margin-top: 4px;">联网搜索工具(Tavily、Google等)</p>
|
||||
</div>
|
||||
<div style="padding: 12px; background: #f5f7fa; border-radius: 8px;">
|
||||
<strong>🧮 calculator</strong>
|
||||
<p style="color: #718096; font-size: 12px; margin-top: 4px;">数学计算工具</p>
|
||||
</div>
|
||||
<div style="padding: 12px; background: #f5f7fa; border-radius: 8px;">
|
||||
<strong>🎨 image</strong>
|
||||
<p style="color: #718096; font-size: 12px; margin-top: 4px;">图像生成工具(DALL-E等)</p>
|
||||
</div>
|
||||
<div style="padding: 12px; background: #f5f7fa; border-radius: 8px;">
|
||||
<strong>💻 code</strong>
|
||||
<p style="color: #718096; font-size: 12px; margin-top: 4px;">代码执行工具</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
function showAddSearchModal() {
|
||||
showModal('添加搜索配置', `
|
||||
function showAddToolModal() {
|
||||
showModal('添加工具', `
|
||||
<div class="form-group">
|
||||
<label class="form-label">名称</label>
|
||||
<input type="text" class="form-input" id="searchName" placeholder="如:Tavily">
|
||||
<label class="form-label">工具ID</label>
|
||||
<input type="text" class="form-input" id="toolId" placeholder="如:search">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">提供商</label>
|
||||
<select class="form-select" id="searchProvider">
|
||||
<option value="tavily">Tavily</option>
|
||||
<option value="google">Google</option>
|
||||
<option value="bing">Bing</option>
|
||||
<label class="form-label">名称</label>
|
||||
<input type="text" class="form-input" id="toolName" placeholder="如:联网搜索">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">类型</label>
|
||||
<select class="form-select" id="toolType">
|
||||
<option value="search">搜索工具</option>
|
||||
<option value="calculator">计算器</option>
|
||||
<option value="image">图像生成</option>
|
||||
<option value="code">代码执行</option>
|
||||
<option value="weather">天气查询</option>
|
||||
<option value="custom">自定义</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">提供商</label>
|
||||
<input type="text" class="form-input" id="toolProvider" placeholder="如:tavily">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">API URL</label>
|
||||
<input type="text" class="form-input" id="searchApiUrl" placeholder="API endpoint URL">
|
||||
<input type="text" class="form-input" id="toolApiUrl" placeholder="API endpoint URL">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">API Key</label>
|
||||
<input type="text" class="form-input" id="searchApiKey" placeholder="API Key">
|
||||
<input type="text" class="form-input" id="toolApiKey" placeholder="API Key(可选)">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">最大结果数</label>
|
||||
<input type="number" class="form-input" id="searchMaxResults" value="10">
|
||||
<input type="number" class="form-input" id="toolMaxResults" value="10">
|
||||
</div>
|
||||
<button class="form-submit" onclick="saveSearch()">保存</button>
|
||||
<div class="form-group">
|
||||
<label class="form-label">额外配置(JSON格式)</label>
|
||||
<textarea class="form-textarea" id="toolConfigJson" placeholder="{}"></textarea>
|
||||
</div>
|
||||
<button class="form-submit" onclick="saveTool()">保存</button>
|
||||
`);
|
||||
}
|
||||
|
||||
function showEditSearchModal(id) {
|
||||
const config = searchConfigs.find(c => c.id === id);
|
||||
if (!config) return;
|
||||
function showEditToolModal(toolId) {
|
||||
const tool = toolConfigs.find(t => t.tool_id === toolId);
|
||||
if (!tool) return;
|
||||
|
||||
showModal('编辑搜索配置', `
|
||||
const toolTypes = ['search', 'calculator', 'image', 'code', 'weather', 'custom'];
|
||||
|
||||
showModal('编辑工具', `
|
||||
<div class="form-group">
|
||||
<label class="form-label">名称</label>
|
||||
<input type="text" class="form-input" id="searchName" value="${config.name}">
|
||||
<label class="form-label">工具ID(不可修改)</label>
|
||||
<input type="text" class="form-input" id="toolId" value="${tool.tool_id}" readonly style="background: #f5f7fa;">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">提供商</label>
|
||||
<select class="form-select" id="searchProvider">
|
||||
<option value="tavily" ${config.provider === 'tavily' ? 'selected' : ''}>Tavily</option>
|
||||
<option value="google" ${config.provider === 'google' ? 'selected' : ''}>Google</option>
|
||||
<option value="bing" ${config.provider === 'bing' ? 'selected' : ''}>Bing</option>
|
||||
<option value="custom" ${config.provider === 'custom' ? 'selected' : ''}>自定义</option>
|
||||
<label class="form-label">名称</label>
|
||||
<input type="text" class="form-input" id="toolName" value="${tool.name}">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">类型</label>
|
||||
<select class="form-select" id="toolType">
|
||||
${toolTypes.map(t => `<option value="${t}" ${t === tool.type ? 'selected' : ''}>${t}</option>`).join('')}
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">提供商</label>
|
||||
<input type="text" class="form-input" id="toolProvider" value="${tool.provider}">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">API URL</label>
|
||||
<input type="text" class="form-input" id="searchApiUrl" value="${config.api_url}">
|
||||
<input type="text" class="form-input" id="toolApiUrl" value="${tool.api_url}">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">API Key</label>
|
||||
<input type="text" class="form-input" id="searchApiKey" value="${config.api_key}">
|
||||
<input type="text" class="form-input" id="toolApiKey" value="${tool.api_key || ''}">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">最大结果数</label>
|
||||
<input type="number" class="form-input" id="searchMaxResults" value="${config.max_results}">
|
||||
<input type="number" class="form-input" id="toolMaxResults" value="${tool.max_results || 10}">
|
||||
</div>
|
||||
<button class="form-submit" onclick="updateSearch(${id})">保存</button>
|
||||
<div class="form-group">
|
||||
<label class="form-label">额外配置(JSON格式)</label>
|
||||
<textarea class="form-textarea" id="toolConfigJson">${tool.config_json || '{}'}</textarea>
|
||||
</div>
|
||||
<button class="form-submit" onclick="updateTool('${toolId}')">保存</button>
|
||||
`);
|
||||
}
|
||||
|
||||
async function saveSearch() {
|
||||
async function saveTool() {
|
||||
const data = {
|
||||
name: document.getElementById('searchName').value,
|
||||
provider: document.getElementById('searchProvider').value,
|
||||
api_url: document.getElementById('searchApiUrl').value,
|
||||
api_key: document.getElementById('searchApiKey').value,
|
||||
max_results: parseInt(document.getElementById('searchMaxResults').value)
|
||||
tool_id: document.getElementById('toolId').value,
|
||||
name: document.getElementById('toolName').value,
|
||||
type: document.getElementById('toolType').value,
|
||||
provider: document.getElementById('toolProvider').value,
|
||||
api_url: document.getElementById('toolApiUrl').value,
|
||||
api_key: document.getElementById('toolApiKey').value,
|
||||
max_results: parseInt(document.getElementById('toolMaxResults').value),
|
||||
config_json: document.getElementById('toolConfigJson').value
|
||||
};
|
||||
|
||||
if (!data.name || !data.api_url || !data.api_key) {
|
||||
if (!data.tool_id || !data.name || !data.type) {
|
||||
showToast('请填写完整信息');
|
||||
return;
|
||||
}
|
||||
|
||||
await fetchAPI('/api/admin/search', 'POST', data);
|
||||
await fetchAPI('/api/admin/tools', 'POST', data);
|
||||
closeModal();
|
||||
showToast('添加成功');
|
||||
loadPage('search');
|
||||
loadPage('tools');
|
||||
}
|
||||
|
||||
async function updateSearch(id) {
|
||||
async function updateTool(toolId) {
|
||||
const data = {
|
||||
name: document.getElementById('searchName').value,
|
||||
provider: document.getElementById('searchProvider').value,
|
||||
api_url: document.getElementById('searchApiUrl').value,
|
||||
api_key: document.getElementById('searchApiKey').value,
|
||||
max_results: parseInt(document.getElementById('searchMaxResults').value)
|
||||
name: document.getElementById('toolName').value,
|
||||
type: document.getElementById('toolType').value,
|
||||
provider: document.getElementById('toolProvider').value,
|
||||
api_url: document.getElementById('toolApiUrl').value,
|
||||
api_key: document.getElementById('toolApiKey').value,
|
||||
max_results: parseInt(document.getElementById('toolMaxResults').value),
|
||||
config_json: document.getElementById('toolConfigJson').value
|
||||
};
|
||||
|
||||
await fetchAPI(`/api/admin/search/${id}`, 'PUT', data);
|
||||
await fetchAPI(`/api/admin/tools/${toolId}`, 'PUT', data);
|
||||
closeModal();
|
||||
showToast('更新成功');
|
||||
loadPage('search');
|
||||
loadPage('tools');
|
||||
}
|
||||
|
||||
async function setDefaultSearch(id) {
|
||||
await fetchAPI(`/api/admin/search/${id}/default`, 'POST');
|
||||
async function setDefaultTool(toolId) {
|
||||
await fetchAPI(`/api/admin/tools/${toolId}/default`, 'POST');
|
||||
showToast('已设为默认');
|
||||
loadPage('search');
|
||||
loadPage('tools');
|
||||
}
|
||||
|
||||
async function deleteSearch(id) {
|
||||
if (!confirm('确定删除此配置?')) return;
|
||||
await fetchAPI(`/api/admin/search/${id}`, 'DELETE');
|
||||
async function deleteTool(toolId) {
|
||||
if (!confirm('确定删除此工具?')) return;
|
||||
await fetchAPI(`/api/admin/tools/${toolId}`, 'DELETE');
|
||||
showToast('删除成功');
|
||||
loadPage('search');
|
||||
loadPage('tools');
|
||||
}
|
||||
|
||||
// ==================== 系统设置页面 ====================
|
||||
@@ -760,13 +940,6 @@ async function loadSystemPage(content) {
|
||||
<input type="text" class="form-input" id="appVersion" value="${systemConfigs.app_version?.value || ''}">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label style="display: flex; align-items: center; gap: 8px;">
|
||||
<input type="checkbox" id="enableSearch" ${systemConfigs.enable_search?.value === 'true' ? 'checked' : ''}>
|
||||
启用联网搜索
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<h3 style="margin: 24px 0 16px; padding-top: 16px; border-top: 1px solid #e2e8f0;">游客使用限制</h3>
|
||||
|
||||
<div class="form-group">
|
||||
@@ -793,6 +966,12 @@ async function loadSystemPage(content) {
|
||||
|
||||
<button class="form-submit" onclick="saveSystemConfig()">保存设置</button>
|
||||
</div>
|
||||
|
||||
<div style="margin-top: 16px; padding: 12px; background: #f5f7fa; border-radius: 8px;">
|
||||
<p style="color: #718096; font-size: 13px;">
|
||||
💡 提示:启用联网搜索等对话相关配置请前往"对话配置"页面设置
|
||||
</p>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -800,7 +979,6 @@ async function saveSystemConfig() {
|
||||
const data = {
|
||||
app_name: document.getElementById('appName').value,
|
||||
app_version: document.getElementById('appVersion').value,
|
||||
enable_search: document.getElementById('enableSearch').checked ? 'true' : 'false',
|
||||
guest_chat_sessions: document.getElementById('guestChatSessions').value,
|
||||
guest_chat_messages: document.getElementById('guestChatMessages').value,
|
||||
guest_agent_messages: document.getElementById('guestAgentMessages').value,
|
||||
@@ -809,7 +987,6 @@ async function saveSystemConfig() {
|
||||
|
||||
await fetchAPI('/api/admin/system', 'POST', data);
|
||||
showToast('保存成功');
|
||||
loadPage('system');
|
||||
}
|
||||
|
||||
// ==================== 工具函数 ====================
|
||||
|
||||
@@ -1445,7 +1445,7 @@ function renderProfilePage() {
|
||||
</div>
|
||||
|
||||
<div class="profile-footer">
|
||||
<p>AI助手 v3.5.1</p>
|
||||
<p>AI助手 v3.6.0</p>
|
||||
<p>基于智谱 GLM-4.5-Air</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user