promptly 0.1.13 → 0.1.21

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.
@@ -0,0 +1,116 @@
1
+ ## Rails App Integration
2
+
3
+ ### Service Object Pattern
4
+
5
+ ```ruby
6
+ # app/services/ai_prompt_service.rb
7
+ class AiPromptService
8
+ def self.generate_welcome_email(user, locale: I18n.locale)
9
+ prompt = Promptly.render(
10
+ "user_onboarding/welcome_email",
11
+ locale: locale,
12
+ locals: {
13
+ name: user.full_name,
14
+ app_name: Rails.application.class.module_parent_name,
15
+ user_role: user.role.humanize,
16
+ features: available_features_for(user),
17
+ days_since_signup: (Date.current - user.created_at.to_date).to_i
18
+ }
19
+ )
20
+
21
+ # Send to AI service and return generated content
22
+ openai_client.chat(
23
+ model: "gpt-4",
24
+ messages: [{role: "user", content: prompt}]
25
+ ).dig("choices", 0, "message", "content")
26
+ end
27
+
28
+ private
29
+
30
+ def self.available_features_for(user)
31
+ # Return features based on user's plan, role, etc.
32
+ case user.plan
33
+ when "basic"
34
+ ["Create projects", "Basic reporting"]
35
+ when "pro"
36
+ ["Create projects", "Team collaboration", "Advanced analytics", "API access"]
37
+ else
38
+ ["Create projects"]
39
+ end
40
+ end
41
+
42
+ def self.openai_client
43
+ @openai_client ||= OpenAI::Client.new(access_token: Rails.application.credentials.openai_api_key)
44
+ end
45
+ end
46
+ ```
47
+
48
+ ### Mailer Integration
49
+
50
+ ```ruby
51
+ # app/mailers/user_mailer.rb
52
+ class UserMailer < ApplicationMailer
53
+ def welcome_email(user)
54
+ @user = user
55
+ @ai_content = AiPromptService.generate_welcome_email(user, locale: user.locale)
56
+
57
+ mail(
58
+ to: user.email,
59
+ subject: t('mailer.welcome.subject')
60
+ )
61
+ end
62
+ end
63
+ ```
64
+
65
+ ### Background Job Usage
66
+
67
+ ```ruby
68
+ # app/jobs/generate_ai_content_job.rb
69
+ class GenerateAiContentJob < ApplicationJob
70
+ def perform(user_id, prompt_identifier, locals = {})
71
+ user = User.find(user_id)
72
+
73
+ prompt = Promptly.render(
74
+ prompt_identifier,
75
+ locale: user.locale,
76
+ locals: locals.merge(
77
+ user_name: user.full_name,
78
+ user_role: user.role,
79
+ account_type: user.account_type
80
+ )
81
+ )
82
+
83
+ # Generate AI content
84
+ ai_response = openai_client.chat(
85
+ model: "gpt-4",
86
+ messages: [{role: "user", content: prompt}]
87
+ )
88
+
89
+ generated_content = ai_response.dig("choices", 0, "message", "content")
90
+
91
+ # Store or send the generated content
92
+ user.notifications.create!(
93
+ title: "AI Generated Content Ready",
94
+ content: generated_content,
95
+ notification_type: prompt_identifier.split('/').last
96
+ )
97
+ end
98
+
99
+ private
100
+
101
+ def openai_client
102
+ @openai_client ||= OpenAI::Client.new(access_token: Rails.application.credentials.openai_api_key)
103
+ end
104
+ end
105
+
106
+ # Usage
107
+ GenerateAiContentJob.perform_later(
108
+ user.id,
109
+ "coaching/goal_review",
110
+ {
111
+ current_goals: user.goals.active.pluck(:title),
112
+ progress_summary: "Made good progress on fitness goals",
113
+ challenges: ["Time management", "Consistency"]
114
+ }
115
+ )
116
+ ```
@@ -0,0 +1,27 @@
1
+ ## Schema Validation
2
+
3
+ Ensure all locals passed to templates match a defined schema, so missing or mistyped variables fail fast before sending to AI.
4
+
5
+ ### Schema File Next to Prompt
6
+
7
+ For each prompt, create a `schema.yml` (or `.json`) file alongside the template.
8
+
9
+ **Example:**
10
+
11
+ `app/prompts/user_onboarding/welcome_email.schema.yml`
12
+
13
+ ```yml
14
+ name: string
15
+ app_name: string
16
+ user_role: string
17
+ features: array
18
+ days_since_signup: integer
19
+ ```
20
+
21
+ ### Validation Layer in Promptly
22
+
23
+ The validation is automatically triggered when you call `Promptly.render`. It will check for missing keys and (optionally) value types.
24
+
25
+ Supported types: `string`, `integer`, `array`.
26
+
27
+ If the validation fails, it will raise an `ArgumentError` for missing keys or a `TypeError` for mismatched types.
data/wiki/_Sidebar.md ADDED
@@ -0,0 +1,11 @@
1
+ - [Home](https://github.com/wilburhimself/promptly/wiki)
2
+ - [Quick Start](https://github.com/wilburhimself/promptly/wiki/Quick-Start)
3
+ - [Schema Validation](https://github.com/wilburhimself/promptly/wiki/Schema-Validation)
4
+ - [Helper: render_prompt](https://github.com/wilburhimself/promptly/wiki/Helper-render_prompt)
5
+ - [Rails App Integration](https://github.com/wilburhimself/promptly/wiki/Rails-App-Integration)
6
+ - [I18n Prompts Usage](https://github.com/wilburhimself/promptly/wiki/I18n-Prompts-Usage)
7
+ - [Liquid Templates](https://github.com/wilburhimself/promptly/wiki/Liquid-Templates)
8
+ - [Configuration](https://github.com/wilburhimself/promptly/wiki/Configuration)
9
+ - [Generators](https://github.com/wilburhimself/promptly/wiki/Generators)
10
+ - [Linting Templates](https://github.com/wilburhimself/promptly/wiki/Linting-Templates)
11
+ - [Functional Prompt Tests](https://github.com/wilburhimself/promptly/wiki/Functional-Prompt-Tests)
metadata CHANGED
@@ -1,29 +1,49 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: promptly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13
4
+ version: 0.1.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wilbur Suero
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-08-18 00:00:00.000000000 Z
11
+ date: 2026-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '7.2'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '9'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '7.2'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '9'
33
+ - !ruby/object:Gem::Dependency
34
+ name: json_schemer
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '2.3'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '2.3'
27
47
  - !ruby/object:Gem::Dependency
28
48
  name: rspec
29
49
  requirement: !ruby/object:Gem::Requirement
@@ -70,20 +90,26 @@ dependencies:
70
90
  name: railties
71
91
  requirement: !ruby/object:Gem::Requirement
72
92
  requirements:
73
- - - "~>"
93
+ - - ">="
74
94
  - !ruby/object:Gem::Version
75
95
  version: '7.2'
96
+ - - "<"
97
+ - !ruby/object:Gem::Version
98
+ version: '9'
76
99
  type: :development
77
100
  prerelease: false
78
101
  version_requirements: !ruby/object:Gem::Requirement
79
102
  requirements:
80
- - - "~>"
103
+ - - ">="
81
104
  - !ruby/object:Gem::Version
82
105
  version: '7.2'
106
+ - - "<"
107
+ - !ruby/object:Gem::Version
108
+ version: '9'
83
109
  description: Build maintainable, localized, and testable AI prompts using ERB or Liquid
84
110
  templates with Rails conventions
85
111
  email:
86
- - wilbur@example.com
112
+ - suerowilbur@gmail.com
87
113
  executables: []
88
114
  extensions: []
89
115
  extra_rdoc_files: []
@@ -94,6 +120,8 @@ files:
94
120
  - LICENSE
95
121
  - README.md
96
122
  - Rakefile
123
+ - app/prompts/test/prompt.en.erb
124
+ - app/prompts/test/prompt_with_metadata.en.erb
97
125
  - lib/generators/promptly/prompt_generator.rb
98
126
  - lib/promptly.rb
99
127
  - lib/promptly/cache.rb
@@ -102,7 +130,21 @@ files:
102
130
  - lib/promptly/railtie.rb
103
131
  - lib/promptly/renderer.rb
104
132
  - lib/promptly/tasks/ai_prompts.rake
133
+ - lib/promptly/validator.rb
105
134
  - lib/promptly/version.rb
135
+ - wiki/Configuration.md
136
+ - wiki/Functional-Prompt-Tests.md
137
+ - wiki/Generators.md
138
+ - wiki/Helper-render_prompt.md
139
+ - wiki/Home.md
140
+ - wiki/I18n-Prompts-Usage.md
141
+ - wiki/Linting-Templates.md
142
+ - wiki/Liquid-Templates.md
143
+ - wiki/Prompt-Version-Metadata.md
144
+ - wiki/Quick-Start.md
145
+ - wiki/Rails-App-Integration.md
146
+ - wiki/Schema-Validation.md
147
+ - wiki/_Sidebar.md
106
148
  homepage: https://github.com/wilburhimself/promptly
107
149
  licenses:
108
150
  - MIT