poml 0.0.6 → 0.0.8

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