promptly 0.1.13 → 0.1.17

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,14 +1,14 @@
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.17
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-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '7.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json_schemer
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.3'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.3'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rspec
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -83,7 +97,7 @@ dependencies:
83
97
  description: Build maintainable, localized, and testable AI prompts using ERB or Liquid
84
98
  templates with Rails conventions
85
99
  email:
86
- - wilbur@example.com
100
+ - suerowilbur@gmail.com
87
101
  executables: []
88
102
  extensions: []
89
103
  extra_rdoc_files: []
@@ -94,6 +108,8 @@ files:
94
108
  - LICENSE
95
109
  - README.md
96
110
  - Rakefile
111
+ - app/prompts/test/prompt.en.erb
112
+ - app/prompts/test/prompt_with_metadata.en.erb
97
113
  - lib/generators/promptly/prompt_generator.rb
98
114
  - lib/promptly.rb
99
115
  - lib/promptly/cache.rb
@@ -102,7 +118,21 @@ files:
102
118
  - lib/promptly/railtie.rb
103
119
  - lib/promptly/renderer.rb
104
120
  - lib/promptly/tasks/ai_prompts.rake
121
+ - lib/promptly/validator.rb
105
122
  - lib/promptly/version.rb
123
+ - wiki/Configuration.md
124
+ - wiki/Functional-Prompt-Tests.md
125
+ - wiki/Generators.md
126
+ - wiki/Helper-render_prompt.md
127
+ - wiki/Home.md
128
+ - wiki/I18n-Prompts-Usage.md
129
+ - wiki/Linting-Templates.md
130
+ - wiki/Liquid-Templates.md
131
+ - wiki/Prompt-Version-Metadata.md
132
+ - wiki/Quick-Start.md
133
+ - wiki/Rails-App-Integration.md
134
+ - wiki/Schema-Validation.md
135
+ - wiki/_Sidebar.md
106
136
  homepage: https://github.com/wilburhimself/promptly
107
137
  licenses:
108
138
  - MIT