专栏名称: GitHubStore
分享有意思的开源项目
目录
相关文章推荐
运营研究社  ·  《小红书种草与转化实战手册》包邮送,真香! ·  22 小时前  
91运营网  ·  DeepSeek写爆款短视频文案 ·  2 天前  
运营研究社  ·  2元管饱的县城地头蛇,集体打退网红店 ·  2 天前  
91运营网  ·  第一批因DeepSeek失业的受害者,已经出 ... ·  3 天前  
51好读  ›  专栏  ›  GitHubStore

AI powered typing assistant with Ollama:AI辅助打字工具

GitHubStore  · 公众号  ·  · 2024-03-05 07:57

正文

项目简介


可以在后台运行并侦听热键的脚本,然后使用大型语言模型来修复文本。不到 100 行码。

受到这条推文的启发:

https://twitter.com/karpathy/status/1725553780878647482

"GPT is surprisingly good at correcting minor typos, so you can write really really fast, ignore mistakes and keep going, and it comes out just fine." - Andrej Karpathy
“GPT 在纠正小错别字方面出奇地好,所以你可以写得非常非常快,忽略错误并继续前进,而且结果很好。” - 安德烈·卡帕蒂

您可以在我的 YouTube 频道上找到演示和分步代码说明:


开始使用

1. 安装Ollama

Ollama安装:https://github.com/ollama/ollama

运行 ollama run mistral:7b-instruct-v0.2-q4_K_S

Mistal 7B Instruct 非常适合这项任务,但也可以随意尝试其他模型:)

2.安装依赖

pip install pynput pyperclip httpx
  • pynput: https://pynput.readthedocs.io/en/latest/

  • pyperclip: https://github.com/asweigart/pyperclip

  • httpx: https://github.com/encode/httpx/


3.运行它

启动助手:


python main.py

然后您可以按热键:

  • F9:修复当前行(无需选择文本)

  • F10:修复当前选择


注意:第一次输入 This process is not trusted! Input event monitoring will not be possible until it is added to accessibility clients 时可能会出现错误。在 Mac 上,您需要添加有关可访问性和输入监控的脚本(IDE/终端)。

注意:该代码适用于 macOS。对于 Linux 和 Windows,代码中的底层快捷键(如 Cmd+Shift+Left、Cmd+C、Cmd+V)可能需要更改(例如 Key.cmd -> Key.ctrl )。

定制

热键、提示和 Ollama 配置可以在代码中轻松自定义和扩展。

例如,您可以尝试以下一些提示模板:

from string import Template
PROMPT_TEMPLATE_FIX_TEXT = Template( """Fix all typos and casing and punctuation in this text, but preserve all new line characters:
$text
Return only the corrected text.""")
PROMPT_TEMPLATE_GENERATE_TEXT = Template( """Generate a snarky paragraph with 3 sentences about the following topic:
$text
Return only the corrected text.""")
PROMPT_TEMPLATE_SUMMARIZE_TEXT = Template( """Summarize the following text in 3 sentences:
$text
Return only the corrected text.""")








请到「今天看啥」查看全文