rails_prompts 0.0.1 → 0.0.2
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/CHANGELOG.md +34 -0
- data/LICENSE.txt +21 -0
- data/README.md +227 -0
- data/lib/rails_prompts/version.rb +1 -1
- metadata +4 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f5b6672970bddc5af0f1f9fcdd741c3327b3caaefdc3fa5cda9b0bcea2ec2a4b
|
|
4
|
+
data.tar.gz: 16bd1ab2baf4d1cd00bee0b84d0fb10bd8621e540165b6fee148831863d3d091
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e30dffe4b3b4524dd9754bb095c8ca0540615ba939918102b449f2185ba411cd6444c732265021ad18af392bb709e7197023b5a8a5bf9def6b5e2781844ba1cc
|
|
7
|
+
data.tar.gz: 37e0c5fd86cdb5de025440ce41f2f096f1e06469df93aae4b00ed029d8755a24ebb3fce1bf75d5296bf19a84b1c3a1b4bf6754c3bf94dfae704d2a45826c97bb
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.0.2] - 2025-12-15
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Complete README documentation with usage examples
|
|
12
|
+
- CHANGELOG.md for version tracking
|
|
13
|
+
- LICENSE.txt (MIT License)
|
|
14
|
+
|
|
15
|
+
## [0.0.1] - 2025-12-15
|
|
16
|
+
|
|
17
|
+
### Added
|
|
18
|
+
- Initial release of Rails Prompts gem
|
|
19
|
+
- Core functionality for rendering AI prompts from ERB templates
|
|
20
|
+
- Support for markdown files with `.md.erb` extension
|
|
21
|
+
- `render_prompt` method to render templates with variable interpolation
|
|
22
|
+
- `available_prompts` method to list all available prompt templates
|
|
23
|
+
- Configurable prompts directory (defaults to `app/prompts`)
|
|
24
|
+
- Clean variable binding using anonymous Structs for template isolation
|
|
25
|
+
- Comprehensive documentation and usage examples
|
|
26
|
+
|
|
27
|
+
### Features
|
|
28
|
+
- ERB template support with trim mode
|
|
29
|
+
- Rails integration with automatic directory detection
|
|
30
|
+
- Flexible variable interpolation in prompt templates
|
|
31
|
+
- Error handling for missing templates
|
|
32
|
+
- Support for Ruby >= 2.7.0 and Rails >= 6.0
|
|
33
|
+
|
|
34
|
+
[0.0.1]: https://github.com/riteshchaudhary/rails_prompts/releases/tag/v0.0.1
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Ritesh Chaudhary
|
|
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,227 @@
|
|
|
1
|
+
# Rails Prompts
|
|
2
|
+
|
|
3
|
+
A Ruby gem for managing AI prompts in Rails applications using ERB templates stored in markdown files. Centralize your prompts, make them easier to review, version control, and modify.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'rails_prompts'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
bundle install
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
gem install rails_prompts
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
### 1. Create Your Prompts Directory
|
|
28
|
+
|
|
29
|
+
By default, Rails Prompts looks for prompt templates in `app/prompts/`. Create this directory:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
mkdir -p app/prompts
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### 2. Create Prompt Templates
|
|
36
|
+
|
|
37
|
+
Create prompt templates as `.md.erb` files in the `app/prompts/` directory. Use ERB syntax to interpolate variables.
|
|
38
|
+
|
|
39
|
+
**Example: `app/prompts/summarize_text.md.erb`**
|
|
40
|
+
|
|
41
|
+
```erb
|
|
42
|
+
You are an expert content summarizer. Please summarize the following text:
|
|
43
|
+
|
|
44
|
+
Text to summarize:
|
|
45
|
+
---
|
|
46
|
+
<%= text %>
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
Provide a concise summary in <%= max_words %> words or less.
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### 3. Render Prompts in Your Application
|
|
53
|
+
|
|
54
|
+
Use `RailsPrompts.render_prompt` to render your templates with variables:
|
|
55
|
+
|
|
56
|
+
```ruby
|
|
57
|
+
# In your controller or service
|
|
58
|
+
prompt = RailsPrompts.render_prompt('summarize_text', {
|
|
59
|
+
text: "Long article text here...",
|
|
60
|
+
max_words: 100
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
# Use the prompt with your AI service
|
|
64
|
+
response = OpenAI::Client.new.chat(
|
|
65
|
+
parameters: {
|
|
66
|
+
model: "gpt-4",
|
|
67
|
+
messages: [{ role: "user", content: prompt }]
|
|
68
|
+
}
|
|
69
|
+
)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### 4. List Available Prompts
|
|
73
|
+
|
|
74
|
+
You can get a list of all available prompt templates:
|
|
75
|
+
|
|
76
|
+
```ruby
|
|
77
|
+
RailsPrompts.available_prompts
|
|
78
|
+
# => ["summarize_text", "generate_title", "code_review"]
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### 5. Configure Custom Prompts Directory (Optional)
|
|
82
|
+
|
|
83
|
+
If you want to store prompts in a different directory:
|
|
84
|
+
|
|
85
|
+
```ruby
|
|
86
|
+
# In config/initializers/rails_prompts.rb
|
|
87
|
+
RailsPrompts.prompts_dir = Rails.root.join('lib', 'prompts')
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Examples
|
|
91
|
+
|
|
92
|
+
### Example 1: Code Review Prompt
|
|
93
|
+
|
|
94
|
+
**`app/prompts/code_review.md.erb`**
|
|
95
|
+
|
|
96
|
+
```erb
|
|
97
|
+
You are an expert code reviewer. Please review the following <%= language %> code:
|
|
98
|
+
|
|
99
|
+
```<%= language %>
|
|
100
|
+
<%= code %>
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Focus on:
|
|
104
|
+
- Code quality and best practices
|
|
105
|
+
- Potential bugs or security issues
|
|
106
|
+
- Performance considerations
|
|
107
|
+
- Readability and maintainability
|
|
108
|
+
|
|
109
|
+
Provide constructive feedback.
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
**Usage:**
|
|
113
|
+
|
|
114
|
+
```ruby
|
|
115
|
+
prompt = RailsPrompts.render_prompt('code_review', {
|
|
116
|
+
language: 'ruby',
|
|
117
|
+
code: File.read('app/models/user.rb')
|
|
118
|
+
})
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Example 2: Generate Product Description
|
|
122
|
+
|
|
123
|
+
**`app/prompts/product_description.md.erb`**
|
|
124
|
+
|
|
125
|
+
```erb
|
|
126
|
+
Create a compelling product description for an e-commerce website.
|
|
127
|
+
|
|
128
|
+
Product Details:
|
|
129
|
+
- Name: <%= product_name %>
|
|
130
|
+
- Category: <%= category %>
|
|
131
|
+
- Key Features: <%= features.join(', ') %>
|
|
132
|
+
- Target Audience: <%= target_audience %>
|
|
133
|
+
|
|
134
|
+
Write a description that is engaging, SEO-friendly, and highlights the main benefits.
|
|
135
|
+
Length: <%= word_count %> words.
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
**Usage:**
|
|
139
|
+
|
|
140
|
+
```ruby
|
|
141
|
+
prompt = RailsPrompts.render_prompt('product_description', {
|
|
142
|
+
product_name: "Smart Wireless Headphones",
|
|
143
|
+
category: "Electronics",
|
|
144
|
+
features: ["Noise cancellation", "30-hour battery", "Bluetooth 5.0"],
|
|
145
|
+
target_audience: "Music enthusiasts and commuters",
|
|
146
|
+
word_count: 150
|
|
147
|
+
})
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Example 3: Customer Support Response
|
|
151
|
+
|
|
152
|
+
**`app/prompts/support_response.md.erb`**
|
|
153
|
+
|
|
154
|
+
```erb
|
|
155
|
+
You are a friendly and helpful customer support agent for <%= company_name %>.
|
|
156
|
+
|
|
157
|
+
Customer Issue:
|
|
158
|
+
<%= customer_message %>
|
|
159
|
+
|
|
160
|
+
<% if previous_interactions.any? %>
|
|
161
|
+
Previous Interactions:
|
|
162
|
+
<% previous_interactions.each do |interaction| %>
|
|
163
|
+
- <%= interaction %>
|
|
164
|
+
<% end %>
|
|
165
|
+
<% end %>
|
|
166
|
+
|
|
167
|
+
Generate a professional and empathetic response that addresses the customer's concern.
|
|
168
|
+
Tone: <%= tone %>
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
**Usage:**
|
|
172
|
+
|
|
173
|
+
```ruby
|
|
174
|
+
prompt = RailsPrompts.render_prompt('support_response', {
|
|
175
|
+
company_name: "Acme Corp",
|
|
176
|
+
customer_message: "My order hasn't arrived yet",
|
|
177
|
+
previous_interactions: ["Order placed 5 days ago", "Shipped 3 days ago"],
|
|
178
|
+
tone: "friendly and apologetic"
|
|
179
|
+
})
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Best Practices
|
|
183
|
+
|
|
184
|
+
1. **Keep prompts version controlled**: Since prompts are just files, they're easy to track with git
|
|
185
|
+
2. **Use descriptive template names**: Name your files clearly (e.g., `generate_blog_title.md.erb`)
|
|
186
|
+
3. **Add comments in templates**: Document complex prompts or explain variable usage
|
|
187
|
+
4. **Test your prompts**: Create tests to ensure prompts render correctly with different inputs
|
|
188
|
+
5. **Organize by feature**: Use subdirectories if you have many prompts (coming soon)
|
|
189
|
+
|
|
190
|
+
## Error Handling
|
|
191
|
+
|
|
192
|
+
Rails Prompts will raise an `ArgumentError` if a template is not found:
|
|
193
|
+
|
|
194
|
+
```ruby
|
|
195
|
+
begin
|
|
196
|
+
prompt = RailsPrompts.render_prompt('nonexistent_template', {})
|
|
197
|
+
rescue ArgumentError => e
|
|
198
|
+
puts e.message
|
|
199
|
+
# => "Prompt template 'nonexistent_template' not found at app/prompts/nonexistent_template.md.erb"
|
|
200
|
+
end
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## Testing
|
|
204
|
+
|
|
205
|
+
In your tests, you can configure a test-specific prompts directory:
|
|
206
|
+
|
|
207
|
+
```ruby
|
|
208
|
+
# In test_helper.rb or rails_helper.rb
|
|
209
|
+
RailsPrompts.prompts_dir = Rails.root.join('test', 'fixtures', 'prompts')
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## Requirements
|
|
213
|
+
|
|
214
|
+
- Ruby >= 2.7.0
|
|
215
|
+
- Rails >= 6.0
|
|
216
|
+
|
|
217
|
+
## Contributing
|
|
218
|
+
|
|
219
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/riteshchaudhary/rails_prompts
|
|
220
|
+
|
|
221
|
+
## License
|
|
222
|
+
|
|
223
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
224
|
+
|
|
225
|
+
## Author
|
|
226
|
+
|
|
227
|
+
Ritesh Chaudhary (chaudharyritesh7100@gmail.com)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rails_prompts
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ritesh Chaudhary
|
|
@@ -74,6 +74,9 @@ executables: []
|
|
|
74
74
|
extensions: []
|
|
75
75
|
extra_rdoc_files: []
|
|
76
76
|
files:
|
|
77
|
+
- CHANGELOG.md
|
|
78
|
+
- LICENSE.txt
|
|
79
|
+
- README.md
|
|
77
80
|
- lib/rails_prompts.rb
|
|
78
81
|
- lib/rails_prompts/version.rb
|
|
79
82
|
homepage: https://github.com/riteshchaudhary/rails_prompts
|