poml 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/docs/tutorial/advanced/performance.md +695 -0
- data/docs/tutorial/advanced/tool-registration.md +776 -0
- data/docs/tutorial/basic-usage.md +351 -0
- data/docs/tutorial/components/chat-components.md +552 -0
- data/docs/tutorial/components/formatting.md +623 -0
- data/docs/tutorial/components/index.md +366 -0
- data/docs/tutorial/components/media-components.md +259 -0
- data/docs/tutorial/components/schema-components.md +668 -0
- data/docs/tutorial/index.md +184 -0
- data/docs/tutorial/output-formats.md +688 -0
- data/docs/tutorial/quickstart.md +30 -0
- data/docs/tutorial/template-engine.md +540 -0
- data/lib/poml/components/base.rb +146 -4
- data/lib/poml/components/content.rb +10 -3
- data/lib/poml/components/data.rb +539 -19
- data/lib/poml/components/examples.rb +235 -1
- data/lib/poml/components/formatting.rb +184 -18
- data/lib/poml/components/layout.rb +7 -2
- data/lib/poml/components/lists.rb +69 -35
- data/lib/poml/components/meta.rb +134 -5
- data/lib/poml/components/output_schema.rb +19 -1
- data/lib/poml/components/template.rb +72 -61
- data/lib/poml/components/text.rb +30 -1
- data/lib/poml/components/tool.rb +81 -0
- data/lib/poml/components/tool_definition.rb +339 -10
- data/lib/poml/components/tools.rb +14 -0
- data/lib/poml/components/utilities.rb +34 -18
- data/lib/poml/components.rb +19 -0
- data/lib/poml/context.rb +19 -4
- data/lib/poml/parser.rb +88 -63
- data/lib/poml/renderer.rb +191 -9
- data/lib/poml/template_engine.rb +138 -13
- data/lib/poml/version.rb +1 -1
- data/lib/poml.rb +16 -1
- data/readme.md +154 -27
- metadata +31 -4
- data/TUTORIAL.md +0 -987
@@ -0,0 +1,366 @@
|
|
1
|
+
# Components Overview
|
2
|
+
|
3
|
+
POML provides a rich set of components for creating structured, dynamic AI prompts. This page provides an overview of all available components organized by category.
|
4
|
+
|
5
|
+
## Component Categories
|
6
|
+
|
7
|
+
### [Chat Components](chat-components.md)
|
8
|
+
|
9
|
+
Specialized components for creating structured AI conversations:
|
10
|
+
|
11
|
+
- **`<system>`** - System-level instructions and context
|
12
|
+
- **`<human>`** - User messages and queries
|
13
|
+
- **`<ai>`** - Assistant responses and few-shot examples
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
<poml>
|
17
|
+
<system>You are a helpful programming assistant.</system>
|
18
|
+
<human>How do I optimize this Ruby code?</human>
|
19
|
+
<ai>Here are some optimization strategies...</ai>
|
20
|
+
</poml>
|
21
|
+
```
|
22
|
+
|
23
|
+
### [Formatting Components](formatting.md)
|
24
|
+
|
25
|
+
Text formatting and structure components:
|
26
|
+
|
27
|
+
- **`<b>`** - **Bold text**
|
28
|
+
- **`<i>`** - *Italic text*
|
29
|
+
- **`<u>`** - Underlined text
|
30
|
+
- **`<s>`** - ~~Strikethrough text~~
|
31
|
+
- **`<code>`** - `Inline code`
|
32
|
+
- **`<h1>` to `<h6>`** - Headers
|
33
|
+
- **`<br>`** - Line breaks
|
34
|
+
- **`<p>`** - Paragraphs
|
35
|
+
|
36
|
+
### [Data Components](data-components.md)
|
37
|
+
|
38
|
+
Components for handling data and structured content:
|
39
|
+
|
40
|
+
- **`<table>`** - Render tables from CSV/JSON data
|
41
|
+
- **`<object>`** - Object serialization (JSON, YAML, XML)
|
42
|
+
- **`<file>`** - File content reading with path resolution
|
43
|
+
- **`<folder>`** - Directory listing with depth control
|
44
|
+
|
45
|
+
### [Media Components](media-components.md)
|
46
|
+
|
47
|
+
Multimedia content components:
|
48
|
+
|
49
|
+
- **`<img>`** - Image processing with URL fetching and base64 support
|
50
|
+
- **`<audio>`** - Audio file handling
|
51
|
+
|
52
|
+
### [Schema Components](schema-components.md)
|
53
|
+
|
54
|
+
Components for defining structured AI responses and tools:
|
55
|
+
|
56
|
+
- **`<output-schema>`** - AI response schema definitions
|
57
|
+
- **`<tool-definition>`** - AI tool registration with parameters
|
58
|
+
- **`<meta type="output-schema">`** - Legacy schema support
|
59
|
+
- **`<meta type="tool-definition">`** - Legacy tool definition support
|
60
|
+
|
61
|
+
### [Utility Components](utility-components.md)
|
62
|
+
|
63
|
+
Helper components for specialized content:
|
64
|
+
|
65
|
+
- **`<list>` & `<item>`** - Unordered lists with nested content
|
66
|
+
- **`<conversation>`** - Chat conversation display
|
67
|
+
- **`<tree>`** - Tree structure display with JSON data
|
68
|
+
- **`<include>`** - Template inclusion and composition
|
69
|
+
|
70
|
+
### Template Engine Components
|
71
|
+
|
72
|
+
Dynamic content generation components:
|
73
|
+
|
74
|
+
- **`<if condition="">`** - Conditional logic with comparisons
|
75
|
+
- **`<for variable="" items="">`** - Loops and iteration
|
76
|
+
- **`{{variable}}`** - Variable substitution
|
77
|
+
- **`<meta variables="">`** - Template variables definition
|
78
|
+
|
79
|
+
### Structural Components
|
80
|
+
|
81
|
+
Basic structural components:
|
82
|
+
|
83
|
+
- **`<poml>`** - Root container for all POML content
|
84
|
+
- **`<role>`** - Define AI role and expertise
|
85
|
+
- **`<task>`** - Specify what AI should accomplish
|
86
|
+
- **`<hint>`** - Provide additional guidance
|
87
|
+
|
88
|
+
## Common Attributes
|
89
|
+
|
90
|
+
### Global Attributes
|
91
|
+
|
92
|
+
Most components support these attributes:
|
93
|
+
|
94
|
+
- **`inline="true"`** - Enable inline rendering for seamless text flow
|
95
|
+
- **Template variables** - Use `{{variable}}` in any attribute value
|
96
|
+
|
97
|
+
### Chat-Specific Attributes
|
98
|
+
|
99
|
+
Chat components support:
|
100
|
+
|
101
|
+
- **`role="..."`** - Override default role (system, user, assistant)
|
102
|
+
- **`speaker="..."`** - Custom speaker name for conversations
|
103
|
+
|
104
|
+
### Formatting Attributes
|
105
|
+
|
106
|
+
Components support various formatting attributes:
|
107
|
+
|
108
|
+
- **`style="..."`** - Custom styling
|
109
|
+
- **`class="..."`** - CSS class names
|
110
|
+
|
111
|
+
## Component Usage Patterns
|
112
|
+
|
113
|
+
### Basic Structure
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
<poml>
|
117
|
+
<role>Expert in {{domain}}</role>
|
118
|
+
<task>{{primary_objective}}</task>
|
119
|
+
|
120
|
+
<p>Context and instructions...</p>
|
121
|
+
|
122
|
+
<list>
|
123
|
+
<item>First requirement</item>
|
124
|
+
<item>Second requirement</item>
|
125
|
+
</list>
|
126
|
+
|
127
|
+
<hint>Additional guidance</hint>
|
128
|
+
</poml>
|
129
|
+
```
|
130
|
+
|
131
|
+
### Chat Conversation
|
132
|
+
|
133
|
+
```ruby
|
134
|
+
<poml>
|
135
|
+
<system>You are a {{expertise}} expert.</system>
|
136
|
+
|
137
|
+
<human>
|
138
|
+
I need help with {{problem_description}}.
|
139
|
+
|
140
|
+
<p>Specific requirements:</p>
|
141
|
+
<list>
|
142
|
+
<for variable="req" items="{{requirements}}">
|
143
|
+
<item>{{req}}</item>
|
144
|
+
</for>
|
145
|
+
</list>
|
146
|
+
</human>
|
147
|
+
</poml>
|
148
|
+
```
|
149
|
+
|
150
|
+
### Data Analysis
|
151
|
+
|
152
|
+
```ruby
|
153
|
+
<poml>
|
154
|
+
<role>Data Analyst</role>
|
155
|
+
<task>Analyze the provided dataset</task>
|
156
|
+
|
157
|
+
<table src="{{data_file}}" maxRecords="10" />
|
158
|
+
|
159
|
+
<output-schema name="AnalysisResult">
|
160
|
+
{
|
161
|
+
"type": "object",
|
162
|
+
"properties": {
|
163
|
+
"insights": {"type": "array"},
|
164
|
+
"recommendations": {"type": "array"}
|
165
|
+
}
|
166
|
+
}
|
167
|
+
</output-schema>
|
168
|
+
</poml>
|
169
|
+
```
|
170
|
+
|
171
|
+
### Code Review
|
172
|
+
|
173
|
+
```ruby
|
174
|
+
<poml>
|
175
|
+
<role>Senior {{language}} Developer</role>
|
176
|
+
<task>Review code for best practices</task>
|
177
|
+
|
178
|
+
<file src="{{code_file}}" />
|
179
|
+
|
180
|
+
<p>Review focus areas:</p>
|
181
|
+
<list>
|
182
|
+
<item><b>Performance</b> - Algorithm efficiency</item>
|
183
|
+
<item><b>Security</b> - Vulnerability assessment</item>
|
184
|
+
<item><b>Maintainability</b> - Code organization</item>
|
185
|
+
</list>
|
186
|
+
|
187
|
+
<tool-definition name="suggest_improvements">
|
188
|
+
{
|
189
|
+
"description": "Suggest specific code improvements",
|
190
|
+
"parameters": {
|
191
|
+
"type": "object",
|
192
|
+
"properties": {
|
193
|
+
"file_path": {"type": "string"},
|
194
|
+
"line_number": {"type": "integer"},
|
195
|
+
"suggestion": {"type": "string"},
|
196
|
+
"priority": {"type": "string", "enum": ["low", "medium", "high"]}
|
197
|
+
}
|
198
|
+
}
|
199
|
+
}
|
200
|
+
</tool-definition>
|
201
|
+
</poml>
|
202
|
+
```
|
203
|
+
|
204
|
+
## Component Combinations
|
205
|
+
|
206
|
+
### Inline Formatting
|
207
|
+
|
208
|
+
```ruby
|
209
|
+
<p>
|
210
|
+
The <code inline="true">{{method_name}}</code> method should return a
|
211
|
+
<b inline="true">{{return_type}}</b> value, not
|
212
|
+
<s inline="true">{{incorrect_type}}</s>.
|
213
|
+
</p>
|
214
|
+
```
|
215
|
+
|
216
|
+
### Conditional Content
|
217
|
+
|
218
|
+
```ruby
|
219
|
+
<if condition="{{include_examples}}">
|
220
|
+
<p><b>Examples:</b></p>
|
221
|
+
<for variable="example" items="{{examples}}">
|
222
|
+
<p><i>Example {{example.index}}:</i></p>
|
223
|
+
<code>{{example.code}}</code>
|
224
|
+
</for>
|
225
|
+
</if>
|
226
|
+
```
|
227
|
+
|
228
|
+
### Nested Structures
|
229
|
+
|
230
|
+
```ruby
|
231
|
+
<list>
|
232
|
+
<for variable="category" items="{{categories}}">
|
233
|
+
<item>
|
234
|
+
<b>{{category.name}}</b>
|
235
|
+
<list>
|
236
|
+
<for variable="item" items="{{category.items}}">
|
237
|
+
<item>{{item.name}} - {{item.description}}</item>
|
238
|
+
</for>
|
239
|
+
</list>
|
240
|
+
</item>
|
241
|
+
</for>
|
242
|
+
</list>
|
243
|
+
```
|
244
|
+
|
245
|
+
## Advanced Features
|
246
|
+
|
247
|
+
### Template Composition
|
248
|
+
|
249
|
+
```ruby
|
250
|
+
<!-- Base template -->
|
251
|
+
<poml>
|
252
|
+
<role>{{role_type}} Expert</role>
|
253
|
+
<task>{{main_task}}</task>
|
254
|
+
|
255
|
+
<include src="{{template_path}}" />
|
256
|
+
|
257
|
+
<if condition="{{include_footer}}">
|
258
|
+
<include src="templates/footer.poml" />
|
259
|
+
</if>
|
260
|
+
</poml>
|
261
|
+
```
|
262
|
+
|
263
|
+
### Multi-Format Support
|
264
|
+
|
265
|
+
```ruby
|
266
|
+
<!-- Works across all output formats -->
|
267
|
+
<poml>
|
268
|
+
<system>You are a helpful assistant.</system>
|
269
|
+
|
270
|
+
<output-schema name="Response">
|
271
|
+
{
|
272
|
+
"type": "object",
|
273
|
+
"properties": {
|
274
|
+
"answer": {"type": "string"},
|
275
|
+
"confidence": {"type": "number"}
|
276
|
+
}
|
277
|
+
}
|
278
|
+
</output-schema>
|
279
|
+
|
280
|
+
<human>{{user_question}}</human>
|
281
|
+
</poml>
|
282
|
+
```
|
283
|
+
|
284
|
+
### Error Handling
|
285
|
+
|
286
|
+
```ruby
|
287
|
+
<poml>
|
288
|
+
<role>Support Assistant</role>
|
289
|
+
<task>Help resolve the issue</task>
|
290
|
+
|
291
|
+
<if condition="{{error_logs}}">
|
292
|
+
<p><b>Error Analysis:</b></p>
|
293
|
+
<file src="{{error_logs}}" />
|
294
|
+
</if>
|
295
|
+
|
296
|
+
<if condition="!{{error_logs}}">
|
297
|
+
<p>⚠️ No error logs provided. Please share relevant error information.</p>
|
298
|
+
</if>
|
299
|
+
</poml>
|
300
|
+
```
|
301
|
+
|
302
|
+
## Performance Considerations
|
303
|
+
|
304
|
+
### Component Efficiency
|
305
|
+
|
306
|
+
- **Light components**: `<p>`, `<b>`, `<i>`, `<code>` - Very fast
|
307
|
+
- **Medium components**: `<list>`, `<table>`, `<if>`, `<for>` - Moderate processing
|
308
|
+
- **Heavy components**: `<file>`, `<img>`, `<include>` - I/O dependent
|
309
|
+
|
310
|
+
### Optimization Tips
|
311
|
+
|
312
|
+
1. **Use inline rendering** for seamless text flow
|
313
|
+
2. **Limit file operations** with `maxRecords` on tables
|
314
|
+
3. **Cache include templates** for repeated use
|
315
|
+
4. **Validate schemas** before processing for better error handling
|
316
|
+
|
317
|
+
### Memory Usage
|
318
|
+
|
319
|
+
```ruby
|
320
|
+
# Good: Process in chunks for large datasets
|
321
|
+
<table src="large_dataset.csv" maxRecords="100" />
|
322
|
+
|
323
|
+
# Good: Use conditions to avoid unnecessary processing
|
324
|
+
<if condition="{{debug_mode}}">
|
325
|
+
<file src="debug.log" />
|
326
|
+
</if>
|
327
|
+
|
328
|
+
# Good: Limit nested loops
|
329
|
+
<for variable="category" items="{{categories}}">
|
330
|
+
<if condition="{{category.items.length}} <= 10">
|
331
|
+
<for variable="item" items="{{category.items}}">
|
332
|
+
<item>{{item.name}}</item>
|
333
|
+
</for>
|
334
|
+
</if>
|
335
|
+
</for>
|
336
|
+
```
|
337
|
+
|
338
|
+
## Component Reference Quick Links
|
339
|
+
|
340
|
+
### By Use Case
|
341
|
+
|
342
|
+
- **Chat Applications**: [Chat Components](chat-components.md)
|
343
|
+
- **Data Processing**: [Data Components](data-components.md)
|
344
|
+
- **Content Generation**: [Formatting Components](formatting.md)
|
345
|
+
- **AI Integration**: [Schema Components](schema-components.md)
|
346
|
+
- **Dynamic Content**: [Template Engine](../template-engine.md)
|
347
|
+
|
348
|
+
### By Complexity
|
349
|
+
|
350
|
+
- **Beginner**: `<p>`, `<b>`, `<i>`, `<list>`, `<item>`
|
351
|
+
- **Intermediate**: `<if>`, `<for>`, `<table>`, `<img>`, `<system>`, `<human>`
|
352
|
+
- **Advanced**: `<output-schema>`, `<tool-definition>`, `<include>`, `<meta>`
|
353
|
+
|
354
|
+
### By Output Format
|
355
|
+
|
356
|
+
- **All Formats**: Basic formatting, structure, template engine
|
357
|
+
- **Chat Formats**: `<system>`, `<human>`, `<ai>` components
|
358
|
+
- **Schema Formats**: `<output-schema>`, `<tool-definition>` components
|
359
|
+
|
360
|
+
## Next Steps
|
361
|
+
|
362
|
+
1. **Start Simple** - Begin with [Formatting Components](formatting.md)
|
363
|
+
2. **Add Structure** - Learn [Template Engine](../template-engine.md)
|
364
|
+
3. **Enable Chat** - Explore [Chat Components](chat-components.md)
|
365
|
+
4. **Add Intelligence** - Master [Schema Components](schema-components.md)
|
366
|
+
5. **Optimize** - Review [Performance Guide](../advanced/performance.md)
|
@@ -0,0 +1,259 @@
|
|
1
|
+
# Media Components
|
2
|
+
|
3
|
+
This guide covers POML components for handling multimedia content including images and other media types.
|
4
|
+
|
5
|
+
## Image Component
|
6
|
+
|
7
|
+
The `<img>` component displays images in your POML documents with advanced processing capabilities.
|
8
|
+
|
9
|
+
### Basic Usage
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
require 'poml'
|
13
|
+
|
14
|
+
# Local image file
|
15
|
+
markup = <<~POML
|
16
|
+
<poml>
|
17
|
+
<role>Image Analyst</role>
|
18
|
+
<task>Describe the contents of this image</task>
|
19
|
+
<img src="photo.jpg" alt="User photo" />
|
20
|
+
</poml>
|
21
|
+
POML
|
22
|
+
|
23
|
+
result = Poml.process(markup: markup)
|
24
|
+
puts result['content']
|
25
|
+
```
|
26
|
+
|
27
|
+
### URL-based Images
|
28
|
+
|
29
|
+
The Ruby implementation supports fetching images from HTTP(S) URLs:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
markup = <<~POML
|
33
|
+
<poml>
|
34
|
+
<role>Visual Analyst</role>
|
35
|
+
<img src="https://example.com/image.png" alt="Remote image" />
|
36
|
+
</poml>
|
37
|
+
POML
|
38
|
+
|
39
|
+
result = Poml.process(markup: markup)
|
40
|
+
```
|
41
|
+
|
42
|
+
### Advanced Image Processing
|
43
|
+
|
44
|
+
The Ruby implementation uses **libvips** for high-performance image processing:
|
45
|
+
|
46
|
+
#### Image Resizing
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
# Fit within bounds (preserves aspect ratio)
|
50
|
+
markup = <<~POML
|
51
|
+
<poml>
|
52
|
+
<img src="large-photo.jpg"
|
53
|
+
max-width="800"
|
54
|
+
max-height="600"
|
55
|
+
resize="fit" />
|
56
|
+
</poml>
|
57
|
+
POML
|
58
|
+
|
59
|
+
# Fill area (may crop)
|
60
|
+
markup = <<~POML
|
61
|
+
<poml>
|
62
|
+
<img src="photo.jpg"
|
63
|
+
max-width="400"
|
64
|
+
max-height="400"
|
65
|
+
resize="fill" />
|
66
|
+
</poml>
|
67
|
+
POML
|
68
|
+
|
69
|
+
# Stretch to exact dimensions
|
70
|
+
markup = <<~POML
|
71
|
+
<poml>
|
72
|
+
<img src="photo.jpg"
|
73
|
+
max-width="300"
|
74
|
+
max-height="200"
|
75
|
+
resize="stretch" />
|
76
|
+
</poml>
|
77
|
+
POML
|
78
|
+
```
|
79
|
+
|
80
|
+
#### Format Conversion
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
# Convert JPEG to PNG
|
84
|
+
markup = <<~POML
|
85
|
+
<poml>
|
86
|
+
<img src="photo.jpg" type="png" />
|
87
|
+
</poml>
|
88
|
+
POML
|
89
|
+
|
90
|
+
# Convert to WebP for better compression
|
91
|
+
markup = <<~POML
|
92
|
+
<poml>
|
93
|
+
<img src="large-image.png" type="webp" />
|
94
|
+
</poml>
|
95
|
+
POML
|
96
|
+
```
|
97
|
+
|
98
|
+
### Component Attributes
|
99
|
+
|
100
|
+
| Attribute | Type | Description |
|
101
|
+
|-----------|------|-------------|
|
102
|
+
| `src` | String | Path to image file or HTTP(S) URL |
|
103
|
+
| `alt` | String | Alternative text for accessibility |
|
104
|
+
| `base64` | String | Base64 encoded image data (cannot use with `src`) |
|
105
|
+
| `type` | String | Output format: `jpeg`, `png`, `webp`, `tiff`, `gif` |
|
106
|
+
| `max-width` | Integer | Maximum width in pixels |
|
107
|
+
| `max-height` | Integer | Maximum height in pixels |
|
108
|
+
| `resize` | String | Resize mode: `fit`, `fill`, `stretch` |
|
109
|
+
| `position` | String | Position: `top`, `bottom`, `here` (default: `here`) |
|
110
|
+
| `syntax` | String | Output syntax: `multimedia`, `markdown`, etc. |
|
111
|
+
|
112
|
+
### Resize Modes
|
113
|
+
|
114
|
+
- **`fit`**: Resize to fit within bounds while preserving aspect ratio
|
115
|
+
- **`fill`**: Fill the entire area, potentially cropping to maintain aspect ratio
|
116
|
+
- **`stretch`**: Stretch to exact dimensions (may distort aspect ratio)
|
117
|
+
|
118
|
+
### Format Support
|
119
|
+
|
120
|
+
The libvips-powered implementation supports:
|
121
|
+
|
122
|
+
- **Input formats**: JPEG, PNG, GIF, WebP, TIFF, BMP, SVG
|
123
|
+
- **Output formats**: JPEG (with quality control), PNG, WebP, TIFF, GIF
|
124
|
+
- **Automatic format detection** from file headers
|
125
|
+
- **MIME type handling** for web images
|
126
|
+
|
127
|
+
### Base64 Encoding
|
128
|
+
|
129
|
+
All processed images are automatically converted to base64 data URLs:
|
130
|
+
|
131
|
+
```ruby
|
132
|
+
markup = <<~POML
|
133
|
+
<poml>
|
134
|
+
<img src="photo.jpg" />
|
135
|
+
</poml>
|
136
|
+
POML
|
137
|
+
|
138
|
+
result = Poml.process(markup: markup)
|
139
|
+
# Result contains: data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEA...
|
140
|
+
```
|
141
|
+
|
142
|
+
### Error Handling
|
143
|
+
|
144
|
+
The implementation provides graceful error handling:
|
145
|
+
|
146
|
+
```ruby
|
147
|
+
# Missing file
|
148
|
+
markup = '<poml><img src="missing.jpg" alt="Missing image" /></poml>'
|
149
|
+
result = Poml.process(markup: markup)
|
150
|
+
# Returns alt text: "Missing image"
|
151
|
+
|
152
|
+
# Invalid URL
|
153
|
+
markup = '<poml><img src="https://invalid-url.com/image.jpg" /></poml>'
|
154
|
+
result = Poml.process(markup: markup)
|
155
|
+
# Returns error message with graceful fallback
|
156
|
+
```
|
157
|
+
|
158
|
+
### Fallback Behavior
|
159
|
+
|
160
|
+
When libvips is not available, the implementation:
|
161
|
+
|
162
|
+
1. **Falls back** to basic image handling
|
163
|
+
2. **Warns the user** about limited functionality
|
164
|
+
3. **Continues processing** without breaking
|
165
|
+
4. **Returns original image data** when possible
|
166
|
+
|
167
|
+
### Installation Requirements
|
168
|
+
|
169
|
+
For full image processing capabilities:
|
170
|
+
|
171
|
+
```bash
|
172
|
+
# Install libvips system library (macOS)
|
173
|
+
brew install vips
|
174
|
+
|
175
|
+
# Install libvips system library (Ubuntu/Debian)
|
176
|
+
sudo apt-get install libvips-dev
|
177
|
+
|
178
|
+
# Ruby gem is automatically installed with POML
|
179
|
+
gem install poml
|
180
|
+
```
|
181
|
+
|
182
|
+
The ruby-vips gem is automatically included as a dependency.
|
183
|
+
|
184
|
+
### Examples
|
185
|
+
|
186
|
+
#### Simple Image Display
|
187
|
+
|
188
|
+
```ruby
|
189
|
+
markup = <<~POML
|
190
|
+
<poml>
|
191
|
+
<role>Photo Critic</role>
|
192
|
+
<task>Analyze the composition of this photograph</task>
|
193
|
+
<img src="artwork.jpg" alt="Artistic photograph" />
|
194
|
+
<instruction>Focus on lighting, composition, and visual impact</instruction>
|
195
|
+
</poml>
|
196
|
+
POML
|
197
|
+
```
|
198
|
+
|
199
|
+
#### Image Processing Pipeline
|
200
|
+
|
201
|
+
```ruby
|
202
|
+
markup = <<~POML
|
203
|
+
<poml>
|
204
|
+
<role>Image Processor</role>
|
205
|
+
<task>Process and optimize images for web display</task>
|
206
|
+
|
207
|
+
<h2>Original Image</h2>
|
208
|
+
<img src="large-photo.jpg" alt="Original high-resolution photo" />
|
209
|
+
|
210
|
+
<h2>Optimized for Web</h2>
|
211
|
+
<img src="large-photo.jpg"
|
212
|
+
type="webp"
|
213
|
+
max-width="800"
|
214
|
+
resize="fit"
|
215
|
+
alt="Web-optimized version" />
|
216
|
+
</poml>
|
217
|
+
POML
|
218
|
+
```
|
219
|
+
|
220
|
+
#### Multiple Format Output
|
221
|
+
|
222
|
+
```ruby
|
223
|
+
markup = <<~POML
|
224
|
+
<poml>
|
225
|
+
<role>Format Converter</role>
|
226
|
+
|
227
|
+
<h3>JPEG Version</h3>
|
228
|
+
<img src="source.png" type="jpeg" />
|
229
|
+
|
230
|
+
<h3>WebP Version</h3>
|
231
|
+
<img src="source.png" type="webp" />
|
232
|
+
|
233
|
+
<h3>Thumbnail</h3>
|
234
|
+
<img src="source.png" max-width="150" max-height="150" resize="fill" />
|
235
|
+
</poml>
|
236
|
+
POML
|
237
|
+
```
|
238
|
+
|
239
|
+
## Best Practices
|
240
|
+
|
241
|
+
1. **Always provide alt text** for accessibility
|
242
|
+
2. **Use appropriate formats**: WebP for web, PNG for transparency, JPEG for photos
|
243
|
+
3. **Optimize dimensions** before processing when possible
|
244
|
+
4. **Handle errors gracefully** with meaningful alt text
|
245
|
+
5. **Consider performance** when processing many large images
|
246
|
+
|
247
|
+
## Performance Notes
|
248
|
+
|
249
|
+
- **libvips is highly optimized** for image processing
|
250
|
+
- **Streaming processing** minimizes memory usage
|
251
|
+
- **Format conversion** is efficient with quality control
|
252
|
+
- **URL fetching** includes timeout and error handling
|
253
|
+
- **Base64 encoding** is automatic and optimized
|
254
|
+
|
255
|
+
## See Also
|
256
|
+
|
257
|
+
- [Data Components](data-components.md) - For handling other data types
|
258
|
+
- [Template Engine](../template-engine.md) - For dynamic image paths
|
259
|
+
- [Error Handling](../advanced/error-handling.md) - For robust error handling patterns
|