一个界面照着豆包抠的 AI 助手。主力是安卓端,完全离线自主:不依赖电脑、 不需要另外装 Termux。 安卓端 - 原生 Jetpack Compose,7 个页面,配色/圆角/间距对着真机截图量出来的 - 完整动效:抽屉滑入、页面切换、气泡淡入上移、面板底部升起、typing 三点、按钮回弹 - 内置 Termux:bash/apt/pkg 388 个命令、真 pty 终端; pty 不可用的 ROM 上自动降级成命令控制台 - APK 内嵌 CPython 3.13(Chaquopy),AI 内核跑在手机上 - 设备能力:定位 / 陀螺仪 / 加速度计 / 光线 / 电量 / 剪贴板 - 语音:朗读 + 语音输入,火山豆包音色 / OpenAI 兼容 / 设备自带三级引擎 AI 能力 - 10 家 OpenAI 兼容提供商:方舟 / OpenAI / DeepSeek / Kimi / 智谱 / 通义 / 硅基流动 / OpenRouter / 本地 Ollama / 自定义 - 思考强度按各家支持情况发不同字段(thinking / reasoning_effort / 不发), 认不出来的一律不发,避免给不支持的厂商发字段直接 400 - MCP 三种传输(http / stdio / inproc)、工具热加载、文件上传、权限模式 跨端 - 安卓走原生 Compose,Web / Windows 走 Lynx - Node 与 Python 两份内核接口逐字段一致,关键路径都有对拍脚本 自检脚本(都不需要真 Key) - verify-phone.mjs 设备端 24 项验收 - verify-speech.mjs 语音链路 31 项,两份内核各跑一遍 - parity-thinking.mjs 思考强度映射对拍 - probe-settings-wipe.mjs 设置防清空攻击测试 - mock-llm.mjs 假的 OpenAI + 火山语音服务 许可 MIT;第三方组件(Termux Apache-2.0、Chaquopy、Compose、LynxJS、Electron) 的授权见 LICENSE。
130 lines
4.4 KiB
JavaScript
130 lines
4.4 KiB
JavaScript
/**
|
||
* 对拍:Node 内核和 Python 内核,给每个提供商 + 每个思考强度
|
||
* 生成的请求体必须逐字段一致。
|
||
*
|
||
* 为什么值得专门对拍:这两份实现跑在不同端(电脑 / 手机),
|
||
* 一旦分叉,就会出现"电脑上好好的,手机上 400"这种最难查的问题。
|
||
*
|
||
* 用法: node scripts/parity-thinking.mjs
|
||
*/
|
||
import { spawnSync } from 'node:child_process';
|
||
import { normalizeBody, thinkingModeOf } from '../server/src/providers.mjs';
|
||
import { PROVIDER_PRESETS } from '../server/src/config.mjs';
|
||
|
||
const PY = 'C:\\Python313\\python.exe';
|
||
const LEVELS = ['auto', 'off', 'low', 'medium', 'high'];
|
||
const MODELS = {
|
||
ark: 'doubao-seed-2-1-pro-260628',
|
||
openai: 'gpt-5-mini', // 故意用推理模型,把剥离 sampling 参数那条分支也带上
|
||
deepseek: 'deepseek-reasoner',
|
||
kimi: 'kimi-k2-0905-preview',
|
||
zhipu: 'glm-4.6',
|
||
dashscope: 'qwen-plus',
|
||
siliconflow: 'deepseek-ai/DeepSeek-V3',
|
||
openrouter: 'o3-mini',
|
||
ollama: 'qwen2.5:7b',
|
||
custom: 'my-model',
|
||
};
|
||
|
||
/* ---------------- Node 侧:直接算 ---------------- */
|
||
const nodeCases = [];
|
||
for (const provider of Object.keys(PROVIDER_PRESETS)) {
|
||
for (const level of LEVELS) {
|
||
const body = normalizeBody({
|
||
provider,
|
||
model: MODELS[provider] || 'x',
|
||
thinkingLevel: level,
|
||
body: {
|
||
model: MODELS[provider] || 'x',
|
||
messages: [{ role: 'user', content: 'hi' }],
|
||
stream: false,
|
||
temperature: 0.7,
|
||
},
|
||
});
|
||
nodeCases.push({ provider, level, body });
|
||
}
|
||
}
|
||
|
||
/* ---------------- Python 侧:让内核自己算 ---------------- */
|
||
const pyScript = `
|
||
import json, sys
|
||
sys.path.insert(0, 'android/kernel')
|
||
import providers
|
||
from defaults import PROVIDER_PRESETS
|
||
|
||
models = json.loads(sys.argv[1])
|
||
levels = json.loads(sys.argv[2])
|
||
out = []
|
||
for provider in PROVIDER_PRESETS:
|
||
for level in levels:
|
||
body = providers.normalize_body(
|
||
provider, models.get(provider, 'x'), level,
|
||
{'model': models.get(provider, 'x'),
|
||
'messages': [{'role': 'user', 'content': 'hi'}],
|
||
'stream': False, 'temperature': 0.7},
|
||
)
|
||
out.append({'provider': provider, 'level': level, 'body': body,
|
||
'mode': providers.thinking_mode_of(provider)})
|
||
print(json.dumps(out, ensure_ascii=False))
|
||
`;
|
||
|
||
const res = spawnSync(
|
||
PY,
|
||
['-c', pyScript, JSON.stringify(MODELS), JSON.stringify(LEVELS)],
|
||
{ encoding: 'utf8', cwd: process.cwd(), timeout: 120000 },
|
||
);
|
||
|
||
if (res.status !== 0) {
|
||
console.error('Python 侧跑失败:');
|
||
console.error(res.stderr || res.stdout);
|
||
process.exit(1);
|
||
}
|
||
|
||
const pyCases = JSON.parse(res.stdout.trim());
|
||
|
||
/* ---------------- 比对 ---------------- */
|
||
if (pyCases.length !== nodeCases.length) {
|
||
console.error(`❌ 用例数不一样:Node ${nodeCases.length} vs Python ${pyCases.length}`);
|
||
process.exit(1);
|
||
}
|
||
|
||
let pass = 0;
|
||
const fails = [];
|
||
for (const n of nodeCases) {
|
||
const p = pyCases.find((x) => x.provider === n.provider && x.level === n.level);
|
||
if (!p) {
|
||
fails.push(`${n.provider}/${n.level}: Python 侧没有这个用例`);
|
||
continue;
|
||
}
|
||
const a = JSON.stringify(n.body, Object.keys(n.body).sort());
|
||
const b = JSON.stringify(p.body, Object.keys(p.body).sort());
|
||
if (a === b) {
|
||
pass += 1;
|
||
} else {
|
||
fails.push(`${n.provider}/${n.level}\n Node : ${a}\n Python: ${b}`);
|
||
}
|
||
}
|
||
|
||
console.log('=== 思考强度映射对拍 ===');
|
||
console.log(` 提供商 ${Object.keys(PROVIDER_PRESETS).length} 家 × 思考强度 ${LEVELS.length} 档 = ${nodeCases.length} 个用例`);
|
||
console.log(` 结果:${pass} 通过 / ${fails.length} 失败`);
|
||
|
||
console.log('\n=== 每家实际发什么 ===');
|
||
for (const provider of Object.keys(PROVIDER_PRESETS)) {
|
||
const mode = thinkingModeOf(provider);
|
||
const samples = [];
|
||
for (const level of ['off', 'high']) {
|
||
const c = nodeCases.find((x) => x.provider === provider && x.level === level);
|
||
const keys = Object.keys(c.body).filter((k) => ['thinking', 'reasoning_effort', 'temperature'].includes(k));
|
||
samples.push(`${level}: ${keys.length ? JSON.stringify(Object.fromEntries(keys.map((k) => [k, c.body[k]]))) : '(不加字段)'}`);
|
||
}
|
||
console.log(` ${provider.padEnd(12)} mode=${mode.padEnd(7)} ${samples.join(' ')}`);
|
||
}
|
||
|
||
if (fails.length) {
|
||
console.log('\n=== 不一致明细 ===');
|
||
fails.forEach((f) => console.log(' ❌ ' + f));
|
||
process.exit(1);
|
||
}
|
||
console.log('\n✅ 两边完全一致');
|