poml 0.0.1
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 +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +239 -0
- data/TUTORIAL.md +987 -0
- data/bin/poml +80 -0
- data/examples/101_explain_character.poml +30 -0
- data/examples/102_render_xml.poml +40 -0
- data/examples/103_word_todos.poml +27 -0
- data/examples/104_financial_analysis.poml +33 -0
- data/examples/105_write_blog_post.poml +48 -0
- data/examples/106_research.poml +36 -0
- data/examples/107_read_report_pdf.poml +4 -0
- data/examples/201_orders_qa.poml +50 -0
- data/examples/202_arc_agi.poml +36 -0
- data/examples/301_generate_poml.poml +46 -0
- data/examples/README.md +50 -0
- data/examples/_generate_expects.py +35 -0
- data/examples/assets/101_jerry_mouse.jpg +0 -0
- data/examples/assets/101_tom_and_jerry.docx +0 -0
- data/examples/assets/101_tom_cat.jpg +0 -0
- data/examples/assets/101_tom_introduction.txt +9 -0
- data/examples/assets/103_prompt_wizard.docx +0 -0
- data/examples/assets/104_chart_normalized_price.png +0 -0
- data/examples/assets/104_chart_price.png +0 -0
- data/examples/assets/104_mag7.xlsx +0 -0
- data/examples/assets/107_usenix_paper.pdf +0 -0
- data/examples/assets/201_order_instructions.json +7 -0
- data/examples/assets/201_orderlines.csv +2 -0
- data/examples/assets/201_orders.csv +3 -0
- data/examples/assets/202_arc_agi_data.json +1 -0
- data/examples/expects/101_explain_character.txt +117 -0
- data/examples/expects/102_render_xml.txt +28 -0
- data/examples/expects/103_word_todos.txt +121 -0
- data/examples/expects/104_financial_analysis.txt +86 -0
- data/examples/expects/105_write_blog_post.txt +41 -0
- data/examples/expects/106_research.txt +29 -0
- data/examples/expects/107_read_report_pdf.txt +151 -0
- data/examples/expects/201_orders_qa.txt +44 -0
- data/examples/expects/202_arc_agi.txt +64 -0
- data/examples/expects/301_generate_poml.txt +153 -0
- data/examples/ruby_expects/101_explain_character.txt +17 -0
- data/examples/ruby_expects/102_render_xml.txt +28 -0
- data/examples/ruby_expects/103_word_todos.txt +14 -0
- data/examples/ruby_expects/104_financial_analysis.txt +0 -0
- data/examples/ruby_expects/105_write_blog_post.txt +57 -0
- data/examples/ruby_expects/106_research.txt +5 -0
- data/examples/ruby_expects/107_read_report_pdf.txt +403 -0
- data/examples/ruby_expects/201_orders_qa.txt +41 -0
- data/examples/ruby_expects/202_arc_agi.txt +17 -0
- data/examples/ruby_expects/301_generate_poml.txt +17 -0
- data/lib/poml/components/base.rb +132 -0
- data/lib/poml/components/content.rb +156 -0
- data/lib/poml/components/data.rb +346 -0
- data/lib/poml/components/examples.rb +55 -0
- data/lib/poml/components/instructions.rb +93 -0
- data/lib/poml/components/layout.rb +50 -0
- data/lib/poml/components/lists.rb +82 -0
- data/lib/poml/components/styling.rb +36 -0
- data/lib/poml/components/text.rb +8 -0
- data/lib/poml/components/workflow.rb +63 -0
- data/lib/poml/components.rb +47 -0
- data/lib/poml/components_new.rb +297 -0
- data/lib/poml/components_old.rb +1096 -0
- data/lib/poml/context.rb +53 -0
- data/lib/poml/parser.rb +153 -0
- data/lib/poml/renderer.rb +147 -0
- data/lib/poml/template_engine.rb +66 -0
- data/lib/poml/version.rb +5 -0
- data/lib/poml.rb +53 -0
- data/media/logo-16-purple.png +0 -0
- data/media/logo-64-white.png +0 -0
- metadata +149 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3e104ca36939275deeacddbc12fd7ad75129a288e15120ee5103928691188a33
|
4
|
+
data.tar.gz: 997315c25a24ec17f3e0281d634fca83cb65535673ab6334a380402783d5a854
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 429e8c22d2f9527a537d312a72975700f84d1dcda381aff1a98fd2842f5520130928780b7cf1c40fc60366180425ae61ac14719560996548ec363e777e619dca
|
7
|
+
data.tar.gz: 776c99377cf172f0edc9cbfa277f83e3d7d1fd47442b64c57c416087a56d4817b50abdfe777e92835a6238a65d292d5e6928cd89bb298e52b522dd3fc5d9a3d4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 Ghennadii Mirosnicenco
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,239 @@
|
|
1
|
+
# POML Ruby Gem
|
2
|
+
|
3
|
+
A Ruby implementation of the POML (Prompt Oriented Markup Language) interpreter.
|
4
|
+
|
5
|
+
## About This Implementation
|
6
|
+
|
7
|
+
This is a **Ruby port** of the original [POML library](https://github.com/microsoft/poml) developed by Microsoft, which was originally implemented in JavaScript/TypeScript and Python. This Ruby gem is designed to be **fully compatible** with the original POML specification and will **closely follow** the development of the original library to maintain feature parity.
|
8
|
+
|
9
|
+
### Original Library Resources
|
10
|
+
|
11
|
+
For comprehensive documentation, tutorials, and examples, please refer to the **original POML library documentation**:
|
12
|
+
|
13
|
+
- 📚 **Main Repository**: <https://github.com/microsoft/poml>
|
14
|
+
- 📖 **Documentation**: Complete language reference and guides
|
15
|
+
- 💡 **Examples**: Extensive collection of POML examples
|
16
|
+
- 🎯 **Use Cases**: Real-world applications and patterns
|
17
|
+
|
18
|
+
The original documentation is an excellent resource for learning POML concepts, syntax, and best practices that apply to this Ruby implementation as well.
|
19
|
+
|
20
|
+
## Installation
|
21
|
+
|
22
|
+
```bash
|
23
|
+
gem install poml
|
24
|
+
```
|
25
|
+
|
26
|
+
Or add to your Gemfile:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
gem 'poml'
|
30
|
+
```
|
31
|
+
|
32
|
+
After installation, check out [TUTORIAL.md](TUTORIAL.md) for comprehensive examples and integration patterns.
|
33
|
+
|
34
|
+
## Usage
|
35
|
+
|
36
|
+
### Ruby API
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
require 'poml'
|
40
|
+
|
41
|
+
# Basic usage
|
42
|
+
result = Poml.process(markup: '<poml><role>Assistant</role><task>Help users</task></poml>')
|
43
|
+
puts result['content']
|
44
|
+
|
45
|
+
# With template variables
|
46
|
+
markup = '<poml><role>{{role_name}}</role><task>{{task_name}}</task></poml>'
|
47
|
+
context = { 'role_name' => 'Data Analyst', 'task_name' => 'Analyze data' }
|
48
|
+
result = Poml.process(markup: markup, context: context)
|
49
|
+
|
50
|
+
# Different output formats
|
51
|
+
result = Poml.process(markup: markup, format: 'openai_chat') # OpenAI chat format
|
52
|
+
result = Poml.process(markup: markup, format: 'raw') # Raw text
|
53
|
+
result = Poml.process(markup: markup, format: 'dict') # Dictionary (default)
|
54
|
+
|
55
|
+
# With custom stylesheet
|
56
|
+
stylesheet = { 'role' => { 'captionStyle' => 'bold' } }
|
57
|
+
result = Poml.process(markup: markup, stylesheet: stylesheet)
|
58
|
+
|
59
|
+
# Disable chat mode for single prompts
|
60
|
+
result = Poml.process(markup: markup, chat: false)
|
61
|
+
```
|
62
|
+
|
63
|
+
📖 **For comprehensive examples and advanced usage patterns, see [TUTORIAL.md](TUTORIAL.md)**
|
64
|
+
|
65
|
+
#### Quick Reference - Common Patterns
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
# OpenAI API integration
|
69
|
+
messages = Poml.process(markup: prompt_template, context: vars, format: 'openai_chat')
|
70
|
+
response = openai_client.chat.completions.create(model: 'gpt-4', messages: messages)
|
71
|
+
|
72
|
+
# Rails service integration
|
73
|
+
class PromptService
|
74
|
+
def self.generate(template_name, context = {})
|
75
|
+
markup = File.read("app/prompts/#{template_name}.poml")
|
76
|
+
Poml.process(markup: markup, context: context, format: 'raw')
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Error handling
|
81
|
+
begin
|
82
|
+
result = Poml.process(markup: user_input)
|
83
|
+
rescue Poml::Error => e
|
84
|
+
puts "POML Error: #{e.message}"
|
85
|
+
end
|
86
|
+
```
|
87
|
+
|
88
|
+
### Command Line Interface
|
89
|
+
|
90
|
+
```bash
|
91
|
+
# Process a POML file
|
92
|
+
poml examples/101_explain_character.poml
|
93
|
+
|
94
|
+
# Process markup directly
|
95
|
+
poml "<poml><role>Test</role><task>Say hello</task></poml>" --format raw
|
96
|
+
|
97
|
+
# With context variables
|
98
|
+
poml markup.poml --context '{"name": "John", "role": "developer"}'
|
99
|
+
|
100
|
+
# Different output formats
|
101
|
+
poml markup.poml --format openai_chat
|
102
|
+
poml markup.poml --format raw
|
103
|
+
```
|
104
|
+
|
105
|
+
### CLI Options
|
106
|
+
|
107
|
+
- `-f, --format FORMAT`: Output format (raw, dict, openai_chat, langchain, pydantic)
|
108
|
+
- `raw`: Plain text output with message boundaries (like `===== system =====`)
|
109
|
+
- `dict`: JSON object with content and metadata
|
110
|
+
- `openai_chat`: Array of messages in OpenAI Chat Completion API format
|
111
|
+
- `langchain`: Object with both messages array and raw content
|
112
|
+
- `pydantic`: Simplified object structure with prompt, variables, and settings
|
113
|
+
- `-c, --context JSON`: Context variables as JSON
|
114
|
+
- `--no-chat`: Disable chat mode
|
115
|
+
- `-s, --stylesheet JSON`: Stylesheet as JSON
|
116
|
+
- `-o, --output FILE`: Output to file
|
117
|
+
- `-h, --help`: Show help
|
118
|
+
- `-v, --version`: Show version
|
119
|
+
|
120
|
+
> **Note**: While this Ruby implementation aims for compatibility with the original POML library, the output format structures may differ slightly from the original TypeScript/Python implementations. The format names are kept consistent for API compatibility, but the Ruby gem provides its own implementation of each format suitable for Ruby applications.
|
121
|
+
|
122
|
+
## POML Components
|
123
|
+
|
124
|
+
### Basic Components
|
125
|
+
|
126
|
+
- `<role>`: Define the AI's role
|
127
|
+
- `<task>`: Define the task to perform
|
128
|
+
- `<hint>`: Provide hints or additional information
|
129
|
+
- `<p>`: Paragraph text
|
130
|
+
|
131
|
+
### Content Components
|
132
|
+
|
133
|
+
- `<Document src="file.txt">`: Include external documents (.txt, .docx, .pdf)
|
134
|
+
- `<img src="image.jpg" alt="description">`: Include images
|
135
|
+
- `<Table src="data.csv">`: Include tabular data
|
136
|
+
|
137
|
+
### Layout Components
|
138
|
+
|
139
|
+
- `<cp caption="Section Title">`: Captioned paragraph/section
|
140
|
+
- `<list>` with `<item>`: Create lists
|
141
|
+
- `<example>` with `<input>` and `<output>`: Define examples
|
142
|
+
|
143
|
+
### Template Variables
|
144
|
+
|
145
|
+
Use `{{variable}}` syntax for template substitution:
|
146
|
+
|
147
|
+
```xml
|
148
|
+
<poml>
|
149
|
+
<role>{{user_role}}</role>
|
150
|
+
<task>Process {{count}} items</task>
|
151
|
+
</poml>
|
152
|
+
```
|
153
|
+
|
154
|
+
### XML Syntax Mode
|
155
|
+
|
156
|
+
Enable XML output mode:
|
157
|
+
|
158
|
+
```xml
|
159
|
+
<poml syntax="xml">
|
160
|
+
<role>Consultant</role>
|
161
|
+
<cp caption="Requirements">
|
162
|
+
<list>
|
163
|
+
<item>Requirement 1</item>
|
164
|
+
<item>Requirement 2</item>
|
165
|
+
</list>
|
166
|
+
</cp>
|
167
|
+
</poml>
|
168
|
+
```
|
169
|
+
|
170
|
+
### Stylesheets
|
171
|
+
|
172
|
+
Customize component appearance:
|
173
|
+
|
174
|
+
```xml
|
175
|
+
<poml>
|
176
|
+
<stylesheet>
|
177
|
+
{
|
178
|
+
"role": {
|
179
|
+
"captionStyle": "bold",
|
180
|
+
"caption": "System Role"
|
181
|
+
}
|
182
|
+
}
|
183
|
+
</stylesheet>
|
184
|
+
<role>Assistant</role>
|
185
|
+
</poml>
|
186
|
+
```
|
187
|
+
|
188
|
+
## Features
|
189
|
+
|
190
|
+
- ✅ Full POML component support
|
191
|
+
- ✅ Template variable substitution
|
192
|
+
- ✅ Multiple output formats (raw, dict, OpenAI chat, etc.)
|
193
|
+
- ✅ Document inclusion (.txt, .docx, .pdf)
|
194
|
+
- ✅ Image handling
|
195
|
+
- ✅ Table data processing
|
196
|
+
- ✅ XML syntax mode
|
197
|
+
- ✅ Stylesheet support
|
198
|
+
- ✅ Command-line interface
|
199
|
+
- ✅ Chat vs non-chat modes
|
200
|
+
|
201
|
+
## Document Support
|
202
|
+
|
203
|
+
The gem supports including external documents:
|
204
|
+
|
205
|
+
- **Text files** (.txt): Direct inclusion
|
206
|
+
- **Word documents** (.docx): Text extraction using system tools or zip parsing
|
207
|
+
- **PDF files** (.pdf): Text extraction using `pdftotext` (when available)
|
208
|
+
|
209
|
+
## Development
|
210
|
+
|
211
|
+
```bash
|
212
|
+
git clone https://github.com/GhennadiiMir/poml.git
|
213
|
+
cd poml
|
214
|
+
bundle install
|
215
|
+
```
|
216
|
+
|
217
|
+
Run tests:
|
218
|
+
|
219
|
+
```bash
|
220
|
+
# Run all tests
|
221
|
+
bundle exec ruby test/run_all_tests.rb
|
222
|
+
|
223
|
+
# Run main test suite
|
224
|
+
bundle exec ruby -I lib test/test_poml.rb
|
225
|
+
|
226
|
+
# Run tutorial examples tests
|
227
|
+
bundle exec ruby -I lib test/test_tutorial_examples.rb
|
228
|
+
```
|
229
|
+
|
230
|
+
Build and install locally:
|
231
|
+
|
232
|
+
```bash
|
233
|
+
gem build poml.gemspec
|
234
|
+
gem install poml-0.0.1.gem
|
235
|
+
```
|
236
|
+
|
237
|
+
## License
|
238
|
+
|
239
|
+
The gem is available as open source under the terms of the [MIT License](LICENSE.txt).
|