|
| 1 | +# Model and source configuration |
| 2 | + |
| 3 | +TalkPipe LLM segments need two values for every call: |
| 4 | + |
| 5 | +- **`source`** — which backend provides the model (for example `ollama`, `openai`, or `anthropic` for chat). |
| 6 | +- **`model`** — the model id on that backend (for example `llama3.2`, `gpt-4o`, or `mxbai-embed-large`). |
| 7 | + |
| 8 | +You can set these on each segment, in `~/.talkpipe.toml`, via `TALKPIPE_*` environment variables, or through ChatterLang `$key` substitution. This guide explains how those layers interact. For logging, security, and general config mechanics, see [Configuration architecture](../architecture/configuration.md). |
| 9 | + |
| 10 | +--- |
| 11 | + |
| 12 | +## Supported sources |
| 13 | + |
| 14 | +Sources are registered in `talkpipe.llm.config`: |
| 15 | + |
| 16 | +| Segment | Registered sources | |
| 17 | +|---------|-------------------| |
| 18 | +| **`llmPrompt`** (chat) | `ollama`, `openai`, `anthropic` | |
| 19 | +| **`llmEmbed`** (embeddings) | `ollama` | |
| 20 | + |
| 21 | +Additional sources can be registered at runtime with `registerPromptAdapter` or `registerEmbeddingAdapter` (see [Extending TalkPipe](../architecture/extending-talkpipe.md)). |
| 22 | + |
| 23 | +Install optional provider dependencies as needed: `pip install talkpipe[ollama]`, `talkpipe[openai]`, `talkpipe[anthropic]`, or `talkpipe[all]`. |
| 24 | + |
| 25 | +--- |
| 26 | + |
| 27 | +## How values are resolved |
| 28 | + |
| 29 | +When `LLMPrompt` or `LLMEmbed` is constructed, TalkPipe fills in missing `model` / `source` from `get_config()` (merged `~/.talkpipe.toml` plus `TALKPIPE_*` environment variables). If either is still missing, construction raises an error. |
| 30 | + |
| 31 | +```mermaid |
| 32 | +flowchart TD |
| 33 | + segmentParams["Segment parameters model and source"] |
| 34 | + chatterlangDollar["ChatterLang $key at parse time"] |
| 35 | + getConfig["get_config: TALKPIPE env then talkpipe.toml"] |
| 36 | + providerSdk["Provider SDK env OPENAI_API_KEY etc"] |
| 37 | +
|
| 38 | + segmentParams -->|"highest for LLM segments"| resolved["Resolved model and source"] |
| 39 | + chatterlangDollar --> segmentParams |
| 40 | + getConfig --> segmentParams |
| 41 | + providerSdk -->|"credentials only"| adapters["OpenAI and Anthropic adapters"] |
| 42 | +``` |
| 43 | + |
| 44 | +### Precedence (highest first) |
| 45 | + |
| 46 | +| Layer | How it applies | Example | |
| 47 | +|-------|----------------|---------| |
| 48 | +| **Segment parameters** | Explicit `model` / `source` on the segment always win | `llmPrompt[model="gpt-4o", source="openai"]` | |
| 49 | +| **ChatterLang `$key`** | Resolved at parse time from `get_config()` | `llmPrompt[model=$default_model_name, source=$default_model_source]` | |
| 50 | +| **Environment variables** | `TALKPIPE_` + exact config key name | `export TALKPIPE_default_model_name=llama3.2` | |
| 51 | +| **Configuration file** | `~/.talkpipe.toml` | `default_model_name = "llama3.2"` | |
| 52 | + |
| 53 | +Within `get_config()`, environment variables override file values. ChatterLang `$key` precedence for CLI overrides is documented in [Configuration architecture](../architecture/configuration.md#chatterlang-script-variable-access): command-line `--key value` beats `TALKPIPE_key` beats TOML. |
| 54 | + |
| 55 | +**Provider credentials** (API keys) are separate: OpenAI and Anthropic adapters use their official SDKs, which read `OPENAI_API_KEY` and `ANTHROPIC_API_KEY` from the environment—not TalkPipe `default_*` keys. |
| 56 | + |
| 57 | +--- |
| 58 | + |
| 59 | +## Configuration keys |
| 60 | + |
| 61 | +### Segment defaults (`default_*`) |
| 62 | + |
| 63 | +Used by `llmPrompt` and `llmEmbed` when `model` / `source` are omitted: |
| 64 | + |
| 65 | +| Purpose | TOML / config key | Environment variable | |
| 66 | +|---------|-------------------|----------------------| |
| 67 | +| Default chat model | `default_model_name` | `TALKPIPE_default_model_name` | |
| 68 | +| Default chat source | `default_model_source` | `TALKPIPE_default_model_source` | |
| 69 | +| Default embedding model | `default_embedding_model_name` | `TALKPIPE_default_embedding_model_name` | |
| 70 | +| Default embedding source | `default_embedding_model_source` | `TALKPIPE_default_embedding_model_source` | |
| 71 | +| Ollama server URL | `OLLAMA_SERVER_URL` | `TALKPIPE_OLLAMA_SERVER_URL` | |
| 72 | + |
| 73 | +Example `~/.talkpipe.toml`: |
| 74 | + |
| 75 | +```toml |
| 76 | +default_model_name = "llama3.2" |
| 77 | +default_model_source = "ollama" |
| 78 | +default_embedding_model_name = "mxbai-embed-large" |
| 79 | +default_embedding_model_source = "ollama" |
| 80 | +OLLAMA_SERVER_URL = "http://localhost:11434" |
| 81 | +``` |
| 82 | + |
| 83 | +### RAG CLI defaults (`DEFAULT_*`) |
| 84 | + |
| 85 | +`makevectordatabase` and `serverag` read these when you omit `--embedding_model`, `--embedding_source`, `--completion_model`, and `--completion_source`: |
| 86 | + |
| 87 | +| Purpose | TOML / config key | Environment variable | |
| 88 | +|---------|-------------------|----------------------| |
| 89 | +| Embedding model | `DEFAULT_EMBEDDING_MODEL` | `TALKPIPE_DEFAULT_EMBEDDING_MODEL` | |
| 90 | +| Embedding source | `DEFAULT_EMBEDDING_SOURCE` | `TALKPIPE_DEFAULT_EMBEDDING_SOURCE` | |
| 91 | +| Completion model | `DEFAULT_LLM_MODEL` | `TALKPIPE_DEFAULT_LLM_MODEL` | |
| 92 | +| Completion source | `DEFAULT_LLM_SOURCE` | `TALKPIPE_DEFAULT_LLM_SOURCE` | |
| 93 | + |
| 94 | +If a CLI flag is omitted and the matching `DEFAULT_*` key is unset, the value passed into the RAG pipeline may be `None`, and inner `llmEmbed` / `llmPrompt` segments fall back to the `default_*` keys above. |
| 95 | + |
| 96 | +**Recommendation:** set `default_*` once for most workflows. Add `DEFAULT_*` only when you want different defaults specifically for the RAG commands. See [makevectordatabase and serverag](makevectordatabase-and-serverag.md). |
| 97 | + |
| 98 | +--- |
| 99 | + |
| 100 | +## Segment parameters |
| 101 | + |
| 102 | +### `llmPrompt` / `LLMPrompt` |
| 103 | + |
| 104 | +Required (directly or via config): `model`, `source`. |
| 105 | + |
| 106 | +```chatterlang |
| 107 | +INPUT FROM prompt[data="Summarize this:"] |
| 108 | +| llmPrompt[model="llama3.2", source="ollama", field="data"] |
| 109 | +| print |
| 110 | +``` |
| 111 | + |
| 112 | +```python |
| 113 | +from talkpipe.llm.chat import LLMPrompt |
| 114 | + |
| 115 | +segment = LLMPrompt(model="gpt-4o", source="openai", system_prompt="You are concise.") |
| 116 | +``` |
| 117 | + |
| 118 | +Memory and compaction options (`memory_mode`, `context_token_trigger`, etc.) are described in [ChatterLang memory controls](../architecture/chatterlang.md#llmprompt-conversation-memory-controls). |
| 119 | + |
| 120 | +### `llmEmbed` / `LLMEmbed` |
| 121 | + |
| 122 | +Required (directly or via config): `model`, `source`. Optional: `field` (text field to embed), `set_as` (field to store the vector on the item). |
| 123 | + |
| 124 | +```chatterlang |
| 125 | +INPUT FROM echo[data="Hello world"] |
| 126 | +| llmEmbed[model="mxbai-embed-large", source="ollama", set_as="vector"] |
| 127 | +| print |
| 128 | +``` |
| 129 | + |
| 130 | +### RAG and vector pipelines |
| 131 | + |
| 132 | +Higher-level segments forward model settings to inner LLM segments: |
| 133 | + |
| 134 | +| Segment / app | Parameters | |
| 135 | +|---------------|------------| |
| 136 | +| `makeVectorDatabase`, `searchVectorDatabase` | `embedding_model`, `embedding_source` | |
| 137 | +| `ragToText`, `ragToBinaryAnswer`, etc. | `embedding_model`, `embedding_source`, `completion_model`, `completion_source` | |
| 138 | +| `makevectordatabase`, `serverag` CLIs | `--embedding_model`, `--embedding_source`, `--completion_model`, `--completion_source` | |
| 139 | + |
| 140 | +### Ollama server URL |
| 141 | + |
| 142 | +Not a segment parameter by default. Set `OLLAMA_SERVER_URL` in config or `TALKPIPE_OLLAMA_SERVER_URL` in the environment when Ollama is not on localhost. |
| 143 | + |
| 144 | +--- |
| 145 | + |
| 146 | +## Examples |
| 147 | + |
| 148 | +### 1. Explicit model and source (per call) |
| 149 | + |
| 150 | +```chatterlang |
| 151 | +INPUT FROM prompt[data="Hello"] |
| 152 | +| llmPrompt[model="llama3.2", source="ollama"] |
| 153 | +| print |
| 154 | +``` |
| 155 | + |
| 156 | +### 2. Global defaults in TOML |
| 157 | + |
| 158 | +With `default_model_name` and `default_model_source` set in `~/.talkpipe.toml`: |
| 159 | + |
| 160 | +```chatterlang |
| 161 | +INPUT FROM prompt[data="Hello"] |
| 162 | +| llmPrompt |
| 163 | +| print |
| 164 | +``` |
| 165 | + |
| 166 | +### 3. Environment-only defaults (containers / CI) |
| 167 | + |
| 168 | +```bash |
| 169 | +export TALKPIPE_default_model_name=llama3.2 |
| 170 | +export TALKPIPE_default_model_source=ollama |
| 171 | +export TALKPIPE_default_embedding_model_name=mxbai-embed-large |
| 172 | +export TALKPIPE_default_embedding_model_source=ollama |
| 173 | +chatterlang_script --script 'INPUT FROM prompt[data="Hi"] | llmPrompt | print' |
| 174 | +``` |
| 175 | + |
| 176 | +### 4. ChatterLang `$key` and CLI overrides |
| 177 | + |
| 178 | +```bash |
| 179 | +chatterlang_script --script 'INPUT FROM prompt[data="Hi"] | llmPrompt[model=$default_model_name, source=$default_model_source] | print' \ |
| 180 | + --default_model_name llama3.2 \ |
| 181 | + --default_model_source ollama |
| 182 | +``` |
| 183 | + |
| 184 | +### 5. Pipe API with config fallback |
| 185 | + |
| 186 | +```python |
| 187 | +from talkpipe.llm.chat import LLMPrompt |
| 188 | + |
| 189 | +# Uses default_model_name / default_model_source from config when omitted |
| 190 | +segment = LLMPrompt(system_prompt="You are helpful.") |
| 191 | +``` |
| 192 | + |
| 193 | +--- |
| 194 | + |
| 195 | +## Troubleshooting |
| 196 | + |
| 197 | +| Symptom | What to check | |
| 198 | +|---------|----------------| |
| 199 | +| `Model name and source must be provided` | Set `model` and `source` on the segment, or add `default_model_name` and `default_model_source` (or embedding equivalents for `llmEmbed`). | |
| 200 | +| `Unknown source` | Chat: use `ollama`, `openai`, or `anthropic`. Embeddings: only `ollama` is registered unless you added adapters. | |
| 201 | +| Ollama connection refused | Run `ollama serve` or set `OLLAMA_SERVER_URL` / `TALKPIPE_OLLAMA_SERVER_URL`. | |
| 202 | +| OpenAI / Anthropic auth errors | Set `OPENAI_API_KEY` or `ANTHROPIC_API_KEY`; these are not read from `TALKPIPE_*` model keys. | |
| 203 | +| RAG CLI uses unexpected models | Check `DEFAULT_*` keys and CLI flags; then check segment `default_*` fallbacks. | |
| 204 | + |
| 205 | +--- |
| 206 | + |
| 207 | +## Related documentation |
| 208 | + |
| 209 | +- [Configuration architecture](../architecture/configuration.md) — full config system, precedence, and security |
| 210 | +- [ChatterLang](../architecture/chatterlang.md) — DSL syntax and `llmPrompt` memory |
| 211 | +- [makevectordatabase and serverag](makevectordatabase-and-serverag.md) — RAG workflow |
| 212 | +- [Quickstart](../quickstart.md) — first pipeline examples |
| 213 | +- [Developer handbook](../contributing/developer-handbook.md) — standard `~/.talkpipe.toml` keys |
0 commit comments