Commit 8519ba1
authored
Add chat-with-multimodal example (#116)
* Add chat-with-multimodal example
New examples/11-chat-with-multimodal/ demonstrates the headline of
proposal 0046 (ChatPrompt + PlaceholderSegment, shipped in v0.11.0)
end-to-end:
- ChatPrompt with ContentSegment (system + user) and
PlaceholderSegment for chat-history injection.
- Multi-turn conversation memory threaded through state via the
``append`` reducer; each turn's render() sees the full prior
history through the placeholder slot.
- Multimodal turn: one of four scripted turns attaches a NASA
public-domain Apollo 16 LM "Orion" photograph via
ImageURLBlockTemplate. Same chat template, only the trailing
user ContentSegment's content shape changes (string vs
content-blocks list); system + placeholder segments are
identical across both shapes.
- Error handling at the invoke() boundary: try/except NodeException
in main(), inspect exc.__cause__ for LlmProviderError to surface
the canonical category string. Comments name the other two
legitimate handler locations (RetryMiddleware, node-internal
try/except).
- Streaming transcript: each turn prints from inside the respond
node body so the conversation arrives as the graph executes
rather than waiting for invoke() to return. A 0.5s
``_TURN_DELAY_S`` pacing constant lets the reader follow along.
- ``--traces`` argparse flag (default off) opts in to the OTel
observer with a console exporter. Without it the chat runs
without any observer attached; with it, JSON spans stream to
stderr alongside the conversation on stdout.
Complementary to example 09 (tool calling); chat history threading
and tool calling are separate primitives. Example 03 owns the
observer-hooks story, so this example points readers there for the
observability details rather than re-teaching them.
Bonus pickup: docs/examples/index.md was missing example 10 from
its catalog before this PR. Caught alongside the example 11 entry
and added.
* Fix three docstring inconsistencies per PR review
Three CoPilot findings on PR #116:
1. main.py docstring referenced PlaceholderSegment(name="history")
but the actual field is named ``placeholder``. The code's
chat-template construction uses ``placeholder=`` correctly; only
the docstring narrative was wrong. A reader copy-pasting from the
docstring would have hit a Pydantic ValidationError.
2. Walk-through doc's intro paragraph still said "Apollo 11 Lunar
Module" after the image URL swap to the Apollo 16 "Orion" shot.
The code's docstring + inline comment got updated when the URL
changed but the walk-through intro was missed.
3. Sample "Reading the output" block showed an ``upload.wikimedia.org``
image URL the example explicitly warns against. Updated to the
actual default ``images-assets.nasa.gov`` URL so the sample
matches a real run.1 parent dc13b71 commit 8519ba1
6 files changed
Lines changed: 704 additions & 0 deletions
File tree
- docs/examples
- examples/11-chat-with-multimodal
- src/openarmature
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
46 | 54 | | |
47 | 55 | | |
48 | 56 | | |
| |||
0 commit comments