/** * 验证:思考强度映射 + 两个新工具。 * 用法: node scripts/verify-round.mjs [base] */ const BASE = process.argv[2] || 'http://127.0.0.1:5199'; async function post(path, body) { const res = await fetch(BASE + path, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body ?? {}), }); return { status: res.status, json: await res.json().catch(() => null), text: res }; } async function put(path, body) { const res = await fetch(BASE + path, { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body ?? {}), }); return res.json(); } console.log('=== python_run: 跑一段代码 ==='); const code = [ 'import sys, json, platform', 'print(json.dumps({"python": sys.version.split()[0], "os": platform.system(), "sum": sum(range(101))}))', ].join('\n'); const runRes = await post('/api/tools/run', { name: 'python_run', args: { code } }); console.log(JSON.stringify(runRes.json).slice(0, 300)); console.log('\n=== python_run: 联网能力 ==='); const netCode = [ 'import urllib.request, json', 'try:', ' with urllib.request.urlopen("https://example.com", timeout=15) as r:', ' print("HTTP", r.status, "len", len(r.read()))', 'except Exception as e:', ' print("ERR", type(e).__name__, e)', ].join('\n'); const netRes = await post('/api/tools/run', { name: 'python_run', args: { code: netCode } }); console.log(JSON.stringify(netRes.json).slice(0, 300)); console.log('\n=== 思考强度:依次切换,看上游收到的字段 ==='); const levels = ['auto', 'off', 'low', 'high']; for (const level of levels) { await put('/api/settings', { thinkingLevel: level, provider: 'ark', model: 'doubao-seed-2-1-pro-260628' }); await post('/api/chat', { conversationId: 'c_main', message: `probe-${level}`, history: [] }); await new Promise((r) => setTimeout(r, 300)); } console.log('(上游字段见 mock 的 stderr 日志:thinking={...})'); console.log('\n=== 恢复默认 ==='); await put('/api/settings', { thinkingLevel: 'auto' }); console.log('done');