Skip to main content

Modulare Python-TUI zur Steuerung von LLMs via LangChain

Project description

OChaT

PyPI version Build Status License: MIT

OChaT is a modular Python TUI application that orchestrates Large Language Models (LLMs) via LangChain. It supports both local models (Ollama) and cloud providers (ChatGPT, Claude, Grok).


๐Ÿ“ฆ Installation

  1. Clone the repository

    git clone https://github.com/dein-username/OChaT.git
    cd OChaT
    
  2. Install dependencies

    uv sync
    
  3. Install package in development mode

    uv install -e .
    

Note: By default, uv sync installs all dependencies from pyproject.toml, including:

  • alembic>=1.15.2
  • click>=8.1.8
  • langchain>=0.3.26
  • langchain-ollama>=0.3.3
  • ollama>=0.4.8
  • rich>=14.0.0
  • sqlmodel>=0.0.24
  • textual>=3.2.0

โšก Quick Start

Launch the TUI application:

uv run ocht

Or use specific commands:

  • uv run ocht init <workspace> - Create new workspace
  • uv run ocht chat - Start interactive chat
  • uv run ocht list-models - List available models
  • uv run ocht sync-models - Sync model metadata
  • uv run ocht config - Open configuration editor
  • uv run ocht migrate <version> - Run database migrations

Available CLI Commands

Command Description
init <name> Creates a new chat workspace with configuration file and history
chat Starts interactive chat session based on current workspace
config Opens configuration in default editor
export-config <file> Exports current settings as YAML or JSON file
import-config <file> Imports settings from YAML or JSON file
list-models Lists available LLM models via LangChain
sync-models Synchronizes model metadata from external providers
migrate <version> Runs Alembic migrations to specified target version
version Shows current CLI/package version
help [command] Shows detailed help for a command
Example Usage
# Create new chat workspace
uv run ocht init my-workspace

# Start chat session
uv run ocht chat

# List available models
uv run ocht list-models

# Sync model metadata
uv run ocht sync-models

๐Ÿ—๏ธ Architecture

Core Components

Database Layer (core/)

  • models.py - SQLModel entities: Workspace, Message, LLMProviderConfig, Model, Setting, PromptTemplate
  • db.py - Database engine, session management, and initialization
  • migration.py - Alembic integration for schema migrations

Repository Layer (repositories/)

  • CRUD operations for each entity
  • Direct database access abstraction
  • Files: workspace.py, message.py, llm_provider_config.py, model.py, setting.py, prompt_template.py

Service Layer (services/)

  • Business logic and use cases
  • Orchestrates repositories and external APIs
  • Files: workspace.py, chat.py, config.py, model_manager.py, provider_manager.py, prompt_manager.py

Adapter Layer (adapters/)

  • LangChain integration
  • base.py - Abstract LLMAdapter interface
  • ollama.py - Ollama-specific implementation

TUI Layer (tui/)

  • Textual-based user interface
  • app.py - Main TUI application
  • screens/ - UI screens for model/provider management
  • widgets/ - Custom UI components (chat bubbles, etc.)
  • styles/ - TCSS styling files

๐Ÿ—‚๏ธ Project Structure

OChaT/
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ pyproject.toml
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ CLAUDE.md              # Claude Code project instructions
โ”œโ”€โ”€ alembic.ini            # Alembic configuration
โ”œโ”€โ”€ migrations/            # Database migration files
โ”œโ”€โ”€ docs/
โ”œโ”€โ”€ tests/                 # Test files
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ ocht/
โ”‚       โ”œโ”€โ”€ __init__.py
โ”‚       โ”œโ”€โ”€ cli.py             # CLI entry point (Click commands)
โ”‚       โ”œโ”€โ”€ core/              # Database engine, sessions & models
โ”‚       โ”‚   โ”œโ”€โ”€ db.py          # Engine & session factory
โ”‚       โ”‚   โ”œโ”€โ”€ migration.py   # Alembic integration
โ”‚       โ”‚   โ”œโ”€โ”€ models.py      # SQLModel entities
โ”‚       โ”‚   โ””โ”€โ”€ version.py     # Version management
โ”‚       โ”œโ”€โ”€ repositories/      # CRUD logic per entity
โ”‚       โ”‚   โ”œโ”€โ”€ workspace.py
โ”‚       โ”‚   โ”œโ”€โ”€ message.py
โ”‚       โ”‚   โ”œโ”€โ”€ llm_provider_config.py
โ”‚       โ”‚   โ”œโ”€โ”€ model.py
โ”‚       โ”‚   โ”œโ”€โ”€ setting.py
โ”‚       โ”‚   โ””โ”€โ”€ prompt_template.py
โ”‚       โ”œโ”€โ”€ services/          # Business logic / use cases
โ”‚       โ”‚   โ”œโ”€โ”€ workspace.py
โ”‚       โ”‚   โ”œโ”€โ”€ chat.py
โ”‚       โ”‚   โ”œโ”€โ”€ config.py
โ”‚       โ”‚   โ”œโ”€โ”€ model_manager.py
โ”‚       โ”‚   โ”œโ”€โ”€ provider_manager.py
โ”‚       โ”‚   โ”œโ”€โ”€ prompt_manager.py
โ”‚       โ”‚   โ”œโ”€โ”€ settings_manager.py
โ”‚       โ”‚   โ””โ”€โ”€ adapter_manager.py
โ”‚       โ”œโ”€โ”€ adapters/          # LangChain adapters
โ”‚       โ”‚   โ”œโ”€โ”€ base.py        # Abstract adapter interface
โ”‚       โ”‚   โ””โ”€โ”€ ollama.py      # Ollama implementation
โ”‚       โ”œโ”€โ”€ tui/               # Text-based UI components
โ”‚       โ”‚   โ”œโ”€โ”€ app.py         # Main TUI application
โ”‚       โ”‚   โ”œโ”€โ”€ screens/       # UI screens
โ”‚       โ”‚   โ”œโ”€โ”€ widgets/       # Custom widgets
โ”‚       โ”‚   โ””โ”€โ”€ styles/        # TCSS styling
โ”‚       โ””โ”€โ”€ data/              # SQLite database
โ””โ”€โ”€ uv.lock

๐Ÿงช Testing

Run tests using pytest:

uv run pytest

๐Ÿค Contributing

Contributions are welcome!

  1. Fork the repository
  2. Create feature branch:
    git checkout -b feature/my-feature
    
  3. Commit changes:
    git commit -m "feat: description of my feature"
    
  4. Push to fork:
    git push origin feature/my-feature
    
  5. Open Pull Request

Please follow our coding guidelines and add tests for new features.


๐Ÿ“„ License

This project is licensed under the MIT License.

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

ocht-0.1.1.tar.gz (40.5 kB view details)

Uploaded Source

Built Distribution

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

ocht-0.1.1-py3-none-any.whl (57.5 kB view details)

Uploaded Python 3

File details

Details for the file ocht-0.1.1.tar.gz.

File metadata

  • Download URL: ocht-0.1.1.tar.gz
  • Upload date:
  • Size: 40.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.4

File hashes

Hashes for ocht-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f9ffd6ad6de22dbcca6fa2f89a51aa5136d57d54998ad0780de9c179e4fe78e2
MD5 1fb06543044e484784be53d9a59b1c38
BLAKE2b-256 d2c630180d8e0780b303c53278440191f3f73b89c89460d39cd19cd73ae23e9c

See more details on using hashes here.

File details

Details for the file ocht-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: ocht-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 57.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.4

File hashes

Hashes for ocht-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5b58f1f5cbec82141d2e2f2882393753502ef7502ceb94840026b4521494050a
MD5 3c24275c45cada43f0c5faf3468bf2af
BLAKE2b-256 b60727ef529f7b2df051f5a207654ab9828ba2dd101e4a2d881636ec4c912182

See more details on using hashes here.

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