Skip to content

Commit ac51a81

Browse files
committed
Merge branch 'chore/documentation_updates'
2 parents 9f5fd72 + b47f63e commit ac51a81

12 files changed

Lines changed: 232 additions & 7 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ talkpipe/
508508

509509
## Configuration
510510

511-
TalkPipe uses a flexible configuration system via `~/.talkpipe.toml` or environment variables:
511+
TalkPipe uses a flexible configuration system via `~/.talkpipe.toml` or environment variables. For LLM and embedding `model` / `source` defaults, see [Model and source configuration](docs/guides/model-and-source-configuration.md).
512512

513513
```toml
514514
# ~/.talkpipe.toml

docs/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ New to TalkPipe? Start here for installation, basic concepts, and your first pip
1010
### 📖 [RAG Commands](guides/makevectordatabase-and-serverag.md)
1111
Create vector databases and run RAG servers in two commands: `makevectordatabase` and `serverag`.
1212

13+
### ⚙️ [Model and source configuration](guides/model-and-source-configuration.md)
14+
Set default LLM and embedding providers via segment parameters, `~/.talkpipe.toml`, or environment variables.
15+
1316
### 🐳 [Container images](guides/container-images.md)
1417
Pull multi-platform release images from GitHub Container Registry (`ghcr.io`), tags, and Docker/Podman usage.
1518

docs/api-reference/chatterlang-script.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ chatterlang_script \
6666
--factor 10
6767
```
6868

69-
This feature is useful for parameterizing scripts without editing configuration files or script content.
69+
This feature is useful for parameterizing scripts without editing configuration files or script content. You can use `$key` for `model` and `source` on LLM segments (for example `llmPrompt[model=$default_model_name, source=$default_model_source]`). See [Model and source configuration](../guides/model-and-source-configuration.md).
7070

7171
## Troubleshooting
7272

docs/architecture/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ How TalkPipe manages configuration across different environments.
5555
- Precedence rules
5656
- Security considerations
5757

58+
For LLM and embedding `model` / `source` defaults, see [Model and source configuration](../guides/model-and-source-configuration.md).
59+
5860
---
5961

6062
*For API details, see [API Reference](../api-reference/). For working examples, see the [tutorials](../tutorials/) directory.*

docs/architecture/chatterlang.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ INPUT FROM @variable_name
5959

6060
#### `llmPrompt` conversation memory controls
6161

62+
For `model`, `source`, and global defaults, see [Model and source configuration](../guides/model-and-source-configuration.md).
63+
6264
When using `llmPrompt`, three parameters control memory compaction behavior:
6365

6466
- `context_token_trigger`: **when** compaction triggers.

docs/architecture/configuration.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ For application settings (logging, server ports, etc.):
148148

149149
### Embedding and LLM defaults: `serverag` vs segment keys
150150

151+
See [Model and source configuration](../guides/model-and-source-configuration.md) for a user-focused guide to `model`, `source`, and related config keys.
152+
151153
Several components resolve embedding and chat model defaults from `get_config()`. Two naming patterns appear in configuration:
152154

153155
- **Segment defaults**`LLMEmbed` and `LLMPrompt` fall back to these keys when `model` / `source` arguments are omitted: `default_embedding_model_name`, `default_embedding_model_source`, `default_model_name`, and `default_model_source` (see `talkpipe.util.constants`).

docs/contributing/developer-handbook.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ After talkpipe is installed, a script called "chatterlang_reference_browser" is
9090

9191
Configuration constants can be defined either in ~/.talkpipe.toml or in environment variables. Any constant defined in an environment variable needs to be prefixed with TALKPIPE_. So email_password, stored in an environment variable, needs to be TALKPIPE_email_password. Note that in ChatterLang, any key defined in ~/.talkpipe.toml or set via a TALKPIPE_* environment variable can be referenced in scripts as a parameter using $var_name. That reference resolves to the environment variable TALKPIPE_var_name or to var_name in talkpipe.toml.
9292

93+
For how `model`, `source`, and LLM defaults interact across segments and CLIs, see [Model and source configuration](../guides/model-and-source-configuration.md).
94+
9395
* **default_embedding_model_source** - The default source (e.g. ollama) to be used for creating sentence embeddings.
9496
* **default_embedding_model_name** - The name of the LLM model to be used for creating sentence embeddings.
9597
* **default_model_name** - The default name of a LLM model to be used in chat

docs/guides/makevectordatabase-and-serverag.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Together they form a minimal path from raw documents to a queryable RAG interfac
2424
- **Completion model** (for serverag): Ollama with an LLM (e.g. `ollama pull llama3.2`)
2525
- **Configuration**: Set `DEFAULT_EMBEDDING_MODEL`, `DEFAULT_EMBEDDING_SOURCE`, `DEFAULT_LLM_MODEL`, and `DEFAULT_LLM_SOURCE` in `~/.talkpipe.toml` or pass them on the command line
2626

27-
See [Configuration](../architecture/configuration.md) for details.
27+
See [Model and source configuration](model-and-source-configuration.md) for how embedding and completion defaults work. For general config (logging, `$key` syntax), see [Configuration](../architecture/configuration.md).
2828

2929
---
3030

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
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

docs/quickstart.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ chat = compiler.compile(script).as_function(single_in=True, single_out=True)
9696
response = chat("Hello! Tell me about the history of computers.")
9797
```
9898

99+
To avoid repeating `model` and `source` on every segment, set defaults in `~/.talkpipe.toml` or environment variables. See [Model and source configuration](guides/model-and-source-configuration.md).
100+
99101
For `llmPrompt` memory behavior (`context_token_trigger`, `memory_mode`, `unsummarized_message_count`, `memory_size`), see
100102
[ChatterLang memory controls](architecture/chatterlang.md#llmprompt-conversation-memory-controls).
101103

0 commit comments

Comments
 (0)