[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-80790":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":13,"openIssues":14,"contributorsCount":15,"subscribersCount":15,"size":15,"stars1d":14,"stars7d":14,"stars30d":12,"stars90d":15,"forks30d":15,"starsTrendScore":16,"compositeScore":17,"rankGlobal":9,"rankLanguage":9,"license":18,"archived":19,"fork":19,"defaultBranch":20,"hasWiki":21,"hasPages":19,"topics":22,"createdAt":9,"pushedAt":9,"updatedAt":23,"readmeContent":24,"aiSummary":25,"trendingCount":15,"starSnapshotCount":15,"syncStatus":12,"lastSyncTime":26,"discoverSource":27},80790,"ibus_llm_pinyin_input","volsifly\u002Fibus_llm_pinyin_input","volsifly","ibus使用大模型输入拼音",null,"Python",41,2,39,1,0,3,1.43,"MIT License",false,"main",true,[],"2026-06-12 02:04:06","# IBus LLM Pinyin Input\n\n一个基于 IBus 的大模型拼音输入法。用户输入拼音后按空格，输入法通过 OpenAI-compatible Chat Completions 接口请求中文候选，再由用户选择候选提交到当前输入框。\n\n当前实现偏 MVP：IBus 负责按键捕获、候选窗、提交文本和缓存；大模型负责把拼音转换成中文候选。详细设计见 [design.md](design.md)。\n\n[更新日志](changelog.md)\n\n## 特性\n\n- 支持 OpenAI-compatible Chat Completions API。\n- 支持本地 llama.cpp、Ollama、DeepSeek、OpenRouter 等兼容服务。\n- 拼音输入期间不把原始拼音写入当前输入框，只在 IBus 弹出区域显示输入内容和候选。\n- 用户选择候选后才提交中文到输入框。\n- 焦点切换时自动清空原始拼音、候选和辅助文本。\n- 支持快捷键切换中英文输入模式，默认 `Ctrl+Space`。\n- IBus 状态栏\u002F面板会显示当前输入模式：`中` 或 `英`。\n- 支持 SQLite 候选缓存，常用候选会被提升排序。\n- 支持导入 `.dict.json` 自定义领域词库，领域词会作为 LLM 上下文参与长拼音纠错。\n- 拼音输入过程中输入 ASCII 标点或符号时，不会退出输入，会把符号连同拼音一起发送给 LLM。\n- 未开始输入拼音时数字键直通应用；已经开始输入拼音后数字会进入缓冲区，不会中断输入。\n- 中文模式下开启 CapsLock 时，英文按键会直接交给当前应用。\n- 模型失败或超时时不会阻塞输入，可按回车提交原始拼音。\n- 支持本地常用词兜底候选。\n- Ctrl、Alt、Super、Meta 快捷键以及功能键、方向键等会直通应用，避免被输入法屏蔽。\n\n## 依赖\n\n```bash\nsudo apt update\nsudo apt install -y ibus python3 python3-gi gir1.2-ibus-1.0 python3-requests sqlite3\n```\n\n如果当前系统没有启用 IBus：\n\n```bash\nim-config -n ibus\n```\n\n然后注销并重新登录。\n\n## 安装\n\n```bash\nchmod +x scripts\u002Finstall-user.sh\n.\u002Fscripts\u002Finstall-user.sh\nibus restart\n```\n\n之后打开 `ibus-setup`，添加：\n\n```text\nChinese -> AI 拼音输入法\n```\n\n也可以在 GNOME 设置中通过 `Settings -> Keyboard -> Input Sources` 添加。\n\n如果命令行切换可用，也可以执行：\n\n```bash\nibus engine ai-pinyin\n```\n\n## 配置\n\n首次启动会生成：\n\n```text\n~\u002F.config\u002Fibus-ai-pinyin\u002Fconfig.json\n```\n\n修改配置后需要重启 IBus 才会生效：\n\n```bash\nibus restart\nibus engine ai-pinyin\n```\n\n默认配置使用本地 OpenAI-compatible 服务：\n\n```json\n{\n  \"api\": {\n    \"base_url\": \"http:\u002F\u002F127.0.0.1:8080\u002Fv1\",\n    \"api_key\": \"\",\n    \"api_key_env\": \"OPENAI_API_KEY\",\n    \"model\": \"qwen3-0.6b\",\n    \"endpoint\": \"\u002Fchat\u002Fcompletions\",\n    \"timeout_ms\": 800,\n    \"temperature\": 0.1,\n    \"top_p\": 0.8,\n    \"max_tokens\": 64,\n    \"stream\": false,\n    \"proxy_enabled\": false,\n    \"thinking\": {\n      \"enabled\": false,\n      \"type\": \"disabled\"\n    },\n    \"extra_body\": {}\n  },\n  \"input\": {\n    \"max_buffer_length\": 120,\n    \"candidate_page_size\": 5,\n    \"default_mode\": \"zh\",\n    \"toggle_key\": {\n      \"enabled\": true,\n      \"key\": \"space\",\n      \"modifiers\": [\"Control\"]\n    }\n  },\n  \"dictionary\": {\n    \"enabled\": true,\n    \"path\": \"~\u002F.config\u002Fibus-ai-pinyin\u002Fcache.sqlite3\",\n    \"max_candidates\": 5\n  }\n}\n```\n\n### DeepSeek 示例\n\n```json\n{\n  \"api\": {\n    \"base_url\": \"https:\u002F\u002Fapi.deepseek.com\",\n    \"api_key\": \"sk-...\",\n    \"model\": \"deepseek-v4-flash\",\n    \"endpoint\": \"\u002Fchat\u002Fcompletions\",\n    \"timeout_ms\": 15000,\n    \"max_tokens\": 256,\n    \"stream\": false,\n    \"proxy_enabled\": false,\n    \"thinking\": {\n      \"enabled\": false,\n      \"type\": \"disabled\"\n    },\n    \"extra_body\": {}\n  }\n}\n```\n\n`thinking.enabled=false` 会在请求体中加入：\n\n```json\n{\n  \"thinking\": {\n    \"type\": \"disabled\"\n  }\n}\n```\n\n这适用于支持关闭思考的 OpenAI-compatible 服务。其他厂商需要额外请求字段时，可以放到 `api.extra_body`。\n\n如果服务不支持 `thinking` 请求字段，把 `thinking.enabled` 设为 `null`，客户端就不会发送该字段。NVIDIA NIM 的部分推理模型需要在 system prompt 开头加入 `\u002Fno_think` 来关闭扩展思考，例如：\n\n```json\n{\n  \"api\": {\n    \"base_url\": \"https:\u002F\u002Fintegrate.api.nvidia.com\u002Fv1\",\n    \"api_key\": \"nvapi-...\",\n    \"model\": \"stepfun-ai\u002Fstep-3.5-flash\",\n    \"endpoint\": \"\u002Fchat\u002Fcompletions\",\n    \"temperature\": 0,\n    \"thinking\": {\n      \"enabled\": null,\n      \"type\": \"disabled\"\n    }\n  },\n  \"prompt\": {\n    \"system\": \"\u002Fno_think\\n只输出 JSON 字符串数组，不要解释，不要 Markdown。最多输出 5 个中文候选。\"\n  }\n}\n```\n\n### 中英文切换快捷键\n\n默认快捷键是 `Ctrl+Space`：\n\n```json\n{\n  \"input\": {\n    \"default_mode\": \"zh\",\n    \"toggle_key\": {\n      \"enabled\": true,\n      \"key\": \"space\",\n      \"modifiers\": [\"Control\"]\n    }\n  }\n}\n```\n\n`default_mode` 可设置为：\n\n```text\nzh\nen\n```\n\n英文模式下，输入法不会拦截普通按键，所有输入都会直接交给当前应用。再次按切换快捷键会回到中文模式。\n\nIBus 状态栏\u002F面板会显示当前模式：\n\n```text\n中\n英\n```\n\n状态显示通过 IBus component 的 `icon_prop_key=InputMode` 和引擎内同名 property 实现。\n\n例如改成 `Alt+Space`：\n\n```json\n{\n  \"input\": {\n    \"toggle_key\": {\n      \"enabled\": true,\n      \"key\": \"space\",\n      \"modifiers\": [\"Alt\"]\n    }\n  }\n}\n```\n\n### Ollama 示例\n\n```json\n{\n  \"api\": {\n    \"base_url\": \"http:\u002F\u002F127.0.0.1:11434\u002Fv1\",\n    \"api_key\": \"ollama\",\n    \"model\": \"qwen3:0.6b\",\n    \"endpoint\": \"\u002Fchat\u002Fcompletions\",\n    \"timeout_ms\": 1200\n  }\n}\n```\n\n### llama.cpp server 示例\n\n```bash\nllama-server \\\n  -m .\u002Fmodels\u002Fqwen3-0.6b-q4_k_m.gguf \\\n  --host 127.0.0.1 \\\n  --port 8080 \\\n  -c 512 \\\n  -n 64\n```\n\n## 使用\n\n```text\n输入 nihao\n按空格请求候选\n候选不准确时继续输入补充说明，再按空格调整候选\n按 - 或 = 排除当前候选并生成下一组候选\n按 1-9 选择候选\n按 Ctrl+1 到 Ctrl+9 修改对应候选\n按空格提交当前第一个候选\n按回车提交当前候选或原始拼音\n按 Esc 清空\n按 Backspace 删除\n```\n\n拼音输入过程中，原始拼音不会写入当前输入框。IBus 候选弹窗会显示当前拼音和候选结果，只有选择候选或回车提交时才会写入输入框。\n\n候选列表显示后，如果继续输入字母、数字或符号，输入法不会立刻提交当前候选，也不会把这段内容当成新的拼音重新查询；它会把后续输入作为本轮候选的补充说明显示在辅助文本里。再次按空格时，输入法会把原始拼音、当前候选和补充说明一起发送给 LLM，用来修正候选中不准确的地方。补充说明为空时，按空格仍然提交当前选中的候选。\n\n候选列表显示时，按 `-` 或 `=` 会模拟翻页：输入法把当前候选作为排除列表发给 LLM，请求生成一组新的候选。如果模型没有返回新候选，会继续保留当前候选列表。\n\n如果已经开始输入拼音，继续输入 ASCII 标点或符号不会退出输入法缓冲区。例如输入 `nihao,` 后按空格，发送给 LLM 的内容就是 `nihao,`。如果当前没有拼音缓冲区，符号仍然直接交给当前应用。\n\n数字键按输入状态区分处理：没有拼音缓冲区时直接输入数字；已经开始输入拼音后，数字会进入缓冲区；候选列表显示时，`1-9` 继续用于选择候选。\n\n中文模式下开启 CapsLock 后，英文按键会直接交给当前应用，便于临时输入大写英文。\n\n## 候选词修改和用户动态词库\n\n候选列表显示后，可以按 `Ctrl+数字` 进入候选修改模式。例如 `Ctrl+1` 修改第一个候选。\n\n修改模式下：\n\n```text\n左右方向键 \u002F Home \u002F End 移动光标\nBackspace \u002F Delete 删除文字\n输入中文或符号会直接插入\n输入拼音后按空格生成局部替换候选\n按 1-9 选择局部替换候选\n按 Enter 提交修正结果并保存记忆\n按 Ctrl+Enter 只提交，不保存记忆\n按 Esc 返回原候选列表\n```\n\n修正提交后，输入法会记录修正日志；如果修正结果包含 2 到 12 个汉字，会自动加入用户动态词库。下次输入相同完整拼音时，用户动态词会优先出现在候选里；长拼音命中用户词时，也会作为少量上下文发送给 LLM。\n\n默认配置：\n\n```json\n{\n  \"memory_dictionary\": {\n    \"enabled\": true,\n    \"path\": \"~\u002F.config\u002Fibus-ai-pinyin\u002Fcache.sqlite3\",\n    \"auto_learn\": true,\n    \"send_to_llm\": true,\n    \"max_context_terms\": 8,\n    \"exact_match_candidate\": true,\n    \"auto_learn_min_han\": 2,\n    \"auto_learn_max_han\": 12,\n    \"default_weight\": 80,\n    \"max_weight\": 120,\n    \"record_corrections\": true\n  }\n}\n```\n\n管理用户动态词库：\n\n```bash\nscripts\u002Fuser-memory.py list\nscripts\u002Fuser-memory.py search 鸿灵\nscripts\u002Fuser-memory.py disable 鸿灵\nscripts\u002Fuser-memory.py enable 鸿灵\nscripts\u002Fuser-memory.py delete 鸿灵\nscripts\u002Fuser-memory.py export > user-memory.dict.json\n```\n\n## 自定义领域词库\n\n输入法支持导入标准 `.dict.json` 词库。导入后，词库只作为 LLM 上下文使用，不会直接加入候选列表：\n\n- 普通短输入不会被词库前缀候选污染，例如 `zhi` 不会因为词库里有 `知识库` 而直接展示 `知识库`。\n- 长拼音短语输入时，命中的领域词会作为上下文传给 LLM，并对 LLM 候选重排。例如输入 `honglingzhishikujiansuogongneng` 时，词库可提供 `鸿灵`、`知识库`、`搜索`，帮助模型输出 `鸿灵知识库搜索功能`。\n\n### 词库格式\n\n最小示例：\n\n```json\n{\n  \"version\": \"1.0\",\n  \"name\": \"我的项目词库\",\n  \"entries\": [\n    {\n      \"term\": \"鸿灵\",\n      \"pinyin\": [\"hong ling\"],\n      \"short\": [\"hl\"],\n      \"type\": \"product\",\n      \"weight\": 100,\n      \"enabled\": true\n    },\n    {\n      \"term\": \"搜索\",\n      \"pinyin\": [\"sou suo\", \"jian suo\"],\n      \"short\": [\"ss\"],\n      \"type\": \"tech\",\n      \"weight\": 85,\n      \"enabled\": true\n    }\n  ]\n}\n```\n\n`type` 只能使用以下值：\n\n```text\nproduct project system module feature organization person tech abbreviation business mixed other\n```\n\n不要使用 `concept`、`tool`、`algorithm`、`framework` 等非标准类型。完整格式见 [docs\u002Fdictionary-format-v1.md](docs\u002Fdictionary-format-v1.md)。\n\n### 使用 skill 生成词库\n\n项目内提供了 `ibus-ai-pinyin-dict-skill\u002F`，可用于从项目文档、Wiki、术语表中生成 `.dict.json`。\n\n典型提示：\n\n```text\n请使用 ibus-ai-pinyin-domain-dictionary skill，\n从下面资料中提取适合输入法使用的专有名词，\n生成 dev\u002Fmydict.json 词库文件。\n```\n\n生成词库时注意：\n\n- 精准优先，不要把普通词大量加入词库。\n- 核心领域词必须提供完整 `pinyin`，不能只给 `short`。\n- 如果用户常输入同义词，但期望输出规范词，把同义输入的拼音也加到规范词的 `pinyin` 中。例如期望 `jiansuo` 输出 `搜索`，则写 `\"pinyin\": [\"sou suo\", \"jian suo\"]`。\n- 生成后先校验，再导入。\n\n### 校验和导入\n\n校验 skill 生成的词库：\n\n```bash\npython3 ibus-ai-pinyin-dict-skill\u002Fscripts\u002Fvalidate_dict.py dev\u002Fmydict.json\n```\n\n只检查导入效果，不写数据库：\n\n```bash\npython3 scripts\u002Fimport-dictionary.py dev\u002Fmydict.json --dry-run\n```\n\n导入到默认数据库：\n\n```bash\npython3 scripts\u002Fimport-dictionary.py dev\u002Fmydict.json\n```\n\n默认数据库路径：\n\n```text\n~\u002F.config\u002Fibus-ai-pinyin\u002Fcache.sqlite3\n```\n\n导入后重启 IBus：\n\n```bash\nibus restart\nibus engine ai-pinyin\n```\n\n### 缓存和 LLM 的关系\n\n候选来源会融合：\n\n```text\n用户动态词库完整匹配候选\nLLM 新结果\nSQLite 历史缓存\n本地兜底候选\n```\n\n词库本身不直接输出候选。当长输入命中领域词上下文时，缓存不会直接截断请求，输入法仍会调用 LLM 补充结果；缓存只作为后备候选参与融合，避免旧缓存污染覆盖新的词库纠错结果。\n\n## 日志和缓存\n\n日志：\n\n```text\n~\u002F.cache\u002Fibus-ai-pinyin\u002Fengine.log\n```\n\n缓存：\n\n```text\n~\u002F.config\u002Fibus-ai-pinyin\u002Fcache.sqlite3\n```\n\n日志会记录模型请求耗时、HTTP 状态、原始输出和解析后的候选，便于排查 API 配置问题。日志可能包含模型返回内容，调试完成后可以按需清理：\n\n```bash\ntruncate -s 0 ~\u002F.cache\u002Fibus-ai-pinyin\u002Fengine.log\n```\n\n## 开发验证\n\n```bash\npython3 -m py_compile engine.py ibus_ai_pinyin\u002F*.py tests\u002F*.py\npython3 tests\u002Ftest_core.py\n```\n\n## License\n\nMIT. See [LICENSE](LICENSE).\n","这是一个基于 IBus 的大模型拼音输入法，用户输入拼音后通过大模型生成中文候选词供选择。项目利用 OpenAI 兼容的 Chat Completions API 或本地 LLM 服务将拼音转换成中文候选，并支持多种配置选项以优化用户体验。它特别适合需要高效、智能中文输入体验的场景，如日常办公、编程或内容创作等。此外，该项目还提供了丰富的功能特性，包括快捷键切换输入模式、自动缓存常用候选词、自定义领域词库导入以及对多种标点符号和特殊按键的支持，确保了在不同使用环境下的灵活性与便捷性。","2026-06-11 04:02:20","CREATED_QUERY"]