Elia Documentation

repository·main·Indexed 25 days ago

https://github.com/darrenburns/elia

A keyboard-centric terminal user interface (TUI) for interacting with Large Language Models, including proprietary providers like ChatGPT, Claude, and Gemini, as well as local models via Ollama or LocalAI. Features include inline mode, custom UI themes, ChatGPT conversation imports, and a programmatic API for managing chat history via ChatsManager.

Tokens
5.3K
Snippets
7
Records
40
Agent score
80%

What's inside Elia

  1. Run local models with Ollama

    main

    To use local models via ollama, follow these steps:

    1. Install ollama.
    2. Pull the desired model (e.g., ollama pull llama3).
    3. Start the local server with ollama serve.
    4. Add the model to your Elia configuration file (see Configuration section).
  2. Create custom UI themes

    main

    You can add custom themes by placing a YAML file in the Elia themes directory. To find the directory, press ctrl+o on the home screen.

    A theme file must define colors for various UI elements:

    name: example  # use this name in your config file
    primary: '#4e78c4'
    secondary: '#f39c12'
    accent: '#e74c3c'
    background: '#0e1726'
    surface: '#17202a'
    error: '#e74c3c'
    success: '#2ecc71'
    warning: '#f1c40f'
  3. Launch Elia and use CLI options

    main

    You can launch Elia from the command line with various modes and model specifications:

    • Standard launch: elia opens the TUI.
    • Inline mode: Use -i or --inline to launch a new chat directly under your prompt.
    • Full-screen mode: Pass a prompt string directly to launch in full-screen.
    • Specify model: Use -m or --model to select a specific model.

    Example: Launching Gemini 1.5 Flash in inline mode:

    elia -i -m gemini/gemini-1.5-flash-latest "How do I call Rust code from Python?"
  4. Install Elia via pipx

    main

    Install the elia-chat package using pipx. It is recommended to use Python 3.11. Depending on the models you intend to use, you will need to set the appropriate environment variables such as OPENAI_API_KEY, ANTHROPIC_API_KEY, or GEMINI_API_KEY.

    pipx install --python 3.11 elia-chat
  5. Subscribe to runtime configuration changes

    main

    The Elia application exposes a runtime_config_signal which is a Signal[RuntimeConfig]. This allows widgets or other components to subscribe to updates whenever the user changes settings (like the selected model or system prompt) via the UI.

    When the runtime_config property is updated via its setter, this signal publishes the new RuntimeConfig object.

  6. Configure Elia settings and models

    main

    Elia uses a configuration file (location found via ctrl+o in the app) to manage default settings and model definitions.

    Global Settings

    • default_model: The model ID used on launch.
    • system_prompt: The system instruction used on launch.
    • theme: UI theme. Options: "nebula", "cobalt", "twilight", "hacker", "alpine", "galaxy", "nautilus", "monokai", "textual".
    • message_code_theme: Pygments syntax highlighting theme for code blocks (defaults to "monokai").

    Defining Models

    You can define models in a [[models]] array. Supported fields include:

    • name: The model identifier (e.g., ollama/llama3 or openai/some-model).
    • id: A unique identifier for the model instance.
    • display_name: The name shown in the UI.
    • provider: The provider name shown in the UI.
    • api_base: The base URL for local servers (e.g., LocalAI).
    • api_key: Required for many proprietary providers.
    • temperature: Controls output variation.
    • max_retries: Number of retries on failed requests.
    # Example configuration
    default_model = "gpt-4o"
    system_prompt = "You are a helpful assistant who talks like a pirate."
    theme = "galaxy"
    message_code_theme = "dracula"
    
    [[models]]
    name = "ollama/llama3"
    
    [[models]]
    name = "openai/some-model"
    api_base = "http://localhost:8080/v1"
    api_key = "api-key-if-required"
    
    [[models]]
    name = "groq/llama2-70b-4096"
    display_name = "Llama 2 70B"
    provider = "Groq"
    temperature = 1.0
    max_retries = 0
  7. Retrieve an EliaChatModel using get_model()

    main

    Use get_model(model_id_or_name, config) to look up an EliaChatModel instance. The function first attempts to find a match by the model's id, and if that fails, it attempts to find a match by the model's name.

    If no match is found, it returns an instance of UnknownModel (which inherits from EliaChatModel) with the ID and name set to "unknown".

    If config is not provided, the function attempts to retrieve the launch_config from the active_app context.

  8. Manage conversation history with ChatsManager

    main
    The ChatsManager class provides a static asynchronous API for managing chat sessions and their message histories in the database. It handles operations such as retrieving all chats, fetching specific chat details, renaming chats, creating new chats with initial messages, archiving chats, and appending new messages to existing conversations.