Python-based Input Method Powered by Large Language Models

Introduction

An IBus-based large language model (LLM) Pinyin input method. After the user types Pinyin and presses Space, the input method requests Chinese candidate phrases via an OpenAI-compatible Chat Completions API, and the user selects a candidate to submit to the current input field.

The current implementation leans toward an MVP (Minimum Viable Product): IBus handles key capture, candidate window rendering, text submission, and caching; the LLM handles converting Pinyin into Chinese candidate phrases. For detailed design, see design.md.

Changelog

Features

  • Supports OpenAI-compatible Chat Completions APIs.
  • Supports local compatible services such as llama.cpp, Ollama, DeepSeek, and OpenRouter.
  • While typing Pinyin, the raw Pinyin is not written to the current input field—only displayed in the IBus pop-up area alongside candidates.
  • Chinese candidates are submitted to the input field only after the user selects one.
  • Automatically clears raw Pinyin, candidates, and auxiliary text upon focus switching.
  • Supports keyboard shortcuts to toggle between Chinese and English input modes; default shortcut is Ctrl+Space.
  • The IBus status bar/panel displays the current input mode: CN (Chinese) or EN (English).
  • Supports SQLite-based candidate caching; frequently used candidates are promoted in ranking.
  • Supports importing custom domain-specific dictionaries in .dict.json format; domain terms are injected into the LLM context to assist with long-Pinyin error correction.
  • Typing ASCII punctuation or symbols during Pinyin input does not exit the input mode; symbols are sent to the LLM along with the Pinyin.
  • Numeric keys pass through directly to the application when no Pinyin input has started; once Pinyin input begins, digits enter the buffer without interrupting input.
  • In Chinese mode, pressing Caps Lock causes English keystrokes to be passed directly to the current application.
  • Input remains unblocked if the model fails or times out; users may press Enter to submit the raw Pinyin instead.
  • Supports local fallback candidates from commonly used words.
  • Keyboard shortcuts involving Ctrl, Alt, Super, Meta, function keys, and arrow keys are passed through directly to the application, avoiding interference from the input method.

Project Repository

volsifly/ibus_llm_pinyin_input: IBus Pinyin Input Method Powered by Large Language Models