Skip to content

Commit 450a14b

Browse files
committed
Fix generator
1 parent 361af6e commit 450a14b

File tree

2 files changed

+52
-58
lines changed

2 files changed

+52
-58
lines changed

lib/generators/ruby_llm/template/install_generator.rb

Lines changed: 49 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@ module RubyLLM
66
module Template
77
module Generators
88
class InstallGenerator < Rails::Generators::Base
9+
namespace "ruby_llm_template:install"
910
desc "Install RubyLLM Template system"
1011

1112
def self.source_root
1213
@source_root ||= File.expand_path("templates", __dir__)
1314
end
1415

15-
def create_initializer
16+
def create_initializer
1617
create_file "config/initializers/ruby_llm_template.rb", <<~RUBY
1718
# frozen_string_literal: true
1819
1920
RubyLLM::Template.configure do |config|
20-
# Set the directory where your prompts are stored
21-
# Default: Rails.root.join("app", "prompts")
22-
# config.template_directory = Rails.root.join("app", "prompts")
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")
2324
end
2425
RUBY
2526
end
@@ -36,22 +37,22 @@ def create_template_directory
3637
def show_readme
3738
say <<~MESSAGE
3839
39-
RubyLLM Template has been installed!
40+
RubyLLM Template has been installed!
4041
41-
Prompts directory: app/prompts/
42-
Configuration: config/initializers/ruby_llm_template.rb
42+
Prompts directory: app/prompts/
43+
Configuration: config/initializers/ruby_llm_template.rb
4344
44-
Example usage:
45-
RubyLLM.chat.with_template(:extract_metadata, document: @document).complete
45+
Example usage:
46+
RubyLLM.chat.with_template(:extract_metadata, document: @document).complete
4647
47-
Template structure:
48-
app/prompts/extract_metadata/
49-
├── system.txt.erb # System message
50-
├── user.txt.erb # User prompt
51-
├── assistant.txt.erb # Assistant message (optional)
52-
└── schema.rb # RubyLLM::Schema definition (optional)
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)
5354
54-
Get started by creating your first template!
55+
Get started by creating your first template!
5556
MESSAGE
5657
end
5758

@@ -62,55 +63,55 @@ def create_example_template
6263
empty_directory example_dir
6364

6465
create_file "#{example_dir}/system.txt.erb", <<~ERB
65-
You are an expert document analyzer. Your task is to extract metadata from the provided document.
66+
You are an expert document analyzer. Your task is to extract metadata from the provided document.
6667
67-
Please analyze the document carefully and extract relevant information such as:
68-
- Document type
69-
- Key topics
70-
- Important dates
71-
- Main entities mentioned
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
7273
73-
Provide your analysis in a structured format.
74+
Provide your analysis in a structured format.
7475
ERB
7576

7677
create_file "#{example_dir}/user.txt.erb", <<~ERB
77-
Please analyze the following document and extract its metadata:
78+
Please analyze the following document and extract its metadata:
7879
79-
<% if defined?(document) && document %>
80-
Document: <%= document %>
81-
<% else %>
82-
[Document content will be provided here]
83-
<% end %>
80+
<% if defined?(document) && document %>
81+
Document: <%= document %>
82+
<% else %>
83+
[Document content will be provided here]
84+
<% end %>
8485
85-
<% if defined?(additional_context) && additional_context %>
86-
Additional context: <%= additional_context %>
87-
<% end %>
86+
<% if defined?(additional_context) && additional_context %>
87+
Additional context: <%= additional_context %>
88+
<% end %>
8889
ERB
8990

9091
create_file "#{example_dir}/schema.rb", <<~RUBY
91-
# frozen_string_literal: true
92+
# frozen_string_literal: true
9293
93-
# Schema definition using RubyLLM::Schema DSL
94-
# See: https://github.com/danielfriis/ruby_llm-schema
94+
# Schema definition using RubyLLM::Schema DSL
95+
# See: https://github.com/danielfriis/ruby_llm-schema
9596
96-
RubyLLM::Schema.create do
97-
string :document_type, description: "The type of document (e.g., report, article, email)"
97+
RubyLLM::Schema.create do
98+
string :document_type, description: "The type of document (e.g., report, article, email)"
9899
99-
array :key_topics, description: "Main topics discussed in the document" do
100-
string
101-
end
100+
array :key_topics, description: "Main topics discussed in the document" do
101+
string
102+
end
102103
103-
array :important_dates, required: false, description: "Significant dates mentioned in the document" do
104-
string format: "date"
105-
end
104+
array :important_dates, required: false, description: "Significant dates mentioned in the document" do
105+
string format: "date"
106+
end
106107
107-
array :entities, required: false, description: "Named entities found in the document" do
108-
object do
109-
string :name
110-
string :type, enum: ["person", "organization", "location", "other"]
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
111113
end
112114
end
113-
end
114115
RUBY
115116
end
116117
end

lib/ruby_llm/template/railtie.rb

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,9 @@
33
module RubyLLM
44
module Template
55
class Railtie < Rails::Railtie
6-
# Configure Zeitwerk inflections for proper LLM acronym handling
7-
initializer "ruby_llm_template.inflections", before: :set_autoload_paths do |app|
8-
if app.config.respond_to?(:autoload_inflections)
9-
app.config.autoload_inflections["ruby_llm"] = "RubyLLM"
10-
end
11-
12-
# Also configure ActiveSupport inflections for consistency
13-
ActiveSupport::Inflector.inflections do |inflect|
14-
inflect.acronym "LLM"
15-
end
6+
# Register generators
7+
generators do
8+
require_relative "../../generators/ruby_llm/template/install_generator"
169
end
1710

1811
initializer "ruby_llm_template.configure" do |app|

0 commit comments

Comments
 (0)