Skip to content

Commit

Permalink
improve readme
Browse files Browse the repository at this point in the history
  • Loading branch information
evdevdev committed Sep 20, 2024
1 parent f4036c9 commit 0abdfae
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@
"editor.formatOnType": true,
"editor.wordSeparators": "`~@#$%^&*()-=+[{]}\\|;:'\",.<>/"
},
"[markdown]": {
"editor.formatOnSave": true,
}
}
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
# Action Prompt

Action Prompt provides a dead simple way to way to organize and render prompts within a Rails App. This draws heavy inspiration from `ActionMailer::Preview`.
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.
> 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"`.

## Previewing Prompts
## Organizing & Previewing Prompts

1. Create a template for a prompt. These go in your `app/prompts` folder. For example, you might create `app/prompts/hello_world.text.erb` and give it the following content:
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:

```
```erb
You are a helpful assistant who replies with, "<%= @message >"
```

Expand All @@ -36,13 +42,20 @@ Install the gem with `gem "action_prompt"`.
## 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`.
1. You can now render this anywhere in your codebase with the following:
2. You can now render this anywhere in your codebase with the following:

```ruby
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](https://opensource.org/licenses/MIT).

0 comments on commit 0abdfae

Please sign in to comment.