ruby_llm-template 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1c7cd2995edf14cfa1711e8e2a92a0d67a162d904865d559aaf3ec01d158e044
4
- data.tar.gz: 3f1efee4b9cbe460ad9f029345b26d98acd0ff3f6e25b895b30c71dd9322d3a4
3
+ metadata.gz: 8af32c4910100355c57302be6fb145bc6463fa3c39105533bda9a6002709bd1c
4
+ data.tar.gz: a55213fce936c617a83db65eea1aeb54584fcafae203a54a8736c41c17d25c33
5
5
  SHA512:
6
- metadata.gz: 01fe1048a262c4922ab3e9255d99be4a9f9d623dc9f97881f1f524c1a1f0914ae3b3dddd7751e4ebfc3aab79d661f73f17dfbaca3582df1512d9b145617e8245
7
- data.tar.gz: 1d379ae8359f039c50a4953dbc0c29d0609ffa397e49701632fd1df05e42f484205637e7ef8a3398beda7f4a054864738c6a4a4c98601c65a379938541153903
6
+ metadata.gz: 8831170d3d2a9dc5feacfb0332cbe9c232a2383c970e1b50de51429e2fe0eddf87ee70cbaf85bc2fec67430082e2a3f0b40d7d2d62187ff454a4198a4d0be7d8
7
+ data.tar.gz: 9a16c7e87550bfd9d5e0cd796543429933a027641fdc99c770337fc97d2e37e940b216404e1a88d19fb3418405ac86417fed1755d0056711fabd2f6261998afc
data/README.md CHANGED
@@ -7,12 +7,6 @@
7
7
  Organize prompts into easy-to-use templates for [RubyLLM](https://github.com/crmne/ruby_llm).
8
8
 
9
9
  ```ruby
10
- chat = RubyLLM.chat
11
- chat.with_template(:extract_metadata, document: @document).complete
12
-
13
- # ----------------------------------
14
- # Retrieves the following files:
15
- # ----------------------------------
16
10
  # prompts/
17
11
  # extract_metadata/
18
12
  # ├── system.txt.erb # System message
@@ -20,6 +14,8 @@ chat.with_template(:extract_metadata, document: @document).complete
20
14
  # ├── assistant.txt.erb # Assistant message (optional)
21
15
  # └── schema.rb # RubyLLM::Schema definition (optional)
22
16
 
17
+ chat = RubyLLM.chat
18
+ chat.with_template(:extract_metadata, document: @document).complete
23
19
  ```
24
20
 
25
21
  ## Features
@@ -115,22 +111,18 @@ end
115
111
  ### 3. Use the Template
116
112
 
117
113
  ```ruby
118
- # Basic usage
119
- RubyLLM.chat.with_template(:extract_metadata, document: @document).complete
114
+ chat = RubyLLM.chat
115
+ chat.with_template(:extract_metadata, document: @document, additional_context: "Focus on technical details").complete
120
116
 
121
- # With context variables
122
- RubyLLM.chat.with_template(:extract_metadata,
123
- document: @document,
124
- additional_context: "Focus on technical details"
125
- ).complete
117
+ # Under the hood, RubyLLM::Template renders the templates with the context variables
118
+ # and applies them to the chat instance using native RubyLLM methods:
126
119
 
127
- # Chaining with other RubyLLM methods
128
- RubyLLM.chat
129
- .with_template(:extract_metadata, document: @document)
130
- .with_model("gpt-4")
131
- .complete
120
+ # chat.add_message(:system, rendered_system_message)
121
+ # chat.add_message(:user, rendered_user_message)
122
+ # chat.add_schema(instantiated_schema)
132
123
  ```
133
124
 
125
+
134
126
  ## Configuration
135
127
 
136
128
  ### Non-Rails Applications
@@ -166,7 +158,13 @@ Templates are processed in order: system → user → assistant → schema
166
158
 
167
159
  All context variables passed to `with_template` are available in your ERB templates:
168
160
 
161
+ ```ruby
162
+ chat = RubyLLM.chat
163
+ chat.with_template(:message, name: "Alice", urgent: true, documents: @documents)
164
+ ```
165
+
169
166
  ```erb
167
+ <!-- /prompts/message/user.txt.erb -->
170
168
  Hello <%= name %>!
171
169
 
172
170
  <% if urgent %>
@@ -0,0 +1,120 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators"
4
+
5
+ module RubyLLM
6
+ module Template
7
+ module Generators
8
+ class InstallGenerator < Rails::Generators::Base
9
+ namespace "ruby_llm_template:install"
10
+ desc "Install RubyLLM Template system"
11
+
12
+ def self.source_root
13
+ @source_root ||= File.expand_path("templates", __dir__)
14
+ end
15
+
16
+ def create_initializer
17
+ create_file "config/initializers/ruby_llm_template.rb", <<~RUBY
18
+ # frozen_string_literal: true
19
+
20
+ RubyLLM::Template.configure do |config|
21
+ # Set the directory where your prompts are stored
22
+ # Default: Rails.root.join("app", "prompts")
23
+ # config.template_directory = Rails.root.join("app", "prompts")
24
+ end
25
+ RUBY
26
+ end
27
+
28
+ def create_template_directory
29
+ empty_directory "app/prompts"
30
+
31
+ create_file "app/prompts/.keep", ""
32
+
33
+ # Create an example template
34
+ create_example_template
35
+ end
36
+
37
+ def show_readme
38
+ say <<~MESSAGE
39
+
40
+ RubyLLM Template has been installed!
41
+
42
+ Prompts directory: app/prompts/
43
+ Configuration: config/initializers/ruby_llm_template.rb
44
+
45
+ Example usage:
46
+ RubyLLM.chat.with_template(:extract_metadata, document: @document).complete
47
+
48
+ Template structure:
49
+ app/prompts/extract_metadata/
50
+ ├── system.txt.erb # System message
51
+ ├── user.txt.erb # User prompt
52
+ ├── assistant.txt.erb # Assistant message (optional)
53
+ └── schema.rb # RubyLLM::Schema definition (optional)
54
+
55
+ Get started by creating your first template!
56
+ MESSAGE
57
+ end
58
+
59
+ private
60
+
61
+ def create_example_template
62
+ example_dir = "app/prompts/extract_metadata"
63
+ empty_directory example_dir
64
+
65
+ create_file "#{example_dir}/system.txt.erb", <<~ERB
66
+ You are an expert document analyzer. Your task is to extract metadata from the provided document.
67
+
68
+ Please analyze the document carefully and extract relevant information such as:
69
+ - Document type
70
+ - Key topics
71
+ - Important dates
72
+ - Main entities mentioned
73
+
74
+ Provide your analysis in a structured format.
75
+ ERB
76
+
77
+ create_file "#{example_dir}/user.txt.erb", <<~ERB
78
+ Please analyze the following document and extract its metadata:
79
+
80
+ <% if defined?(document) && document %>
81
+ Document: <%= document %>
82
+ <% else %>
83
+ [Document content will be provided here]
84
+ <% end %>
85
+
86
+ <% if defined?(additional_context) && additional_context %>
87
+ Additional context: <%= additional_context %>
88
+ <% end %>
89
+ ERB
90
+
91
+ create_file "#{example_dir}/schema.rb", <<~RUBY
92
+ # frozen_string_literal: true
93
+
94
+ # Schema definition using RubyLLM::Schema DSL
95
+ # See: https://github.com/danielfriis/ruby_llm-schema
96
+
97
+ RubyLLM::Schema.create do
98
+ string :document_type, description: "The type of document (e.g., report, article, email)"
99
+
100
+ array :key_topics, description: "Main topics discussed in the document" do
101
+ string
102
+ end
103
+
104
+ array :important_dates, required: false, description: "Significant dates mentioned in the document" do
105
+ string format: "date"
106
+ end
107
+
108
+ array :entities, required: false, description: "Named entities found in the document" do
109
+ object do
110
+ string :name
111
+ string :type, enum: ["person", "organization", "location", "other"]
112
+ end
113
+ end
114
+ end
115
+ RUBY
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
@@ -3,6 +3,11 @@
3
3
  module RubyLLM
4
4
  module Template
5
5
  class Railtie < Rails::Railtie
6
+ # Register generators
7
+ generators do
8
+ require_relative "../../generators/ruby_llm/template/install_generator"
9
+ end
10
+
6
11
  initializer "ruby_llm_template.configure" do |app|
7
12
  # Set default template directory for Rails applications
8
13
  RubyLLM::Template.configure do |config|
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RubyLLM
4
4
  module Template
5
- VERSION = "0.1.5"
5
+ VERSION = "0.1.6"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_llm-template
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Friis
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-09-03 00:00:00.000000000 Z
11
+ date: 2025-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby_llm
@@ -68,7 +68,7 @@ files:
68
68
  - README.md
69
69
  - Rakefile
70
70
  - examples/basic_usage.rb
71
- - lib/generators/ruby_llm_template/install_generator.rb
71
+ - lib/generators/ruby_llm/template/install_generator.rb
72
72
  - lib/ruby_llm/template.rb
73
73
  - lib/ruby_llm/template/chat_extension.rb
74
74
  - lib/ruby_llm/template/configuration.rb
@@ -1,117 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "rails/generators"
4
-
5
- module RubyLLMTemplate
6
- module Generators
7
- class InstallGenerator < Rails::Generators::Base
8
- desc "Install RubyLLM Template system"
9
-
10
- def self.source_root
11
- @source_root ||= File.expand_path("templates", __dir__)
12
- end
13
-
14
- def create_initializer
15
- create_file "config/initializers/ruby_llm_template.rb", <<~RUBY
16
- # frozen_string_literal: true
17
-
18
- RubyLLM::Template.configure do |config|
19
- # Set the directory where your prompts are stored
20
- # Default: Rails.root.join("app", "prompts")
21
- # config.template_directory = Rails.root.join("app", "prompts")
22
- end
23
- RUBY
24
- end
25
-
26
- def create_template_directory
27
- empty_directory "app/prompts"
28
-
29
- create_file "app/prompts/.keep", ""
30
-
31
- # Create an example template
32
- create_example_template
33
- end
34
-
35
- def show_readme
36
- say <<~MESSAGE
37
-
38
- RubyLLM Template has been installed!
39
-
40
- Prompts directory: app/prompts/
41
- Configuration: config/initializers/ruby_llm_template.rb
42
-
43
- Example usage:
44
- RubyLLM.chat.with_template(:extract_metadata, document: @document).complete
45
-
46
- Template structure:
47
- app/prompts/extract_metadata/
48
- ├── system.txt.erb # System message
49
- ├── user.txt.erb # User prompt
50
- ├── assistant.txt.erb # Assistant message (optional)
51
- └── schema.rb # RubyLLM::Schema definition (optional)
52
-
53
- Get started by creating your first template!
54
- MESSAGE
55
- end
56
-
57
- private
58
-
59
- def create_example_template
60
- example_dir = "app/prompts/extract_metadata"
61
- empty_directory example_dir
62
-
63
- create_file "#{example_dir}/system.txt.erb", <<~ERB
64
- You are an expert document analyzer. Your task is to extract metadata from the provided document.
65
-
66
- Please analyze the document carefully and extract relevant information such as:
67
- - Document type
68
- - Key topics
69
- - Important dates
70
- - Main entities mentioned
71
-
72
- Provide your analysis in a structured format.
73
- ERB
74
-
75
- create_file "#{example_dir}/user.txt.erb", <<~ERB
76
- Please analyze the following document and extract its metadata:
77
-
78
- <% if defined?(document) && document %>
79
- Document: <%= document %>
80
- <% else %>
81
- [Document content will be provided here]
82
- <% end %>
83
-
84
- <% if defined?(additional_context) && additional_context %>
85
- Additional context: <%= additional_context %>
86
- <% end %>
87
- ERB
88
-
89
- create_file "#{example_dir}/schema.rb", <<~RUBY
90
- # frozen_string_literal: true
91
-
92
- # Schema definition using RubyLLM::Schema DSL
93
- # See: https://github.com/danielfriis/ruby_llm-schema
94
-
95
- RubyLLM::Schema.create do
96
- string :document_type, description: "The type of document (e.g., report, article, email)"
97
-
98
- array :key_topics, description: "Main topics discussed in the document" do
99
- string
100
- end
101
-
102
- array :important_dates, required: false, description: "Significant dates mentioned in the document" do
103
- string format: "date"
104
- end
105
-
106
- array :entities, required: false, description: "Named entities found in the document" do
107
- object do
108
- string :name
109
- string :type, enum: ["person", "organization", "location", "other"]
110
- end
111
- end
112
- end
113
- RUBY
114
- end
115
- end
116
- end
117
- end