{"id":47742621,"url":"https://github.com/6alex776/llminputenhancer","last_synced_at":"2026-04-03T00:01:48.539Z","repository":{"id":346302252,"uuid":"1187742024","full_name":"6alex776/LLMInputEnhancer","owner":"6alex776","description":"面向端侧离线场景的轻量化 LLM 输入增强系统，支持文本润色、翻译、扩写、缩写与智能任务分类","archived":false,"fork":false,"pushed_at":"2026-04-01T16:41:51.000Z","size":581,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-01T17:45:57.393Z","etag":null,"topics":["cnn","llm","pyside6","python","pytorch","windows"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/6alex776.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-21T05:09:29.000Z","updated_at":"2026-04-01T16:41:54.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/6alex776/LLMInputEnhancer","commit_stats":null,"previous_names":["6alex776/llminputenhancer"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/6alex776/LLMInputEnhancer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/6alex776%2FLLMInputEnhancer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/6alex776%2FLLMInputEnhancer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/6alex776%2FLLMInputEnhancer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/6alex776%2FLLMInputEnhancer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/6alex776","download_url":"https://codeload.github.com/6alex776/LLMInputEnhancer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/6alex776%2FLLMInputEnhancer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31319743,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-02T23:57:25.032Z","status":"ssl_error","status_checked_at":"2026-04-02T23:57:06.281Z","response_time":89,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cnn","llm","pyside6","python","pytorch","windows"],"created_at":"2026-04-03T00:01:47.580Z","updated_at":"2026-04-03T00:01:48.518Z","avatar_url":"https://github.com/6alex776.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LLMInputEnhancer\n\n当前版本：`v0.2.1-beta`\n\n一个面向 Windows 桌面输入场景的本地大模型输入增强工具。\n\n它的目标不是替代聊天界面，而是把本地 LLM 直接接入你正在使用的输入框：先选中文本，再通过全局热键完成润色、翻译、扩写、缩写或自定义改写，并把结果回灌到原输入位置。\n\n## 项目特点\n\n- 面向桌面输入场景，而不是单独的聊天窗口\n- 支持全局热键，跨应用触发\n- 优先读取当前选中文本，失败时回退到剪贴板方案\n- 支持本地 OpenAI 兼容接口，默认适配 `llama-server`\n- 支持流式生成并持续写回目标输入框\n- 内置一个基于 PyTorch 的轻量文本任务分类器，可通过 `Alt+A` 自动判断任务类型\n- 不修改系统输入法，不注入驱动，保持项目轻量\n\n## 当前支持的任务\n\n- 文本润色\n- 中英互译\n- 文本扩写\n- 文本缩写\n- 自定义指令处理\n\n## 运行效果\n\n典型使用流程如下：\n\n1. 在任意应用中选中文本\n2. 按下全局快捷键\n3. 程序读取选区内容\n4. 调用本地模型生成结果\n5. 将结果尽量写回原输入框\n\n适用场景包括但不限于：\n\n- 微信、QQ、飞书等聊天输入框\n- 浏览器网页输入框\n- Office 文档编辑\n- IDE、记事本等文本编辑器\n\n不同应用对自动化输入的兼容程度不同，因此“尽量兼容”比“绝对兼容”更符合这个项目的定位。\n\n## 技术栈\n\n- Python\n- PySide6\n- httpx\n- pywin32\n- pyperclip\n- UIAutomation for Windows（可选）\n- PyTorch（分类器功能可选）\n\n## 项目结构\n\n```text\nLLMInputEnhancer/\n├─ config.json              # 本地配置文件\n├─ src/\n│  ├─ main.py               # 程序入口与整体控制器\n│  ├─ ui_components.py      # 托盘、指令面板、设置窗口\n│  ├─ hotkey_listener.py    # Win32 全局热键监听\n│  ├─ clipboard_manager.py  # 选中文本获取、剪贴板处理、流式写回\n│  ├─ llm_client.py         # 本地模型调用封装\n│  ├─ config.py             # 配置读取、保存与校验\n│  ├─ app_logger.py         # 日志初始化\n│  ├─ app_info.py           # 应用名称与版本信息\n│  └─ classifier/           # 文本任务分类器\n│     ├─ train.py           # 训练脚本\n│     ├─ infer.py           # 推理运行时\n│     ├─ model.py           # Hybrid TextCNN 模型\n│     ├─ dataset.py         # 数据读取与特征提取\n│     ├─ data/              # 训练/验证样本\n│     └─ artifacts/         # 导出的模型与词表\n└─ logs/                    # 运行日志\n```\n\n## 环境要求\n\n- Windows\n- Python 3.11+ 或与你当前依赖兼容的 Python 环境\n- 已启动的本地大模型服务\n\n推荐你优先使用独立虚拟环境或 Conda 环境运行本项目。\n\n## 使用前准备\n\n发布包本身只包含客户端，不包含大模型本体，也不包含本地推理服务。\n\n在使用本项目之前，请先完成下面这些准备工作：\n\n1. 下载本项目对应版本的可执行发布包\n2. 额外下载并安装 `llama.cpp`\n3. 准备并部署你自己的本地大模型文件\n4. 启动本地模型服务后，再运行本项目\n\n推荐下载的 `llama.cpp` 版本：\n\n- [llama.cpp b8591](https://github.com/ggml-org/llama.cpp/releases/tag/b8591)\n\n建议优先下载其中带 `llama-server` 的 Windows 预编译包。\n\n你至少需要准备以下内容：\n\n- `llama-server.exe`\n- 你自己的 GGUF 模型文件\n- 可用的本地模型服务地址，例如 `http://127.0.0.1:8080/`\n\n如果没有先部署并启动本地模型服务，本项目即使可以打开，也无法实际完成文本处理。\n\n## 安装依赖\n\n基础运行依赖：\n\n```powershell\npip install PySide6 httpx pyperclip pywin32 uiautomation\n```\n\n如果你需要使用分类器训练或推理功能，再额外安装：\n\n```powershell\npip install torch\n```\n\n## 启动本地模型服务\n\n本项目默认对接 OpenAI 兼容接口，最常见的用法是连接 `llama-server`。\n\n示例：\n\n```powershell\n.\\llama-server.exe -m E:\\llama\\model\\Qwen3.5-0.8B-IQ4_NL.gguf -ngl 80 -c 4096 -np 1 --chat-template-kwargs '{\\\"enable_thinking\\\": false}'\n```\n\n默认情况下，本项目会请求：\n\n- `GET /health`\n- `GET /v1/models`\n- `POST /v1/chat/completions`\n\n只要你的本地服务地址可访问，并且兼容上述接口协议，就可以接入。\n\n### 首次使用建议\n\n首次使用时，建议按这个顺序完成：\n\n1. 下载本项目的 exe 发布包\n2. 从 [llama.cpp b8591](https://github.com/ggml-org/llama.cpp/releases/tag/b8591) 下载 Windows 版本\n3. 准备你自己的 GGUF 模型\n4. 用 `llama-server` 启动模型服务\n5. 启动本项目\n6. 在设置中确认 `local_url` 和 `local_model`\n7. 通过托盘菜单手动执行一次“检查本地模型服务”\n\n## 启动项目\n\n```powershell\npython src/main.py\n```\n\n程序启动后会常驻系统托盘。\n\n## 默认快捷键\n\n- `Alt+\\``：打开指令面板\n- `Alt+1`：文本润色\n- `Alt+2`：中英互译\n- `Alt+3`：文本扩写\n- `Alt+4`：文本缩写\n- `Alt+A`：自动分类并执行高置信度任务\n\n说明：\n\n- `Alt+A` 默认不会弹出面板\n- 如果分类器不可用或判断不确定，程序会只给出提示，不强制执行\n\n## 配置说明\n\n配置文件位于：\n\n- `config.json`\n\n当前主要配置项如下：\n\n| 配置项 | 说明 |\n| --- | --- |\n| `local_url` | 本地模型服务地址，真正决定能否连接 |\n| `local_model` | 请求体中的模型名；部分本地服务会忽略它，但设置页当前要求非空 |\n| `temperature` | 生成温度 |\n| `max_tokens` | 最大输出长度 |\n| `enable_classifier_recommendation` | 是否启用 `Alt+A` 智能分类 |\n| `auto_classify_execute_threshold` | 高置信度自动执行阈值 |\n| `auto_classify_recommend_threshold` | 中等置信度提示阈值 |\n\n## 分类器说明\n\n项目内置了一个轻量级文本任务分类器，用于判断当前选中文本更适合走：\n\n- `polish`\n- `translate`\n- `expand`\n- `summarize`\n\n当前实现不是大模型分类，而是项目内置的 `Hybrid TextCNN` 小模型，适合本地低延迟推理。\n\n### 训练数据\n\n默认数据位置：\n\n- `src/classifier/data/train.jsonl`\n- `src/classifier/data/val.jsonl`\n\n每行一个 JSON 对象，例如：\n\n```json\n{\"text\":\"请把这段话改得更正式一些\", \"label\":\"polish\"}\n```\n\n### 训练命令\n\n```powershell\npython src/classifier/train.py\n```\n\n常用参数示例：\n\n```powershell\npython src/classifier/train.py --epochs 20 --batch-size 32 --device cuda\n```\n\n训练完成后会在以下目录生成产物：\n\n- `src/classifier/artifacts/model.pt`\n- `src/classifier/artifacts/vocab.json`\n- `src/classifier/artifacts/meta.json`\n\n## 设计说明\n\n### 1. 文本获取\n\n优先尝试通过 UIAutomation 获取当前控件中的选中文本；如果失败，则回退到剪贴板复制方案。\n\n### 2. 模型调用\n\n通过 `llm_client.py` 统一封装对本地模型服务的同步、异步和流式调用。\n\n### 3. 输出回灌\n\n对于标准编辑控件，优先使用更直接的消息写回；对于普通输入场景，则回退到模拟输入方案，以兼顾通用性。\n\n### 4. 智能分类\n\n`Alt+A` 不直接依赖大模型，而是先用本地小分类器快速判断任务类型，再决定是否自动执行。\n\n## 日志\n\n运行后日志自动创建文件夹，并默认写入：\n\n- `logs/app.log`\n\n如果你遇到以下问题，建议优先看日志：\n\n- 本地模型连接失败\n- 热键没有生效\n- 未能读取选中文本\n- 流式写回失败\n- 分类器没有加载成功\n\n## 常见问题\n\n### 1. 为什么模型地址对了，但模型名写错仍然能调用成功？\n\n因为当前很多本地 OpenAI 兼容服务只要求地址可达，并不一定严格校验请求体中的 `model` 字段。\n\n在本项目中：\n\n- `local_url` 是真正决定能否连接的关键项\n- `local_model` 目前仍会写进请求体\n- 手动“检查本地模型服务”时会尝试校验模型名是否存在\n\n### 2. 为什么有些软件里写回效果不稳定？\n\n不同应用的输入框实现方式差异很大。标准编辑框通常兼容更好，浏览器、自绘控件、特殊富文本编辑器则更容易出现行为差异。\n\n### 3. 为什么 `Alt+A` 没有反应？\n\n可能原因包括：\n\n- 分类器功能已在设置中关闭\n- 当前没有选中文本\n- 分类器模型文件尚未训练或未正确生成\n- `torch` 没有安装在当前运行解释器中\n\n## 后续可扩展方向\n\n- 支持更多任务类别\n- 将分类器升级为轻量 Transformer\n- 增加更细粒度的输入控件兼容策略\n- 支持更多本地模型服务后端\n- 增加打包与发布流程\n\n## License\n\n详见：\n\n- `LICENSE.md`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F6alex776%2Fllminputenhancer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F6alex776%2Fllminputenhancer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F6alex776%2Fllminputenhancer/lists"}