Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

action_prompt

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

action_prompt

  • 0.3.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Action Prompt

Action Prompt provides a dead simple way to way to organize, preview, and render prompts within a Ruby on Rails App. Because this leverages the ApplicationController, you're able to leverage all the bells an whistles

This draws heavy inspiration from ActionMailer::Preview.

[!IMPORTANT] This gem is a work-in-progress. It is not production ready . That said, ActionPrompt is under active development. Any and all feedback would be very welcome. Or hey, feel free to open a PR.

Motivation & Usage

As LLMs have become ubiquitous in web applications, we've that prompts intended for Claude or GPT have become scattered throughout our codebase or buried within objects. Often, these prompts were built inline through string manipulation. Our thinking was two-fold, 1) Let's come up with a simple pattern for organizing and rendering these prompts, and 2) Let's make them easy to review.

Installation

Install the gem with gem "action_prompt".

Organizing & Previewing Prompts

  1. Create a template for organizing your prompts located at your app/prompts. For example, you might create app/prompts/hello_world.text.erb and give it the following content:

    You are a helpful assistant who replies with, "<%= @message >"
    
  2. Create a preview class. These live in test/prompts and they inherit from ActionPrompt::Preview. For example, you might create tests/prompts/hello_world_preview.rb and give it the following context:

    class HelloWorldPreview < ActionPrompt::Preview
     def example_prompt
       render "hello_world", locals: {message: "Hello, world!"}
     end
    end
    
  3. Next, start up your rails server (rails s) and navigate to http://localhost:3000/action_prompt/previews. You'll see a list of your prompts that resembles the following:

    Screenshot

    You can now preview your prompts.

Rendering prompts within your app

  1. Assume you've followed step one above, and you have a prompt located at app/prompts/hello_world.text.erb.

  2. You can now render this anywhere in your codebase with the following:

    ActionPrompt::Renderer.new.render("hello_world", locals: {message: "Now we're cooking"})
    # You are a helpful assistant who replies with, "Now we're cooking"
    

Under the hood, ActionPrompt is leveraging the app's ApplicationController. That means you can use the full magic of ActionView which includes

  • Rendering partials.
  • Rendering json with Jbuilder
  • Using route helpers, i.e. posts_url
  • ...and more!

License

The gem is available as open source under the terms of the MIT License.

FAQs

Package last updated on 20 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc