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,351 @@
|
|
1
|
+
# Basic Usage
|
2
|
+
|
3
|
+
This guide covers the fundamental concepts and syntax of POML for creating structured AI prompts.
|
4
|
+
|
5
|
+
## Core Concepts
|
6
|
+
|
7
|
+
### POML Structure
|
8
|
+
|
9
|
+
Every POML document is wrapped in a `<poml>` tag and contains components that define the prompt structure:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
require 'poml'
|
13
|
+
|
14
|
+
markup = <<~POML
|
15
|
+
<poml>
|
16
|
+
<role>Assistant</role>
|
17
|
+
<task>Help users with questions</task>
|
18
|
+
</poml>
|
19
|
+
POML
|
20
|
+
|
21
|
+
result = Poml.process(markup: markup)
|
22
|
+
puts result['content']
|
23
|
+
```
|
24
|
+
|
25
|
+
### Basic Components
|
26
|
+
|
27
|
+
#### Role Component
|
28
|
+
|
29
|
+
Defines the AI's role and expertise:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
markup = <<~POML
|
33
|
+
<poml>
|
34
|
+
<role>Expert Ruby Developer</role>
|
35
|
+
<task>Review code for best practices</task>
|
36
|
+
</poml>
|
37
|
+
POML
|
38
|
+
```
|
39
|
+
|
40
|
+
#### Task Component
|
41
|
+
|
42
|
+
Specifies what the AI should accomplish:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
markup = <<~POML
|
46
|
+
<poml>
|
47
|
+
<role>Technical Writer</role>
|
48
|
+
<task>Create API documentation for the user management endpoints</task>
|
49
|
+
</poml>
|
50
|
+
POML
|
51
|
+
```
|
52
|
+
|
53
|
+
#### Hint Component
|
54
|
+
|
55
|
+
Provides additional guidance:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
markup = <<~POML
|
59
|
+
<poml>
|
60
|
+
<role>Code Reviewer</role>
|
61
|
+
<task>Analyze the following Ruby code</task>
|
62
|
+
<hint>Focus on performance, security, and maintainability</hint>
|
63
|
+
</poml>
|
64
|
+
POML
|
65
|
+
```
|
66
|
+
|
67
|
+
### Text Structure
|
68
|
+
|
69
|
+
#### Paragraphs
|
70
|
+
|
71
|
+
Use `<p>` tags for structured text content:
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
markup = <<~POML
|
75
|
+
<poml>
|
76
|
+
<role>Product Manager</role>
|
77
|
+
<task>Create a feature specification</task>
|
78
|
+
|
79
|
+
<p>The new user authentication system should include:</p>
|
80
|
+
<p>Please provide detailed requirements and acceptance criteria.</p>
|
81
|
+
</poml>
|
82
|
+
POML
|
83
|
+
```
|
84
|
+
|
85
|
+
#### Lists
|
86
|
+
|
87
|
+
Create structured lists with `<list>` and `<item>`:
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
markup = <<~POML
|
91
|
+
<poml>
|
92
|
+
<role>Software Architect</role>
|
93
|
+
<task>Design system architecture</task>
|
94
|
+
|
95
|
+
<p>Consider these requirements:</p>
|
96
|
+
<list>
|
97
|
+
<item>Scalability for 10,000+ concurrent users</item>
|
98
|
+
<item>High availability with 99.9% uptime</item>
|
99
|
+
<item>Security compliance (SOC 2, GDPR)</item>
|
100
|
+
<item>Cost optimization for cloud deployment</item>
|
101
|
+
</list>
|
102
|
+
</poml>
|
103
|
+
POML
|
104
|
+
```
|
105
|
+
|
106
|
+
### Text Formatting
|
107
|
+
|
108
|
+
POML supports various text formatting components:
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
markup = <<~POML
|
112
|
+
<poml>
|
113
|
+
<role>Technical Writer</role>
|
114
|
+
<task>Document the API endpoint</task>
|
115
|
+
|
116
|
+
<p>The <b>POST /users</b> endpoint creates a new user account.</p>
|
117
|
+
<p>Required fields: <code>email</code>, <code>password</code>, and <code>name</code>.</p>
|
118
|
+
<p><i>Note</i>: Password must be at least 8 characters.</p>
|
119
|
+
<p><u>Important</u>: Email must be unique in the system.</p>
|
120
|
+
</poml>
|
121
|
+
POML
|
122
|
+
```
|
123
|
+
|
124
|
+
Available formatting components:
|
125
|
+
|
126
|
+
- `<b>text</b>` - **Bold text**
|
127
|
+
- `<i>text</i>` - *Italic text*
|
128
|
+
- `<u>text</u>` - **Underlined text**
|
129
|
+
- `<s>text</s>` - ~~Strikethrough text~~
|
130
|
+
- `<code>text</code>` - `Inline code`
|
131
|
+
- `<h1>` to `<h6>` - Headers
|
132
|
+
- `<br>` - Line breaks
|
133
|
+
|
134
|
+
### Processing POML
|
135
|
+
|
136
|
+
#### Basic Processing
|
137
|
+
|
138
|
+
```ruby
|
139
|
+
require 'poml'
|
140
|
+
|
141
|
+
# From string
|
142
|
+
markup = '<poml><role>Assistant</role><task>Help users</task></poml>'
|
143
|
+
result = Poml.process(markup: markup)
|
144
|
+
|
145
|
+
puts result['content'] # The formatted prompt
|
146
|
+
puts result['metadata'] # Additional metadata
|
147
|
+
```
|
148
|
+
|
149
|
+
#### From File
|
150
|
+
|
151
|
+
```ruby
|
152
|
+
# From file
|
153
|
+
result = Poml.process(markup: 'path/to/prompt.poml')
|
154
|
+
```
|
155
|
+
|
156
|
+
#### With Context
|
157
|
+
|
158
|
+
```ruby
|
159
|
+
# With variables
|
160
|
+
markup = <<~POML
|
161
|
+
<poml>
|
162
|
+
<role>{{expert_type}} Expert</role>
|
163
|
+
<task>{{main_task}}</task>
|
164
|
+
</poml>
|
165
|
+
POML
|
166
|
+
|
167
|
+
context = {
|
168
|
+
'expert_type' => 'Database',
|
169
|
+
'main_task' => 'Optimize query performance'
|
170
|
+
}
|
171
|
+
|
172
|
+
result = Poml.process(markup: markup, context: context)
|
173
|
+
```
|
174
|
+
|
175
|
+
### Output Structure
|
176
|
+
|
177
|
+
The default output is a Hash with:
|
178
|
+
|
179
|
+
```ruby
|
180
|
+
result = Poml.process(markup: markup)
|
181
|
+
|
182
|
+
# Available keys:
|
183
|
+
result['content'] # The formatted prompt text
|
184
|
+
result['metadata'] # Hash with additional information
|
185
|
+
result['variables'] # Template variables used
|
186
|
+
result['schemas'] # Any output schemas defined
|
187
|
+
result['tools'] # Any tools registered
|
188
|
+
```
|
189
|
+
|
190
|
+
### Metadata
|
191
|
+
|
192
|
+
Every POML document includes metadata:
|
193
|
+
|
194
|
+
```ruby
|
195
|
+
result = Poml.process(markup: markup)
|
196
|
+
metadata = result['metadata']
|
197
|
+
|
198
|
+
puts metadata['chat'] # true/false - whether chat mode is enabled
|
199
|
+
puts metadata['variables'] # Hash of template variables
|
200
|
+
puts metadata['schemas'] # Array of output schemas
|
201
|
+
puts result['tools'] # Array of tool definitions (top-level)
|
202
|
+
```
|
203
|
+
|
204
|
+
### Error Handling
|
205
|
+
|
206
|
+
POML provides graceful error handling:
|
207
|
+
|
208
|
+
```ruby
|
209
|
+
begin
|
210
|
+
result = Poml.process(markup: invalid_markup)
|
211
|
+
rescue Poml::Error => e
|
212
|
+
puts "POML Error: #{e.message}"
|
213
|
+
rescue StandardError => e
|
214
|
+
puts "System Error: #{e.message}"
|
215
|
+
end
|
216
|
+
```
|
217
|
+
|
218
|
+
## Best Practices
|
219
|
+
|
220
|
+
### 1. Use Descriptive Roles
|
221
|
+
|
222
|
+
```ruby
|
223
|
+
# Good
|
224
|
+
<role>Senior Ruby Developer with 10+ years experience</role>
|
225
|
+
|
226
|
+
# Better
|
227
|
+
<role>Senior Ruby Developer specializing in Rails performance optimization</role>
|
228
|
+
```
|
229
|
+
|
230
|
+
### 2. Be Specific in Tasks
|
231
|
+
|
232
|
+
```ruby
|
233
|
+
# Good
|
234
|
+
<task>Review code</task>
|
235
|
+
|
236
|
+
# Better
|
237
|
+
<task>Review the authentication module for security vulnerabilities and performance issues</task>
|
238
|
+
```
|
239
|
+
|
240
|
+
### 3. Structure Content Logically
|
241
|
+
|
242
|
+
```ruby
|
243
|
+
markup = <<~POML
|
244
|
+
<poml>
|
245
|
+
<role>System Analyst</role>
|
246
|
+
<task>Analyze the proposed system architecture</task>
|
247
|
+
|
248
|
+
<p>Architecture Overview:</p>
|
249
|
+
<!-- Main content here -->
|
250
|
+
|
251
|
+
<p>Specific Analysis Areas:</p>
|
252
|
+
<list>
|
253
|
+
<item>Performance characteristics</item>
|
254
|
+
<item>Security considerations</item>
|
255
|
+
<item>Scalability potential</item>
|
256
|
+
</list>
|
257
|
+
|
258
|
+
<hint>Provide concrete recommendations with implementation steps</hint>
|
259
|
+
</poml>
|
260
|
+
POML
|
261
|
+
```
|
262
|
+
|
263
|
+
### 4. Use Comments for Documentation
|
264
|
+
|
265
|
+
```ruby
|
266
|
+
markup = <<~POML
|
267
|
+
<poml>
|
268
|
+
<!-- This prompt is used for code review automation -->
|
269
|
+
<role>Senior Developer</role>
|
270
|
+
<task>Review pull request changes</task>
|
271
|
+
|
272
|
+
<!-- Context will be provided by the CI system -->
|
273
|
+
<p>Changes to review: {{changes_summary}}</p>
|
274
|
+
</poml>
|
275
|
+
POML
|
276
|
+
```
|
277
|
+
|
278
|
+
## Next Steps
|
279
|
+
|
280
|
+
- Learn about [Output Formats](output-formats.md) for different integration scenarios
|
281
|
+
- Explore [Template Engine](template-engine.md) for dynamic content generation
|
282
|
+
- Check [Components Reference](components/index.md) for all available components
|
283
|
+
|
284
|
+
## Common Patterns
|
285
|
+
|
286
|
+
### API Documentation
|
287
|
+
|
288
|
+
```ruby
|
289
|
+
markup = <<~POML
|
290
|
+
<poml>
|
291
|
+
<role>API Documentation Specialist</role>
|
292
|
+
<task>Create comprehensive documentation for the {{endpoint_name}} endpoint</task>
|
293
|
+
|
294
|
+
<p>Include the following sections:</p>
|
295
|
+
<list>
|
296
|
+
<item>Endpoint description and purpose</item>
|
297
|
+
<item>Request parameters and validation rules</item>
|
298
|
+
<item>Response format and status codes</item>
|
299
|
+
<item>Example requests and responses</item>
|
300
|
+
<item>Error handling scenarios</item>
|
301
|
+
</list>
|
302
|
+
|
303
|
+
<hint>Use clear examples and focus on developer experience</hint>
|
304
|
+
</poml>
|
305
|
+
POML
|
306
|
+
```
|
307
|
+
|
308
|
+
### Code Review
|
309
|
+
|
310
|
+
```ruby
|
311
|
+
markup = <<~POML
|
312
|
+
<poml>
|
313
|
+
<role>Senior {{language}} Developer</role>
|
314
|
+
<task>Perform thorough code review</task>
|
315
|
+
|
316
|
+
<p>Review Focus Areas:</p>
|
317
|
+
<list>
|
318
|
+
<item><b>Code Quality</b>: Readability, maintainability, and style</item>
|
319
|
+
<item><b>Performance</b>: Efficiency and optimization opportunities</item>
|
320
|
+
<item><b>Security</b>: Vulnerability assessment and best practices</item>
|
321
|
+
<item><b>Testing</b>: Test coverage and quality</item>
|
322
|
+
</list>
|
323
|
+
|
324
|
+
<hint>Provide specific, actionable feedback with examples</hint>
|
325
|
+
</poml>
|
326
|
+
POML
|
327
|
+
```
|
328
|
+
|
329
|
+
### Content Generation
|
330
|
+
|
331
|
+
```ruby
|
332
|
+
markup = <<~POML
|
333
|
+
<poml>
|
334
|
+
<role>{{content_type}} Writer</role>
|
335
|
+
<task>Create engaging {{content_type}} about {{topic}}</task>
|
336
|
+
|
337
|
+
<p>Target Audience: {{audience}}</p>
|
338
|
+
<p>Tone: {{tone}}</p>
|
339
|
+
<p>Length: Approximately {{word_count}} words</p>
|
340
|
+
|
341
|
+
<p>Key Points to Cover:</p>
|
342
|
+
<list>
|
343
|
+
{{#key_points}}
|
344
|
+
<item>{{.}}</item>
|
345
|
+
{{/key_points}}
|
346
|
+
</list>
|
347
|
+
|
348
|
+
<hint>Make it engaging, informative, and actionable</hint>
|
349
|
+
</poml>
|
350
|
+
POML
|
351
|
+
```
|