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.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/docs/tutorial/advanced/performance.md +695 -0
  3. data/docs/tutorial/advanced/tool-registration.md +776 -0
  4. data/docs/tutorial/basic-usage.md +351 -0
  5. data/docs/tutorial/components/chat-components.md +552 -0
  6. data/docs/tutorial/components/formatting.md +623 -0
  7. data/docs/tutorial/components/index.md +366 -0
  8. data/docs/tutorial/components/media-components.md +259 -0
  9. data/docs/tutorial/components/schema-components.md +668 -0
  10. data/docs/tutorial/index.md +184 -0
  11. data/docs/tutorial/output-formats.md +688 -0
  12. data/docs/tutorial/quickstart.md +30 -0
  13. data/docs/tutorial/template-engine.md +540 -0
  14. data/lib/poml/components/base.rb +146 -4
  15. data/lib/poml/components/content.rb +10 -3
  16. data/lib/poml/components/data.rb +539 -19
  17. data/lib/poml/components/examples.rb +235 -1
  18. data/lib/poml/components/formatting.rb +184 -18
  19. data/lib/poml/components/layout.rb +7 -2
  20. data/lib/poml/components/lists.rb +69 -35
  21. data/lib/poml/components/meta.rb +134 -5
  22. data/lib/poml/components/output_schema.rb +19 -1
  23. data/lib/poml/components/template.rb +72 -61
  24. data/lib/poml/components/text.rb +30 -1
  25. data/lib/poml/components/tool.rb +81 -0
  26. data/lib/poml/components/tool_definition.rb +339 -10
  27. data/lib/poml/components/tools.rb +14 -0
  28. data/lib/poml/components/utilities.rb +34 -18
  29. data/lib/poml/components.rb +19 -0
  30. data/lib/poml/context.rb +19 -4
  31. data/lib/poml/parser.rb +88 -63
  32. data/lib/poml/renderer.rb +191 -9
  33. data/lib/poml/template_engine.rb +138 -13
  34. data/lib/poml/version.rb +1 -1
  35. data/lib/poml.rb +16 -1
  36. data/readme.md +154 -27
  37. metadata +31 -4
  38. data/TUTORIAL.md +0 -987
@@ -0,0 +1,184 @@
1
+ # POML Ruby Gem - Tutorial
2
+
3
+ Welcome to the comprehensive tutorial for the POML (Prompt Oriented Markup Language) Ruby gem. This tutorial will guide you through all features and capabilities of POML for creating structured AI prompts.
4
+
5
+ ## What is POML?
6
+
7
+ POML is a markup language designed for creating structured, reusable AI prompts. It provides components for organizing content, managing templates, handling data, and integrating with various AI services.
8
+
9
+ ## Key Concepts for Ruby Implementation
10
+
11
+ ### Output Formats and Rendering
12
+
13
+ The Ruby POML gem uses a **format-aware rendering system**:
14
+
15
+ - **Default rendering**: Produces Markdown-like output optimized for readability
16
+ - **HTML components**: Use `<output format="html"/>` for HTML output (`<h1>`, `<b>`, `<i>` tags)
17
+ - **JSON/XML formats**: Use `<output format="json"/>` or `<output format="xml"/>` for structured data
18
+ - **Text format**: Use `<output format="text"/>` for plain text output
19
+
20
+ **Example - Getting HTML Output:**
21
+
22
+ ```ruby
23
+ markup = <<~POML
24
+ <poml>
25
+ <role>Documentation Writer</role>
26
+ <h1>Main Title</h1>
27
+ <p>Content with <b>bold</b> and <i>italic</i> text.</p>
28
+ <output format="html"/>
29
+ </poml>
30
+ POML
31
+
32
+ result = Poml.process(markup: markup)
33
+ puts result['output'] # Contains HTML: <h1>Main Title</h1><p>Content with <b>bold</b>...
34
+ ```
35
+
36
+ ### Component Behavior
37
+
38
+ - **Headers**: `<h1>Title</h1>` produces `# Title` by default, `<h1>Title</h1>` with HTML format
39
+ - **Formatting**: `<b>bold</b>` produces `**bold**` by default, `<b>bold</b>` with HTML format
40
+ - **Structure**: Most components adapt their output based on the specified format
41
+
42
+ ## Quick Start
43
+
44
+ ```ruby
45
+ require 'poml'
46
+
47
+ # Simple example
48
+ markup = <<~POML
49
+ <poml>
50
+ <role>Code Reviewer</role>
51
+ <task>Review the following Ruby code for best practices</task>
52
+ <hint>Focus on performance and readability</hint>
53
+ </poml>
54
+ POML
55
+
56
+ result = Poml.process(markup: markup)
57
+ puts result['content']
58
+ ```
59
+
60
+ ## Tutorial Structure
61
+
62
+ ### Core Concepts
63
+
64
+ - **[Basic Usage](basic-usage.md)** - Fundamental POML concepts and syntax
65
+ - **[Output Formats](output-formats.md)** - All supported output formats with examples
66
+ - **[Template Engine](template-engine.md)** - Variables, conditionals, and loops
67
+
68
+ ### Components Reference
69
+
70
+ - **[Components Overview](components/index.md)** - All available POML components
71
+ - **[Chat Components](components/chat-components.md)** - AI, human, and system message components
72
+ - **[Formatting Components](components/formatting.md)** - Text formatting and structure
73
+ - **[Data Components](components/data-components.md)** - Tables, objects, and file handling
74
+ - **[Media Components](components/media-components.md)** - Images and multimedia
75
+ - **[Schema Components](components/schema-components.md)** - Output schemas and tool definitions
76
+ - **[Utility Components](components/utility-components.md)** - Conversations, trees, and folders
77
+
78
+ ### Advanced Features
79
+
80
+ - **[Tool Registration](advanced/tool-registration.md)** - Enhanced tool registration system
81
+ - **[Inline Rendering](advanced/inline-rendering.md)** - Seamless text flow with inline components
82
+ - **[Error Handling](advanced/error-handling.md)** - Robust error handling patterns
83
+ - **[Performance](advanced/performance.md)** - Caching and optimization strategies
84
+
85
+ ### Integration Guides
86
+
87
+ - **[Rails Integration](integration/rails.md)** - Using POML in Rails applications
88
+ - **[Sinatra Integration](integration/sinatra.md)** - Building APIs with POML
89
+ - **[Background Jobs](integration/background-jobs.md)** - Async processing patterns
90
+
91
+ ### Complete Examples
92
+
93
+ - **[Code Review System](examples/code-review.md)** - Complete code review workflow
94
+ - **[API Documentation](examples/documentation.md)** - Automated documentation generation
95
+ - **[Content Generation](examples/content-generation.md)** - Dynamic content creation
96
+
97
+ ## Key Features
98
+
99
+ - **🎯 Multiple Output Formats**: Raw text, OpenAI Chat, LangChain, Pydantic, and more
100
+ - **📝 Template Engine**: Variables, conditionals, loops, and meta variables
101
+
102
+ ## XML Mode and Component Rendering
103
+
104
+ ### Dual Rendering Architecture
105
+
106
+ The Ruby POML implementation supports **dual rendering modes** that automatically adapt based on context:
107
+
108
+ #### Standard Mode (Default)
109
+
110
+ Components render to Markdown-like syntax for readability:
111
+
112
+ - `<code>example</code>` → `` `example` ``
113
+ - `<b>bold</b>` → `**bold**`
114
+ - `<i>italic</i>` → `*italic*`
115
+
116
+ #### XML Mode (with `syntax="xml"`)
117
+
118
+ Components preserve XML structure with attributes:
119
+
120
+ - `<code inline="true">example</code>` → `<code inline="true">example</code>`
121
+ - `<b>bold text</b>` → `<b>bold text</b>`
122
+ - `<list style="decimal">...` → `<list style="decimal">...`
123
+
124
+ ### Important XML Parsing Details
125
+
126
+ **Component Disambiguation**: The parser uses precise boundary detection to distinguish between similar component names:
127
+
128
+ - `<code>` tags are handled separately from `<code-block>` tags
129
+ - Regex patterns use negative lookahead (`(?!-)`) to prevent false matches
130
+ - This ensures proper XML parsing when multiple component types are present
131
+
132
+ **Attribute Preservation**: When `syntax="xml"` is specified, component attributes are maintained in the output, enabling rich structured content while preserving XML compatibility.
133
+
134
+ ### Example: Context-Aware Rendering
135
+
136
+ ```ruby
137
+ # Standard mode
138
+ markup1 = '<poml><code>example</code></poml>'
139
+ result1 = Poml.process(markup: markup1)
140
+ # Output: `example`
141
+
142
+ # XML mode
143
+ markup2 = '<poml syntax="xml"><code inline="true">example</code></poml>'
144
+ result2 = Poml.process(markup: markup2)
145
+ # Output: <code inline="true">example</code>
146
+ ```
147
+
148
+ ## Getting Started
149
+
150
+ - **🔧 Tool Registration**: Enhanced tool definition with parameter conversion
151
+ - **📊 Data Components**: Tables, objects, files, and structured data
152
+ - **🖼️ Media Support**: Images with URL fetching and base64 encoding
153
+ - **💬 Chat Components**: Specialized AI conversation components
154
+ - **🎨 Inline Rendering**: Seamless text flow with component integration
155
+ - **⚡ Performance**: Caching, optimization, and error handling
156
+
157
+ ## Installation
158
+
159
+ Add to your Gemfile:
160
+
161
+ ```ruby
162
+ gem 'poml'
163
+ ```
164
+
165
+ Or install directly:
166
+
167
+ ```bash
168
+ gem install poml
169
+ ```
170
+
171
+ ## Version Compatibility
172
+
173
+ - **Ruby**: >= 2.7.0
174
+ - **Current Version**: 0.0.7
175
+ - **Test Coverage**: 399 tests, 2812 assertions, **100% pass rate** (0 failures, 0 errors, 0 skips)
176
+
177
+ ## Next Steps
178
+
179
+ 1. Start with [Basic Usage](basic-usage.md) to learn core concepts
180
+ 2. Explore [Components](components/index.md) for detailed component reference
181
+ 3. Check [Integration Guides](integration/rails.md) for your specific use case
182
+ 4. Review [Examples](examples/code-review.md) for real-world implementations
183
+
184
+ Happy prompting! 🚀