active_prompt_rails 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +13 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +12 -0
- data/README.md +31 -0
- data/Rakefile +12 -0
- data/active_prompt.gemspec +29 -0
- data/lib/active_prompt/base.rb +55 -0
- data/lib/active_prompt/errors.rb +10 -0
- data/lib/active_prompt/generators/prompt/prompt_generator.rb +21 -0
- data/lib/active_prompt/generators/prompt/templates/system.liquid +1 -0
- data/lib/active_prompt/generators/prompt/templates/user.liquid +1 -0
- data/lib/active_prompt/version.rb +5 -0
- data/lib/active_prompt.rb +8 -0
- data/sig/active_prompt.rbs +4 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d3acda164ca3d3f9d1cdb8be59df667ad5e7a86a034eb659792b89cb05a671ea
|
4
|
+
data.tar.gz: 02caaedae4819c0a5f989fd5a23651435429a324f1ac8b775ed66f213a65debd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3adeb75900c04e0d120c5337dd07e2fbb0d0c1d58229a36e44a5484e2a300cf009caacfacce66daafb9342f4989f8d8b1421082ad40b3074ead641f029377c4c
|
7
|
+
data.tar.gz: d2abb4207dc8c50e470d9a7532d6c26953f8b2ff6f153bca66a05a20169f7b7f9333374e87549d0d0297a36dd75fdd561e6999f710b4fb631ca642709b637938
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# ActivePrompt
|
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.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
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.
|
10
|
+
|
11
|
+
Install the gem and add to the application's Gemfile by executing:
|
12
|
+
|
13
|
+
$ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
14
|
+
|
15
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
16
|
+
|
17
|
+
$ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Development
|
24
|
+
|
25
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
26
|
+
|
27
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/active_prompt.
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/active_prompt/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "active_prompt_rails"
|
7
|
+
spec.licenses = ["MIT"]
|
8
|
+
spec.version = ActivePrompt::VERSION
|
9
|
+
spec.authors = ["Shane Perreault"]
|
10
|
+
spec.email = ["shaneprrlt@gmail.com"]
|
11
|
+
spec.summary = "Easily create and manage LLM prompt templates in your rails app."
|
12
|
+
spec.description = "Easily create and manage LLM prompt templates in your rails app." \
|
13
|
+
"Use your own custom templating engine like ERB or Shopify Liquid."
|
14
|
+
spec.homepage = "https://www.github.com/Shaneprrlt/active_prompt"
|
15
|
+
spec.required_ruby_version = ">= 2.6.0"
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = "https://www.github.com/Shaneprrlt/active_prompt"
|
18
|
+
spec.metadata["changelog_uri"] = "https://www.github.com/Shaneprrlt/active_prompt/blob/main/CHANGELOG.md"
|
19
|
+
spec.files = Dir.chdir(__dir__) do
|
20
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
21
|
+
(File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
spec.bindir = "exe"
|
25
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
spec.add_runtime_dependency "liquid", "~> 5.2", ">= 5.2.0"
|
28
|
+
spec.add_runtime_dependency "rails", "~> 6.0"
|
29
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# lib/active_prompt/base.rb
|
4
|
+
require "active_support/inflector"
|
5
|
+
require "liquid"
|
6
|
+
require_relative "errors"
|
7
|
+
|
8
|
+
module ActivePrompt
|
9
|
+
# Base class for all prompt classes
|
10
|
+
class Base
|
11
|
+
def self.variables
|
12
|
+
@variables ||= []
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.variable(name)
|
16
|
+
variables << name
|
17
|
+
attr_accessor name
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(params = {})
|
21
|
+
self.class.variables.each do |var|
|
22
|
+
raise MissingVariableError, var unless params.key?(var)
|
23
|
+
|
24
|
+
send("#{var}=", params[var]) # Dynamic method call to set the variable
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def render_system
|
29
|
+
render_template("system.liquid")
|
30
|
+
end
|
31
|
+
|
32
|
+
def render_user
|
33
|
+
render_template("user.liquid")
|
34
|
+
end
|
35
|
+
|
36
|
+
def render_messages
|
37
|
+
[
|
38
|
+
{ role: "system", content: render_system },
|
39
|
+
{ role: "user", content: render_user }
|
40
|
+
]
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def render_template(template_name)
|
46
|
+
template_path = File.join("app", "prompts", self.class.name.underscore, template_name)
|
47
|
+
template = File.read(template_path)
|
48
|
+
context = # Dynamic method call to get the variable value
|
49
|
+
self.class.variables.map do |var|
|
50
|
+
[var, send(var)]
|
51
|
+
end.to_h
|
52
|
+
Liquid::Template.parse(template).render(context)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActivePrompt
|
4
|
+
module Generators
|
5
|
+
# This generator creates a new prompt in the app/prompts directory
|
6
|
+
class PromptGenerator < Rails::Generators::NamedBase
|
7
|
+
source_root File.expand_path("templates", __dir__)
|
8
|
+
|
9
|
+
def create_prompt_files
|
10
|
+
create_file "app/prompts/#{file_name}/system.liquid"
|
11
|
+
create_file "app/prompts/#{file_name}/user.liquid"
|
12
|
+
create_file "app/prompts/#{file_name}/prompt.rb", <<~RUBY
|
13
|
+
# This is a generated prompt class for #{file_name}
|
14
|
+
class #{file_name.camelize}Prompt < ActivePrompt::Base
|
15
|
+
# Define your prompt methods here
|
16
|
+
end
|
17
|
+
RUBY
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Enter your system message here.
|
@@ -0,0 +1 @@
|
|
1
|
+
Enter your user message here.
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: active_prompt_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shane Perreault
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-05-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: liquid
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.2'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 5.2.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '5.2'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 5.2.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rails
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '6.0'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '6.0'
|
47
|
+
description: Easily create and manage LLM prompt templates in your rails app.Use your
|
48
|
+
own custom templating engine like ERB or Shopify Liquid.
|
49
|
+
email:
|
50
|
+
- shaneprrlt@gmail.com
|
51
|
+
executables: []
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- ".rspec"
|
56
|
+
- ".rubocop.yml"
|
57
|
+
- CHANGELOG.md
|
58
|
+
- Gemfile
|
59
|
+
- README.md
|
60
|
+
- Rakefile
|
61
|
+
- active_prompt.gemspec
|
62
|
+
- lib/active_prompt.rb
|
63
|
+
- lib/active_prompt/base.rb
|
64
|
+
- lib/active_prompt/errors.rb
|
65
|
+
- lib/active_prompt/generators/prompt/prompt_generator.rb
|
66
|
+
- lib/active_prompt/generators/prompt/templates/system.liquid
|
67
|
+
- lib/active_prompt/generators/prompt/templates/user.liquid
|
68
|
+
- lib/active_prompt/version.rb
|
69
|
+
- sig/active_prompt.rbs
|
70
|
+
homepage: https://www.github.com/Shaneprrlt/active_prompt
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata:
|
74
|
+
homepage_uri: https://www.github.com/Shaneprrlt/active_prompt
|
75
|
+
source_code_uri: https://www.github.com/Shaneprrlt/active_prompt
|
76
|
+
changelog_uri: https://www.github.com/Shaneprrlt/active_prompt/blob/main/CHANGELOG.md
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 2.6.0
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubygems_version: 3.3.7
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Easily create and manage LLM prompt templates in your rails app.
|
96
|
+
test_files: []
|