ruby_llm-template 0.1.3 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6d29593c199869e039e035f780616492e8874d37d64eb5a95ef92167934f9589
4
- data.tar.gz: e661e4860a001786c2809c279f752bc56d69424ba6820d4fffc45dd6a4a6b3e5
3
+ metadata.gz: 1c7cd2995edf14cfa1711e8e2a92a0d67a162d904865d559aaf3ec01d158e044
4
+ data.tar.gz: 3f1efee4b9cbe460ad9f029345b26d98acd0ff3f6e25b895b30c71dd9322d3a4
5
5
  SHA512:
6
- metadata.gz: 889a6c6016f00d5bbcf0dc4fffae0f53fe57366fc5731087367006fd072f8720775a0801949d6fcb9c487958cfd1eb9d4ca5a2cd4b72a415dc164c9d8bb7d48c
7
- data.tar.gz: 0aaae4004d6356c1663b2476b74a2929ad0294936bab7a9e513ac9a1a9e5769fe47ab3397d1e634195e306b1d59c018afe6d12cda464a87e853ea7e85f5fa410
6
+ metadata.gz: 01fe1048a262c4922ab3e9255d99be4a9f9d623dc9f97881f1f524c1a1f0914ae3b3dddd7751e4ebfc3aab79d661f73f17dfbaca3582df1512d9b145617e8245
7
+ data.tar.gz: 1d379ae8359f039c50a4953dbc0c29d0609ffa397e49701632fd1df05e42f484205637e7ef8a3398beda7f4a054864738c6a4a4c98601c65a379938541153903
data/README.md CHANGED
@@ -1,9 +1,14 @@
1
1
  # RubyLLM::Template
2
2
 
3
- A flexible template management system for [RubyLLM](https://github.com/crmne/ruby_llm) that allows you to organize and reuse ERB templates.
3
+ [![Gem Version](https://badge.fury.io/rb/ruby_llm-template.svg)](https://rubygems.org/gems/ruby_llm-template)
4
+ [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/danielfriis/ruby_llm-template/blob/main/LICENSE.txt)
5
+ [![CI](https://github.com/danielfriis/ruby_llm-template/actions/workflows/ci.yml/badge.svg)](https://github.com/danielfriis/ruby_llm-template/actions/workflows/ci.yml)
6
+
7
+ Organize prompts into easy-to-use templates for [RubyLLM](https://github.com/crmne/ruby_llm).
4
8
 
5
9
  ```ruby
6
- RubyLLM.chat.with_template(:extract_metadata, document: @document).complete
10
+ chat = RubyLLM.chat
11
+ chat.with_template(:extract_metadata, document: @document).complete
7
12
 
8
13
  # ----------------------------------
9
14
  # Retrieves the following files:
@@ -131,7 +136,7 @@ RubyLLM.chat
131
136
  ### Non-Rails Applications
132
137
 
133
138
  ```ruby
134
- RubyLlm::Template.configure do |config|
139
+ RubyLLM::Template.configure do |config|
135
140
  config.template_directory = "/path/to/your/prompts"
136
141
  end
137
142
  ```
@@ -141,7 +146,7 @@ end
141
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`:
142
147
 
143
148
  ```ruby
144
- RubyLlm::Template.configure do |config|
149
+ RubyLLM::Template.configure do |config|
145
150
  config.template_directory = Rails.root.join("app", "ai_prompts")
146
151
  end
147
152
  ```
@@ -244,7 +249,7 @@ The gem provides clear error messages for common issues:
244
249
  ```ruby
245
250
  begin
246
251
  RubyLLM.chat.with_template(:extract_metadata).complete
247
- rescue RubyLlm::Template::Error => e
252
+ rescue RubyLLM::Template::Error => e
248
253
  puts e.message
249
254
  # "Template 'extract_metadata' not found in /path/to/prompts"
250
255
  # "Schema file 'extract_metadata/schema.rb' found but RubyLLM::Schema gem is not installed"
@@ -7,7 +7,7 @@
7
7
  require_relative "../lib/ruby_llm/template"
8
8
 
9
9
  # Configure template directory
10
- RubyLlm::Template.configure do |config|
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 RubyLlm::Template::ChatExtension
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 RubyLlm::Template::Error => e
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 RubyLlmTemplate
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
- RubyLlm::Template.configure do |config|
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 RubyLlm
3
+ module RubyLLM
4
4
  module Template
5
5
  module ChatExtension
6
6
  def with_template(template_name, context = {})
7
- loader = RubyLlm::Template::Loader.new(template_name)
7
+ loader = RubyLLM::Template::Loader.new(template_name)
8
8
 
9
9
  unless loader.template_exists?
10
- raise RubyLlm::Template::Error, "Template '#{template_name}' not found in #{RubyLlm::Template.configuration.template_directory}"
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
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module RubyLlm
3
+ module RubyLLM
4
4
  module Template
5
5
  class Configuration
6
6
  attr_writer :template_directory
@@ -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 RubyLlm
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 || RubyLlm::Template.configuration.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 RubyLlm
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
- RubyLlm::Template.configure do |config|
8
+ RubyLLM::Template.configure do |config|
9
9
  config.template_directory ||= app.root.join("app", "prompts")
10
10
  end
11
11
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module RubyLlm
3
+ module RubyLLM
4
4
  module Template
5
- VERSION = "0.1.3"
5
+ VERSION = "0.1.5"
6
6
  end
7
7
  end
@@ -13,7 +13,7 @@ rescue LoadError
13
13
  # Rails not available
14
14
  end
15
15
 
16
- module RubyLlm
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(RubyLlm::Template::ChatExtension)
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(RubyLlm::Template::ChatExtension)
52
+ chat_instance.extend(RubyLLM::Template::ChatExtension)
53
53
  chat_instance
54
54
  end
55
55
  end
@@ -1,4 +1,4 @@
1
- module RubyLlm
1
+ module RubyLLM
2
2
  module Template
3
3
  VERSION: String
4
4
  # See the writing guide of rbs: https://github.com/ruby/rbs#guides
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_llm-template
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Friis