active_prompt_rails 0.1.18 → 0.1.19

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0cce75514b94749199f3bd2b3dbbb3a5017ae5bd69d2c32af838a4aa84268a2c
4
- data.tar.gz: 6fc57f049084c4e4f804c606eb9e9b1f482d06cad1ff48e203f8c517863c1b58
3
+ metadata.gz: d9b0ed834ff87bf6e5e43d1a513cebece5021afc6b4306dda7c4bd7b89038066
4
+ data.tar.gz: 5febc8f1d53ef6309da8d579c78c58bd6ab5b302f7dd1304e999005dd5e89caa
5
5
  SHA512:
6
- metadata.gz: 9dfbb0943bab181f662da38f69b92a2141f8599743d4e14ad6870cef3d9218c2d35c5a9335ec473085e05d3896eb10365766e46b5bffe122c8c4900c4bea8c41
7
- data.tar.gz: 72e5e29a24e415e5b467464fe0b44d35c7bd8398e76db307159aa00575f2703cd33cfe4e1875719769fae6ff75d0ad9387d32049b4435a5a8bce391d8c345552
6
+ metadata.gz: f3b645c825c321dad775b564d1e2d7001b66fd8c94114f10dd1570ea3498f9e03af62b42f6009f9b73f7b4dad59cc8e457b7c4e238d7a5135dd631c480c4be4a
7
+ data.tar.gz: d4d0f0a9b498f3ff84ecb65e79a5ef3a8f2f3b674fff8b722c7b9442985c8aa715294e70454d9a420d59fd2fed0ef1efd4b7787e01c5d5236b502c58e61ca537
data/README.md CHANGED
@@ -1,24 +1,79 @@
1
1
  # ActivePrompt
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
4
-
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/active_prompt`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ ActivePrompt is a gem that helps you structure and manage LLM prompts in your rails apps.
6
4
 
7
5
  ## Installation
8
6
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
7
+ Add the following line to your Gemfile:
8
+
9
+ ```Gemfile
10
+ gem "active_prompt_rails", "~> 0.1.18", require: "active_prompt"
11
+ ```
10
12
 
11
- Install the gem and add to the application's Gemfile by executing:
13
+ and run `bundle install`
12
14
 
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
15
+ ## Usage
14
16
 
15
- If bundler is not being used to manage dependencies, install the gem by executing:
17
+ When you want to create a new LLM prompt, you can generate one using the following command:
16
18
 
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
19
+ ```bash
20
+ rails g active_prompt:prompt moderate_user_comment
21
+ ```
18
22
 
19
- ## Usage
23
+ This will create the following files in your rails project:
24
+
25
+ ```bash
26
+ app/prompts/moderate_user_comment_prompt.rb
27
+ app/prompts/templates/moderate_user_comment_prompt/system.liquid
28
+ app/prompts/templates/moderate_user_comment_prompt/user.liquid
29
+ ```
30
+
31
+ You can add your system message and user message to the corresponding Liquid template files and include any dynamic variables you'd like, e.g.:
32
+
33
+ ```ruby
34
+ # /app/prompts/moderate_user_comment_prompt.rb
35
+
36
+ class ModerateUserCommentPrompt < ActivePrompt::Base
37
+ variable :comment
38
+ end
39
+ ```
40
+
41
+ ```liquid
42
+ # /app/prompts/templates/moderate_user_comment_prompt/system.liquid
43
+
44
+ You are a comment moderator agent that is responsible for reviewing and moderating user comments on a social media platform. You are assigned to reviewing comments and returning your decision on whether to approve or flag them for further review. Check for bullying, hate speech, and threatening language. Swearing is allowed as long as it's not harrassing. You return your decision in JSON format with the following structure:
45
+ {
46
+ "result": "approve" (or "flag"),
47
+ "reason": "optional reason for flagging the comment"
48
+ }
49
+ ```
50
+
51
+ ```liquid
52
+ # /app/prompts/templates/moderate_user_comment_prompt/user.liquid
53
+
54
+ Review this comment and return your decision in the specified JSON format:
55
+
56
+ {{ comment }}
57
+ ```
58
+
59
+ Then within your application, you can use this prompt when calling an LLM as such:
60
+
61
+ ```ruby
62
+ prompt = ModerateUserCommentPrompt.new(comment: user_comment)
20
63
 
21
- TODO: Write usage instructions here
64
+ client = OpenAI::Client.new
65
+ response = client.chat(
66
+ parameters: {
67
+ model: "gpt-4o",
68
+ response_format: { type: "json_object" },
69
+ messages: prompt.render_messages, # ActivePrompt::Base.render_messages returns OpenAI formatted message data
70
+ temperature: 1.0
71
+ }
72
+ )
73
+ content = response.dig("choices", 0, "message", "content")
74
+ data = JSON.parse(content)
75
+ puts data
76
+ ```
22
77
 
23
78
  ## Development
24
79
 
@@ -28,4 +83,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
28
83
 
29
84
  ## Contributing
30
85
 
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/active_prompt.
86
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Shaneprrlt/active_prompt.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActivePrompt
4
- VERSION = "0.1.18"
4
+ VERSION = "0.1.19"
5
5
  end
@@ -14,12 +14,10 @@ module ActivePrompt
14
14
  template "system.liquid", "app/prompts/templates/#{name.underscore}_prompt/system.liquid"
15
15
  template "user.liquid", "app/prompts/templates/#{name.underscore}_prompt/user.liquid"
16
16
  create_file "app/prompts/#{name.underscore}_prompt.rb", <<~RUBY
17
- # This is a generated prompt class for #{file_name}
17
+ # frozen_string_literal: true
18
+
18
19
  class #{name.camelize}Prompt < ActivePrompt::Base
19
- # Define your required template variables here, e.g.
20
20
  # variable :name
21
- # variable :age
22
- # variable :gender
23
21
  end
24
22
  RUBY
25
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_prompt_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.18
4
+ version: 0.1.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane Perreault