GithubHelp home page GithubHelp logo

longbin-chen / ai-typing-assistant Goto Github PK

View Code? Open in Web Editor NEW

This project forked from patrickloeber/ai-typing-assistant

0.0 0.0 0.0 12 KB

AI powered local typing assistant built with Ollama

Home Page: https://patloeber.com/typing-assistant-llm/

License: MIT License

Python 100.00%

ai-typing-assistant's Introduction

AI powered typing assistant with Ollama

A script that can run in the background and listen to hotkeys, then uses a Large Language Model to fix the text. Less than 100 lines of code.

Inspired by this tweet:

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

You'll find a demo and step-by-step code explanations on my YouTube channel:

Alt text

Get Started

1. Set up Ollama

Ollama Installation: https://github.com/ollama/ollama

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

Mistal 7B Instruct works well for this task, but feel free to try other models, too :)

2. Install dependencies

pip install pynput pyperclip httpx

3. Run it

Start the assistant:

python main.py

Hotkeys you can then press:

  • F9: Fixes the current line (without having to select the text)
  • F10: Fixes the current selection

Note: You may get an error the first time saying This process is not trusted! Input event monitoring will not be possible until it is added to accessibility clients. On Mac, you need to add the script (IDE/terminal) both on accessibility and input monitoring.

Note: The code works on macOS. The underlying shortcuts in the code like Cmd+Shift+Left, Cmd+C, Cmd+V might have to be changed for Linux & Windows (e.g. Key.cmd -> Key.ctrl).

Customize

Hotkeys, prompt, and Ollama config can be easily customized and extended in the code.

For example, here are some prompt templates you can try:

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."""
)

ai-typing-assistant's People

Contributors

patrickloeber avatar longbin-chen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.