Skip to content

Opinionated Rails integration for reusable AI prompt templates. Build maintainable, localized, and testable AI prompts using ERB or Liquid templates with Rails conventions.

License

Notifications You must be signed in to change notification settings

wilburhimself/promptly

Repository files navigation

Promptly

Opinionated Rails integration for reusable AI prompt templates. Build maintainable, localized, and testable AI prompts using ERB or Liquid templates with Rails conventions.

Features

  • Template rendering: ERB (via ActionView) and optional Liquid support
  • I18n integration: Automatic locale fallback (welcome.es.erbwelcome.en.erbwelcome.erb)
  • Rails conventions: Store prompts in app/prompts/ with organized subdirectories
  • Render & CLI: Test prompts in Rails console or via rake tasks
  • Minimal setup: Auto-loads via Railtie, zero configuration required
  • Prompt caching: Configurable cache store, TTL, and cache-bypass options
  • Schema Validation: Ensure all locals passed to templates match a defined schema.

Documentation

For detailed documentation, please visit the Promptly Wiki.

Install

Add to your Gemfile:

gem "promptly"

For Liquid template support, also add:

gem "liquid"

Then run:

bundle install

Quick Start

# In a controller, service, or anywhere in Rails
prompt = Promptly.render(
  "user_onboarding/welcome_email",
  locale: :es,
  locals: {
    name: "María García",
    app_name: "ProjectHub",
    user_role: "Team Lead",
    features: ["Create projects", "Invite team members", "Track progress", "Generate reports"],
    days_since_signup: 2
  }
)

# Send to your AI service (OpenAI, Anthropic, etc.)
ai_response = openai_client.completions(
  model: "gpt-4",
  messages: [{role: "user", content: prompt}]
)

puts ai_response.dig("choices", 0, "message", "content")
# => AI-generated personalized welcome email in Spanish

Development

# Install dependencies
bundle install

# Run tests
bundle exec rspec

# Run linter
bundle exec standardrb

# Build gem
rake build

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

MIT

About

Opinionated Rails integration for reusable AI prompt templates. Build maintainable, localized, and testable AI prompts using ERB or Liquid templates with Rails conventions.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published