ruby_llm-template 0.1.4 → 0.1.5
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 +4 -4
- data/README.md +3 -3
- data/examples/basic_usage.rb +3 -3
- data/lib/generators/ruby_llm_template/install_generator.rb +2 -2
- data/lib/ruby_llm/template/chat_extension.rb +3 -3
- data/lib/ruby_llm/template/configuration.rb +1 -1
- data/lib/ruby_llm/template/loader.rb +2 -2
- data/lib/ruby_llm/template/railtie.rb +2 -2
- data/lib/ruby_llm/template/version.rb +2 -2
- data/lib/ruby_llm/template.rb +3 -3
- data/sig/ruby_llm/template.rbs +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c7cd2995edf14cfa1711e8e2a92a0d67a162d904865d559aaf3ec01d158e044
|
4
|
+
data.tar.gz: 3f1efee4b9cbe460ad9f029345b26d98acd0ff3f6e25b895b30c71dd9322d3a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01fe1048a262c4922ab3e9255d99be4a9f9d623dc9f97881f1f524c1a1f0914ae3b3dddd7751e4ebfc3aab79d661f73f17dfbaca3582df1512d9b145617e8245
|
7
|
+
data.tar.gz: 1d379ae8359f039c50a4953dbc0c29d0609ffa397e49701632fd1df05e42f484205637e7ef8a3398beda7f4a054864738c6a4a4c98601c65a379938541153903
|
data/README.md
CHANGED
@@ -136,7 +136,7 @@ RubyLLM.chat
|
|
136
136
|
### Non-Rails Applications
|
137
137
|
|
138
138
|
```ruby
|
139
|
-
|
139
|
+
RubyLLM::Template.configure do |config|
|
140
140
|
config.template_directory = "/path/to/your/prompts"
|
141
141
|
end
|
142
142
|
```
|
@@ -146,7 +146,7 @@ end
|
|
146
146
|
The gem automatically configures itself to use `Rails.root.join("app", "prompts")`, but you can override this in `config/initializers/ruby_llm_template.rb`:
|
147
147
|
|
148
148
|
```ruby
|
149
|
-
|
149
|
+
RubyLLM::Template.configure do |config|
|
150
150
|
config.template_directory = Rails.root.join("app", "ai_prompts")
|
151
151
|
end
|
152
152
|
```
|
@@ -249,7 +249,7 @@ The gem provides clear error messages for common issues:
|
|
249
249
|
```ruby
|
250
250
|
begin
|
251
251
|
RubyLLM.chat.with_template(:extract_metadata).complete
|
252
|
-
rescue
|
252
|
+
rescue RubyLLM::Template::Error => e
|
253
253
|
puts e.message
|
254
254
|
# "Template 'extract_metadata' not found in /path/to/prompts"
|
255
255
|
# "Schema file 'extract_metadata/schema.rb' found but RubyLLM::Schema gem is not installed"
|
data/examples/basic_usage.rb
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
require_relative "../lib/ruby_llm/template"
|
8
8
|
|
9
9
|
# Configure template directory
|
10
|
-
|
10
|
+
RubyLLM::Template.configure do |config|
|
11
11
|
config.template_directory = File.join(__dir__, "prompts")
|
12
12
|
end
|
13
13
|
|
@@ -91,7 +91,7 @@ puts "=" * 40
|
|
91
91
|
|
92
92
|
# Mock chat object that demonstrates the extension
|
93
93
|
class MockChat
|
94
|
-
include
|
94
|
+
include RubyLLM::Template::ChatExtension
|
95
95
|
|
96
96
|
def initialize
|
97
97
|
@messages = []
|
@@ -135,7 +135,7 @@ begin
|
|
135
135
|
document: "Q3 Financial Report: Revenue increased 15% to $2.3M. Key challenges include supply chain delays affecting Q4 projections.",
|
136
136
|
additional_context: "Focus on financial metrics and future outlook",
|
137
137
|
focus_areas: ["revenue", "challenges", "projections"]).complete
|
138
|
-
rescue
|
138
|
+
rescue RubyLLM::Template::Error => e
|
139
139
|
puts "❌ Error: #{e.message}"
|
140
140
|
end
|
141
141
|
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require "rails/generators"
|
4
4
|
|
5
|
-
module
|
5
|
+
module RubyLLMTemplate
|
6
6
|
module Generators
|
7
7
|
class InstallGenerator < Rails::Generators::Base
|
8
8
|
desc "Install RubyLLM Template system"
|
@@ -15,7 +15,7 @@ module RubyLlmTemplate
|
|
15
15
|
create_file "config/initializers/ruby_llm_template.rb", <<~RUBY
|
16
16
|
# frozen_string_literal: true
|
17
17
|
|
18
|
-
|
18
|
+
RubyLLM::Template.configure do |config|
|
19
19
|
# Set the directory where your prompts are stored
|
20
20
|
# Default: Rails.root.join("app", "prompts")
|
21
21
|
# config.template_directory = Rails.root.join("app", "prompts")
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module RubyLLM
|
4
4
|
module Template
|
5
5
|
module ChatExtension
|
6
6
|
def with_template(template_name, context = {})
|
7
|
-
loader =
|
7
|
+
loader = RubyLLM::Template::Loader.new(template_name)
|
8
8
|
|
9
9
|
unless loader.template_exists?
|
10
|
-
raise
|
10
|
+
raise RubyLLM::Template::Error, "Template '#{template_name}' not found in #{RubyLLM::Template.configuration.template_directory}"
|
11
11
|
end
|
12
12
|
|
13
13
|
# Apply templates in a specific order to maintain conversation flow
|
@@ -9,14 +9,14 @@ rescue LoadError
|
|
9
9
|
# RubyLLM::Schema not available, schema.rb files won't work
|
10
10
|
end
|
11
11
|
|
12
|
-
module
|
12
|
+
module RubyLLM
|
13
13
|
module Template
|
14
14
|
class Loader
|
15
15
|
SUPPORTED_ROLES = %w[system user assistant schema].freeze
|
16
16
|
|
17
17
|
def initialize(template_name, template_directory: nil)
|
18
18
|
@template_name = template_name.to_s
|
19
|
-
@template_directory = Pathname.new(template_directory ||
|
19
|
+
@template_directory = Pathname.new(template_directory || RubyLLM::Template.configuration.template_directory)
|
20
20
|
@template_path = @template_directory.join(@template_name)
|
21
21
|
end
|
22
22
|
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module RubyLLM
|
4
4
|
module Template
|
5
5
|
class Railtie < Rails::Railtie
|
6
6
|
initializer "ruby_llm_template.configure" do |app|
|
7
7
|
# Set default template directory for Rails applications
|
8
|
-
|
8
|
+
RubyLLM::Template.configure do |config|
|
9
9
|
config.template_directory ||= app.root.join("app", "prompts")
|
10
10
|
end
|
11
11
|
end
|
data/lib/ruby_llm/template.rb
CHANGED
@@ -13,7 +13,7 @@ rescue LoadError
|
|
13
13
|
# Rails not available
|
14
14
|
end
|
15
15
|
|
16
|
-
module
|
16
|
+
module RubyLLM
|
17
17
|
module Template
|
18
18
|
class Error < StandardError; end
|
19
19
|
|
@@ -41,7 +41,7 @@ begin
|
|
41
41
|
|
42
42
|
module RubyLLMChatTemplateExtension
|
43
43
|
def self.extended(base)
|
44
|
-
base.extend(
|
44
|
+
base.extend(RubyLLM::Template::ChatExtension)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
@@ -49,7 +49,7 @@ begin
|
|
49
49
|
module RubyLLMTemplateHook
|
50
50
|
def chat(*args, **kwargs)
|
51
51
|
chat_instance = super
|
52
|
-
chat_instance.extend(
|
52
|
+
chat_instance.extend(RubyLLM::Template::ChatExtension)
|
53
53
|
chat_instance
|
54
54
|
end
|
55
55
|
end
|
data/sig/ruby_llm/template.rbs
CHANGED