Skip to content

lxol/gptel-fabric

Repository files navigation

gptel-fabric

License: GPL v3 MELPA MELPA Stable

An Emacs package that integrates Fabric prompts with gptel for powerful LLM interactions.

Features

  • Use Fabric patterns (prompts) directly within Emacs
  • No Fabric binary required - works entirely through gptel
  • Support for both standard and custom Fabric patterns
  • Interactive pattern selection with completion
  • Create custom shortcuts for frequently used patterns
  • Pattern caching for fast access
  • History of recently used patterns

Requirements

  • Emacs 27.1 or later
  • gptel 0.8.0 or later
  • Fabric patterns installed (typically in ~/.config/fabric/)

Installation

From MELPA

(use-package gptel-fabric
  :ensure t
  :after gptel
  :config
  (gptel-fabric-setup))

Prerequisites

  1. Install and configure gptel
  2. Have Fabric patterns installed in ~/.config/fabric/ (or configure custom location)

Manual Installation

;; Clone this repository, then add to your init file:
(add-to-list 'load-path "/path/to/gptel-fabric")
(require 'gptel-fabric)

;; Optional: Setup with default configuration
(gptel-fabric-setup)

Using use-package

(use-package gptel-fabric
  :load-path "/path/to/gptel-fabric"
  :after gptel
  :config
  (gptel-fabric-setup)
  ;; Optional: Set default pattern
  (setq gptel-fabric-default-pattern "summarize"))

Configuration

Basic Configuration

;; Set Fabric config directory (default: ~/.config/fabric/)
(setq gptel-fabric-config-dir "~/my-fabric-config/")

;; Set custom patterns directory explicitly
(setq gptel-fabric-custom-patterns-dir "~/my-patterns/")

;; Set default pattern
(setq gptel-fabric-default-pattern "summarize")

;; Set history length
(setq gptel-fabric-history-length 30)

Usage

Interactive Commands

  • gptel-fabric-select-pattern - Select a pattern interactively
  • gptel-fabric-send-with-pattern - Send region/buffer with selected pattern
    • Without prefix: Opens result in new buffer
    • With prefix (C-u): Inserts result at point
  • gptel-fabric-replace-with-pattern - Replace region/buffer with LLM output
    • Replaces region if active, otherwise entire buffer
  • gptel-fabric-proofread - Quick proofreading with replacement
  • gptel-fabric-query-with-pattern - Send a query with selected pattern
  • gptel-fabric-list-patterns - List all available patterns
  • gptel-fabric-describe-pattern - Show details of a specific pattern
  • gptel-fabric-refresh-cache - Refresh the patterns cache

Creating Custom Shortcuts

You can create dedicated commands for frequently used patterns:

;; Create a command for the 'summarize' pattern
(gptel-fabric-create-pattern-command "summarize")
;; This creates: gptel-fabric-run-summarize

;; Create a replace command for proofreading
(gptel-fabric-create-replace-command "proofreader")
;; This creates: gptel-fabric-replace-proofreader

;; Bind to keys
(global-set-key (kbd "C-c g s") 'gptel-fabric-run-summarize)
(global-set-key (kbd "C-c g p") 'gptel-fabric-replace-proofreader)

;; Or use the built-in proofreading function
(global-set-key (kbd "C-c g P") 'gptel-fabric-proofread)

Example Workflow

  1. Summarize text:

    ;; Select text in buffer
    M-x gptel-fabric-send-with-pattern RET summarize RET
  2. Proofread and replace text:

    ;; Select text or use whole buffer
    M-x gptel-fabric-proofread RET
    ;; Or with any pattern:
    M-x gptel-fabric-replace-with-pattern RET improve_writing RET
  3. Quick query with pattern:

    M-x gptel-fabric-query-with-pattern RET explain_code RET
    ;; Type your code or question
  4. Using with keybindings:

    ;; Add to your config
    (define-key gptel-mode-map (kbd "C-c f") 'gptel-fabric-send-with-pattern)
    (define-key gptel-mode-map (kbd "C-c F") 'gptel-fabric-select-pattern)
    (define-key gptel-mode-map (kbd "C-c r") 'gptel-fabric-replace-with-pattern)

Pattern Structure

Fabric patterns are expected to have the following structure:

~/.config/fabric/
├── patterns/
│   ├── summarize/
│   │   ├── system.md
│   │   └── user.md
│   └── explain_code/
│       ├── system.md
│       └── user.md
└── patterns-custom/
    └── my-pattern/
        ├── system.md
        └── user.md
  • system.md - Contains the system prompt for the LLM
  • user.md - Contains user prompt template (optional)

Tips

  1. Pattern Discovery: Use gptel-fabric-list-patterns to see all available patterns
  2. Pattern Details: Use gptel-fabric-describe-pattern to view pattern prompts
  3. Custom Patterns: Custom patterns are marked with [CUSTOM] in listings
  4. Performance: Patterns are cached on first use; refresh with gptel-fabric-refresh-cache

Development

Running Tests

# With gptel installed (full test suite)
make test

# Or specify gptel location
GPTEL_DIR=/path/to/gptel make test

# Standalone tests (without gptel)
make test-standalone

Byte Compilation

make compile

Linting

make lint
make package-lint  # Requires package-lint

Full Check

make check  # Runs lint and tests

License

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

See LICENSE for details.

Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Before submitting, please ensure:

  • All tests pass (make test)
  • Code is properly formatted
  • Documentation is updated if needed

Acknowledgments

  • gptel for the excellent LLM integration
  • Fabric for the comprehensive prompt patterns

Author

Alex Olkhovskiy gtptel-fabric@monoinbox.co.uk

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors