Skip to main content

A lightweight, elegant CLI for AI chat.

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

🔮 Local Sage

A lightweight LLM chat interface that embraces the command line.

Local Sage Demo


Local Sage running in Zellij, alongside Helix and Yazi.

About 🔎

Local Sage is an open-source CLI for chatting with LLMs. Not automation, not agents, just pure dialogue.

Featuring live Markdown rendering with inline math conversion for a silky smooth chatting experience. Designed to hook into any OpenAI API endpoint, and tested with local LLMs hosted via llama.cpp.

What else makes Local Sage shine? ✨

  • Conversations live in your shell, rendering directly to standard output for persistent history.
  • Fancy prompts with command completion and in-memory history.
  • Context-aware file management. See the Under the Hood section for more info!
  • Small but mighty, below 2000 lines of Python 🐍.

Plus everything you'd expect from a solid chat frontend.

  • Session management: load, save, delete, reset, and summarize sessions.
  • Profile management: save, delete, and switch model profiles.
  • Reasoning/Chain-of-thought support with a dedicated Reasoning panel.
  • Context length monitoring, shown through a subtle status panel.

There is also a collection of built-in Markdown themes to choose from to customize your sessions!

Compatibility 🔩

Python 3.10 or later required.

The big three (Linux, macOS, and Windows) are all supported. Ensure your terminal emulator has relatively modern features. Alacritty works well. So does kitty and Ghostty.

You can use non-local models with Local Sage if desired. If you set an API key, the CLI will store it safely in your OS's built-in credential manager via keyring.

Installation 💽

Install a Python package manager for your OS. Both uv and pipx are highly recommended.

For uv, open your terminal and type:
uv tool install localsage
Or, for pipx, type:
pipx install localsage

Type localsage into your terminal to launch the CLI. Type !h to view command usage.

Getting Started ✔️

Configuration is done entirely through interactive commands. You never have to touch a config file.

  1. Configure a profile with !profileadd.
  2. Type !switch to switch to your new profile.
  3. Use !ctx to set your context length.
  4. (Optional) Set your own system prompt with !prompt or an API key with !key.

Typical API endpoint format: http://ipaddress:port/v1

Tip: If you press tab while at the main prompt, you can access a command completer for easy command use.

Dependencies 🧰

Local Sage is designed with minimal dependencies, keeping the download light and minimizing library bloat.

  • Rich - Used extensively throughout. Panels, live rendering, etc.
  • prompt_toolkit - Prompts and completers, also used extensively.
  • OpenAI - Provides all API interaction as well as the conversation history list.
  • keyring - Safely handles API keys on all platforms.
  • tiktoken - Provides tokenization and enables context length calculation.
  • platformdirs - Detects default directories across operating systems.
  • pylatexenc - Absolutely vital for live math sanitization.

File Locations 📁

Your config file, session files, and error logs are stored in your user's data directory.

OS Directory
Linux: ~/.local/share/LocalSage
macOS: ~/Library/Application Support/LocalSage
Windows: %localappdata%/LocalSage

Display Notes 🖥️

Typing into the terminal while streaming is active may cause visual artifacting. Avoid typing into the terminal until the current generation finishes.

A monospaced Nerd font is HIGHLY recommended. It ensures that Markdown, math, and icons all align well on-screen. The main prompt uses a Nerd font chevron.

Under the Hood 🛠️

Context-Aware File Management

If you re-attach a file, context consumption is massively reduced by removing the original file from the conversation history and then appending the new copy. Removing an attachment (via the !purge command) will fully refund its context consumption.

Rendering & Streaming (For Technical Users)

At its core, Local Sage uses the Rich library combined with a custom math sanitizer to render live Markdown and readable inline math. Chunk processing is frame-synchronized to the refresh rate of a rich.live display, meaning that the entire rendering process occurs at a customizable interval. Effectively a hand-rolled, lightweight, synchronized rendering engine running right in your terminal.

You can adjust the refresh rate using the !rate command (30 FPS by default).

Limitations 🛑

Once the live panel group fills the terminal viewport, real-time rendering cannot continue due to terminal constraints. By default, the Response panel consumes the Reasoning panel to conserve space (toggleable with the !consume command).

This should only be noticeable on large responses that consume over an entire viewport's worth of vertical space.

Local Sage is text-only. This limitation keeps Local Sage portable, lightweight, and backend-agnostic.

Local Sage will only ever store one API key in your keychain. If you switch providers often, you will have to swap your API key with !key.

Versioning 🔧

The project follows basic versioning:

  • 1.0.x - Minor patches consisting of bug fixes and aesthetic tweaks.
  • 1.x.0 - Major patches consisting of feature expansions or necessary refactors.

License ⚖️

Local Sage is released under the MIT License.

Closing Notes 🫵

Local Sage is an open-source, single-dev project built purely for the love of the game. Please be kind!

Contributions are always welcome! See Contributing.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

localsage-1.2.0.tar.gz (28.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

localsage-1.2.0-py3-none-any.whl (26.0 kB view details)

Uploaded Python 3

File details

Details for the file localsage-1.2.0.tar.gz.

File metadata

  • Download URL: localsage-1.2.0.tar.gz
  • Upload date:
  • Size: 28.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for localsage-1.2.0.tar.gz
Algorithm Hash digest
SHA256 00b24e04edf1eb88ec537c6e3e8e66fd5b94b9c4b17c0d02376a2078f9fff517
MD5 007a1b65944c34cd2e466cc3269f83e3
BLAKE2b-256 ff36a0d867a3556fcd7dbe1f45717dcac186f8e1e751fc8fadfd0deb8ef8699a

See more details on using hashes here.

Provenance

The following attestation bundles were made for localsage-1.2.0.tar.gz:

Publisher: python-publish.yml on Kyleg142/localsage

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file localsage-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: localsage-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 26.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for localsage-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b9250d4e58f38fea9088a84362e0d2322f9534928f8b2c7cb2eb7ae62bbe103b
MD5 6e9c42ddeacd5b5c5d219378cdc120ba
BLAKE2b-256 0ff7d568a7dcacd204880e44f04e591075677135b9b92999b1ebbeffb0ab75b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for localsage-1.2.0-py3-none-any.whl:

Publisher: python-publish.yml on Kyleg142/localsage

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page