### [fabric](https://github.com/danielmiessler/fabric)

> Handle: `fabric`
> URL: -

<div align="center">

<img src="https://github.com/danielmiessler/fabric/blob/main/images/fabric-logo-gif.gif" alt="fabriclogo" width="400" height="400"/>
</div>

![Static Badge](https://img.shields.io/badge/mission-human_flourishing_via_AI_augmentation-purple)
<br />
![GitHub top language](https://img.shields.io/github/languages/top/danielmiessler/fabric)
![GitHub last commit](https://img.shields.io/github/last-commit/danielmiessler/fabric)
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)

<p class="align center">
<code>fabric</code> is an open-source framework for augmenting humans using AI.
</p>

#### Starting

`fabric` is a CLI, so it doesn't need to be started on its own. It can be used in the same way as `cmdh` or `opint` on an ad-hoc basis.

```bash
# [Optional] pull the pre-built fabric images
harbor pull fabric

# First run - you'll have to run through setup
# otherwise the CLI will continue ignoring the commands
# If running with Harbors ollama - skip all the steps
harbor fabric --setup

# Check if service patterns are loading
# as expected - indicating everything is working
harbor fabric --listpatterns

# List all configured and available AI vendors
harbor fabric --listvendors
```

#### Configuration

Following options can be set via [`harbor config`](./3.-Harbor-CLI-Reference.md#harbor-config):

```bash
# Path on the host where fabric config will be stored
HARBOR_FABRIC_CONFIG_PATH      ~/.config/fabric

# Docker image to use for fabric
HARBOR_FABRIC_IMAGE            ghcr.io/ksylvan/fabric

# Docker tag to use for fabric image
HARBOR_FABRIC_VERSION          latest

# Default model to use with fabric. When running with Ollama,
# must be pre-pulled and available. Check available models with:
# harbor fabric --listmodels
HARBOR_FABRIC_MODEL            qwen3.5:4b
```

##### Ollama

Harbor automatically connects `fabric` to a running `ollama` instance. Additionally, you can configure a specific model to run.

```bash
# Start Ollama to use fabric
harbor up ollama

# Should display same list as "harbor ollama ls"
harbor fabric --listmodels

# Set the model to run
harbor fabric model qwen3.5:4b
```

##### LiteLLM

Harbor automatically connects `fabric` to a running `litellm` instance:

```bash
# Start LiteLLM to use fabric
harbor up litellm

# Set the model to run (must be a model configured in LiteLLM)
harbor fabric model my-model
```

##### Other OpenAI-compatible backends

Fabric (Go version) supports many OpenAI-compatible providers via environment variables.
Configure them by running `harbor fabric --setup` inside the container, or by setting
the appropriate `<VENDOR>_API_BASE_URL` and `<VENDOR>_API_KEY` env vars in
`services/fabric/override.env`.

Run `harbor fabric --listvendors` to see all available vendors.

#### REST API Server

`fabric` includes a built-in REST API server with a web UI. Start it with:

```bash
harbor fabric --serve
```

This exposes endpoints for chat completions, pattern management, model listing, and YouTube transcript extraction. An interactive API browser (Swagger UI) is available at `/swagger/index.html`.

Fabric can also serve as a drop-in Ollama replacement:

```bash
harbor fabric --serve --serveOllama
```

This adds Ollama-compatible endpoints (`/api/tags`, `/api/chat`), allowing tools configured for Ollama to use Fabric's pattern library.

#### Prompt Strategies

Fabric implements reasoning strategies that can be layered on top of any pattern:

```bash
# Available strategies: cot, cod, tot, aot, ltm, self-consistent, self-refine, reflexion, standard
harbor fabric --liststrategies

# Use chain-of-thought reasoning with a pattern
echo "Explain this code" | harbor fabric --strategy cot --pattern explain_code --stream
```

Install strategies to your config directory first:
```bash
harbor fabric --setup  # select the Strategies option
```

#### Usage

> [!NOTE]
> Note, during testing, `fabric` didn't seem to work with large contexts with ollama, so be cautious about the input size.

`fabric` is essentially a CLI for a library of very useful and diverse prompts to accomplish all kinds of tasks. Harbor supports the default pipe pattern when working with a CLI. Here are a few examples:

```bash
# Create a quiz about Harbor CLI - Neat!
cat $(harbor home)/harbor.sh | head -n 150 | harbor fabric --pattern create_quiz --stream
# > Subject: Bash Scripting and Container Management (Harbor CLI)
#   * Learning objective: Understand and utilize basic container management functions in a bash script
#    - Question 1: Which command is used to view the logs of running containers?
#      Answer 1: The `logs` or `l` command is used to view the logs of running containers.
#
#    - Question 2: What does the `exec` function in the Harbor CLI do?
#      Answer 2: The `exec` function in the Harbor CLI allows
#      you to execute a specific command inside a running service container.
#
#    - Question 3: How can you run a one-off command in a service container using the Harbor CLI?
#      Answer 3: You can use the `run` command followed by the name of
#      the service and then the command you want to execute, like so: `./harbor.sh run <service> <command>`.

# Why not generate some tags for the Harbor CLI
cat $(harbor home)/harbor.sh | head -n 50 | harbor fabric -sp create_tags
#   harbor_cli bash_script ollama nvidia gpu docker
#   llamacpp tgi lite_llm openai vllm aphrodite tabbyapi
#   mistralrs cloudflare parllama plandex open_interpreter fabric hugging_face

# Or a character card for DnD
cat $(harbor home)/harbor.sh | head -n 100 | harbor fabric -sp create_npc
#  Harbor CLI Character:
#
# Background: A former sailor and now a coder in the bustling
# city of Port Adrift, Alister was once known for his #adventurous
# spirit. He's since settled down and transformed his hobbies
# into professional opportunities, but he still has a knack for getting into trouble.
#
# Stats:
# - Strength: 14
# - Dexterity: 16 (due to his sailing experience)
# - Constitution: 12
# - Intelligence: 18
# - Wisdom: 10
# - Charisma: 15
```
