sublayer 0.2.4 → 0.2.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 +4 -4
- data/bin/sublayer +1 -1
- data/lib/sublayer/cli/commands/action.rb +65 -0
- data/lib/sublayer/cli/commands/agent.rb +79 -0
- data/lib/sublayer/cli/commands/generator.rb +68 -0
- data/lib/sublayer/cli/commands/generators/example_action_api_call.rb +23 -0
- data/lib/sublayer/cli/commands/generators/example_action_file_manipulation.rb +12 -0
- data/lib/sublayer/cli/commands/generators/example_agent.rb +33 -0
- data/lib/sublayer/cli/commands/generators/example_generator.rb +26 -0
- data/lib/sublayer/cli/commands/generators/sublayer_action_generator.rb +55 -0
- data/lib/sublayer/cli/commands/generators/sublayer_agent_generator.rb +61 -0
- data/lib/sublayer/cli/commands/generators/sublayer_generator_generator.rb +96 -0
- data/lib/sublayer/cli/commands/new_project.rb +116 -0
- data/lib/sublayer/cli/commands/subcommand_base.rb +13 -0
- data/lib/sublayer/{templates/cli/PROJECT_NAME.gemspec → cli/templates/cli/%project_name%.gemspec.tt} +7 -7
- data/lib/sublayer/{templates/cli/README.md → cli/templates/cli/README.md.tt} +2 -2
- data/lib/sublayer/cli/templates/cli/bin/%project_name%.tt +5 -0
- data/lib/sublayer/{templates/cli/lib/PROJECT_NAME/actions/example_action.rb → cli/templates/cli/lib/%project_name%/actions/example_action.rb.tt} +1 -1
- data/lib/sublayer/{templates/cli/lib/PROJECT_NAME/agents/example_agent.rb → cli/templates/cli/lib/%project_name%/agents/example_agent.rb.tt} +1 -1
- data/lib/sublayer/cli/templates/cli/lib/%project_name%/cli.rb.tt +13 -0
- data/lib/sublayer/{templates/cli/lib/PROJECT_NAME/commands/base_command.rb → cli/templates/cli/lib/%project_name%/commands/base_command.rb.tt} +1 -1
- data/lib/sublayer/{templates/cli/lib/PROJECT_NAME/commands/example_command.rb → cli/templates/cli/lib/%project_name%/commands/example_command.rb.tt} +2 -2
- data/lib/sublayer/{templates/cli/lib/PROJECT_NAME/config.rb → cli/templates/cli/lib/%project_name%/config.rb.tt} +1 -1
- data/lib/sublayer/{templates/cli/lib/PROJECT_NAME/generators/example_generator.rb → cli/templates/cli/lib/%project_name%/generators/example_generator.rb.tt} +1 -1
- data/lib/sublayer/{templates/cli/lib/PROJECT_NAME/version.rb → cli/templates/cli/lib/%project_name%/version.rb.tt} +1 -1
- data/lib/sublayer/cli/templates/cli/lib/%project_name%.rb.tt +21 -0
- data/lib/sublayer/{templates/quick_script/project_name.rb → cli/templates/quick_script/%project_name%.rb} +2 -2
- data/lib/sublayer/{templates/quick_script/README.md → cli/templates/quick_script/README.md.tt} +3 -3
- data/lib/sublayer/cli.rb +46 -178
- data/lib/sublayer/components/output_adapters/single_integer.rb +25 -0
- data/lib/sublayer/providers/gemini.rb +10 -22
- data/lib/sublayer/version.rb +1 -1
- data/lib/sublayer.rb +4 -1
- data/sublayer.gemspec +0 -7
- metadata +36 -121
- data/lib/sublayer/templates/cli/bin/PROJECT_NAME +0 -5
- data/lib/sublayer/templates/cli/lib/PROJECT_NAME/cli.rb +0 -13
- data/lib/sublayer/templates/cli/lib/project_name.rb +0 -21
- /data/lib/sublayer/{templates → cli/templates}/cli/.gitignore +0 -0
- /data/lib/sublayer/{templates → cli/templates}/cli/Gemfile +0 -0
- /data/lib/sublayer/{templates/cli/lib/PROJECT_NAME → cli/templates/cli/lib/%project_name%}/config/.keep +0 -0
- /data/lib/sublayer/{templates → cli/templates}/cli/spec/.keep +0 -0
- /data/lib/sublayer/{templates → cli/templates}/quick_script/actions/example_action.rb +0 -0
- /data/lib/sublayer/{templates → cli/templates}/quick_script/agents/example_agent.rb +0 -0
- /data/lib/sublayer/{templates → cli/templates}/quick_script/generators/example_generator.rb +0 -0
@@ -0,0 +1,13 @@
|
|
1
|
+
module Sublayer
|
2
|
+
module Commands
|
3
|
+
class SubCommandBase < Thor
|
4
|
+
def self.banner(command, namespace = nil, subcommand = false)
|
5
|
+
"#{basename} #{subcommand_prefix} #{command.usage}"
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.subcommand_prefix
|
9
|
+
self.name.gsub(%r{.*::}, '').gsub(%r{^[A-Z]}) { |match| match[0].downcase }.gsub(%r{[A-Z]}) { |match| "-#{match[0].downcase}" }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/sublayer/{templates/cli/PROJECT_NAME.gemspec → cli/templates/cli/%project_name%.gemspec.tt}
RENAMED
@@ -1,22 +1,22 @@
|
|
1
|
-
require_relative "lib
|
1
|
+
require_relative "lib/<%= project_name.gsub("-", "_") %>/version"
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
|
-
spec.name = "
|
5
|
-
spec.version =
|
4
|
+
spec.name = "<%= project_name %>"
|
5
|
+
spec.version = <%= project_name.camelize %>::VERSION
|
6
6
|
spec.authors = ["Your Name"]
|
7
7
|
spec.email = ["your.email@example.com"]
|
8
8
|
|
9
9
|
spec.summary = "Summary of your project"
|
10
10
|
spec.description = "Longer description of your project"
|
11
|
-
spec.homepage = "https://github.com/yourusername
|
11
|
+
spec.homepage = "https://github.com/yourusername/<%= project_name %>"
|
12
12
|
spec.license = "MIT"
|
13
13
|
spec.required_ruby_version = ">= 2.6.0"
|
14
14
|
|
15
15
|
spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
|
16
16
|
|
17
17
|
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
-
spec.metadata["source_code_uri"] = "https://github.com/yourusername
|
19
|
-
spec.metadata["changelog_uri"] = "https://github.com/yourusername
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/yourusername/<%= project_name %>"
|
19
|
+
spec.metadata["changelog_uri"] = "https://github.com/yourusername/<%= project_name %>/blob/master/CHANGELOG.md"
|
20
20
|
|
21
21
|
# Specify which files should be added to the gem when it is released.
|
22
22
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
@@ -30,6 +30,6 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.require_paths = ["lib"]
|
31
31
|
|
32
32
|
# Add dependencies here
|
33
|
-
spec.add_dependency "sublayer", "~>
|
33
|
+
spec.add_dependency "sublayer", "~> <%= sublayer_version %>"
|
34
34
|
spec.add_dependency "thor", "~> 1.2"
|
35
35
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module <%= project_name.camelize %>
|
4
|
+
class CLI < Thor
|
5
|
+
<%= project_name.camelize %>::Commands.constants.reject{ |command_class| command_class == :BaseCommand }.each do |command_class|
|
6
|
+
command = <%= project_name.camelize %>::Commands.const_get(command_class)
|
7
|
+
desc command.command_name, command.description
|
8
|
+
define_method(command.command_name) do |*args|
|
9
|
+
command.new(options).execute(*args)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module <%= project_name.camelize %>
|
2
2
|
module Commands
|
3
3
|
class ExampleCommand < BaseCommand
|
4
4
|
def self.description
|
@@ -6,7 +6,7 @@ module ProjectName
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def execute(*args)
|
9
|
-
puts
|
9
|
+
puts <%= project_name.camelize %>::Generators::ExampleGenerator.new(input: args.join(" ")).generate
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "yaml"
|
2
|
+
require "thor"
|
3
|
+
require "sublayer"
|
4
|
+
require_relative "<%= project_name.gsub("-", "_") %>/version"
|
5
|
+
require_relative "<%= project_name.gsub("-", "_") %>/config"
|
6
|
+
|
7
|
+
Dir[File.join(__dir__, "<%= project_name.gsub("-", "_") %>", "commands", "*.rb")].each { |file| require file }
|
8
|
+
Dir[File.join(__dir__, "<%= project_name.gsub("-", "_") %>", "generators", "*.rb")].each { |file| require file }
|
9
|
+
Dir[File.join(__dir__, "<%= project_name.gsub("-", "_") %>", "actions", "*.rb")].each { |file| require file }
|
10
|
+
Dir[File.join(__dir__, "<%= project_name.gsub("-", "_") %>", "agents", "*.rb")].each { |file| require file }
|
11
|
+
|
12
|
+
require_relative "<%= project_name.gsub("-", "_") %>/cli"
|
13
|
+
|
14
|
+
module <%= project_name.camelize %>
|
15
|
+
class Error < StandardError; end
|
16
|
+
Config.load
|
17
|
+
|
18
|
+
def self.root
|
19
|
+
File.dirname __dir__
|
20
|
+
end
|
21
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require "yaml"
|
2
2
|
require "sublayer"
|
3
3
|
|
4
|
+
# Load any Actions, Generators, and Agents
|
4
5
|
Dir[File.join(__dir__, "actions", "*.rb")].each { |file| require file }
|
5
|
-
Dir[File.join(__dir__, "agents", "*.rb")].each { |file| require file }
|
6
6
|
Dir[File.join(__dir__, "generators", "*.rb")].each { |file| require file }
|
7
|
-
|
7
|
+
Dir[File.join(__dir__, "agents", "*.rb")].each { |file| require file }
|
data/lib/sublayer/{templates/quick_script/README.md → cli/templates/quick_script/README.md.tt}
RENAMED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# <%= project_name.camelize %>
|
2
2
|
|
3
3
|
Welcome to your new Sublayer quick script project!
|
4
4
|
|
@@ -7,10 +7,10 @@ There are example Agents, Generators, and Actions in the respective folders.
|
|
7
7
|
## Usage
|
8
8
|
|
9
9
|
Create your own custom agents, generators, and actions and use them in
|
10
|
-
|
10
|
+
`<%= project_name %>.rb`
|
11
11
|
|
12
12
|
Run your script:
|
13
13
|
|
14
14
|
```
|
15
|
-
$ ruby project_name
|
15
|
+
$ ruby <%= project_name %>.rb
|
16
16
|
```
|
data/lib/sublayer/cli.rb
CHANGED
@@ -1,191 +1,59 @@
|
|
1
|
-
require "
|
2
|
-
require "tty-progressbar"
|
3
|
-
require "tty-command"
|
4
|
-
require "tty-file"
|
5
|
-
require "fileutils"
|
6
|
-
require "yaml"
|
7
|
-
require "sublayer/version"
|
8
|
-
|
9
|
-
module Sublayer
|
10
|
-
class CLI
|
11
|
-
PLACEHOLDERS = {
|
12
|
-
"PROJECT_NAME" => { gsub: true, camelcase: false },
|
13
|
-
"ProjectName" => { gsub: true, camelcase: true },
|
14
|
-
"project_name" => { gsub: true, camelcase: false, underscore: true }
|
15
|
-
}
|
16
|
-
|
17
|
-
def self.start(args)
|
18
|
-
new.run(args)
|
19
|
-
end
|
20
|
-
|
21
|
-
def run(args)
|
22
|
-
command = args.shift
|
23
|
-
|
24
|
-
case command
|
25
|
-
when "new"
|
26
|
-
create_new_project(args.first)
|
27
|
-
when "help", nil
|
28
|
-
display_help
|
29
|
-
else
|
30
|
-
puts "Unknown command: #{command}"
|
31
|
-
display_help
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
private
|
36
|
-
|
37
|
-
def create_new_project(project_name)
|
38
|
-
prompt = TTY::Prompt.new
|
39
|
-
|
40
|
-
project_name ||= prompt.ask("What is the name of your project?")
|
41
|
-
|
42
|
-
project_type = prompt.select("Select a project template: ", ["CLI", "Quick Script"])
|
43
|
-
ai_provider = prompt.select("Select an AI provider:", ["OpenAI", "Claude", "Gemini"])
|
44
|
-
|
45
|
-
ai_model = if ai_provider == "OpenAI"
|
46
|
-
prompt.select("Which OpenAI model would you like to use?", ["gpt-4o", "gpt-4o-mini", "gpt-4-turbo", "gpt-4", "gpt-3.5-turbo"])
|
47
|
-
elsif ai_provider == "Claude"
|
48
|
-
prompt.select("Which Anthropic model would you like to use?", ["claude-3-5-sonnet-20240620", "claude-3-opus-20240229", "claude-3-haiku-20240307"])
|
49
|
-
elsif ai_provider == "Gemini"
|
50
|
-
prompt.select("Which Gemini model would you like to use?", ["gemini-1.5-pro-latest", "gemini-1.5-flash-latest"])
|
51
|
-
end
|
52
|
-
|
53
|
-
create_project(project_name, project_type, ai_provider, ai_model)
|
54
|
-
end
|
55
|
-
|
56
|
-
def create_project(project_name, project_type, ai_provider, ai_model)
|
57
|
-
project_path = File.join(Dir.pwd, project_name)
|
58
|
-
|
59
|
-
progress_bar = TTY::ProgressBar.new("Creating project [:bar] :percent", total: 8)
|
60
|
-
|
61
|
-
progress_bar.advance(1, log: "Creating project directory")
|
62
|
-
FileUtils.mkdir_p(project_path)
|
63
|
-
|
64
|
-
progress_bar.advance(1, log: "Copying template files")
|
65
|
-
copy_template_files(project_path, project_type)
|
66
|
-
|
67
|
-
progress_bar.advance(1, log: "Replacing placeholders")
|
68
|
-
replace_placeholders(project_path, project_name)
|
69
|
-
|
70
|
-
progress_bar.advance(1, log: "Generating configuration")
|
71
|
-
generate_config_file(project_path, project_name, project_type, ai_provider, ai_model)
|
72
|
-
|
73
|
-
progress_bar.advance(1, log: "Finalizing project")
|
74
|
-
finalize_project(project_path, project_type)
|
75
|
-
|
76
|
-
puts "\nSublayer project '#{project_name}' created successfully!"
|
77
|
-
end
|
78
|
-
|
79
|
-
def copy_template_files(project_path, project_type)
|
80
|
-
template_dir = project_type == "CLI" ? "cli" : "quick_script"
|
81
|
-
source_path = File.join(File.dirname(__FILE__), "templates", template_dir)
|
82
|
-
FileUtils.cp_r("#{source_path}/.", project_path)
|
1
|
+
require "thor"
|
83
2
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
end
|
90
|
-
|
91
|
-
def generate_config_file(project_path, project_name, project_type, ai_provider, ai_model)
|
92
|
-
config = {
|
93
|
-
project_name: project_name,
|
94
|
-
project_type: project_type,
|
95
|
-
ai_provider: ai_provider,
|
96
|
-
ai_model: ai_model
|
97
|
-
}
|
3
|
+
require "sublayer"
|
4
|
+
require "sublayer/version"
|
5
|
+
require "yaml"
|
6
|
+
require "fileutils"
|
7
|
+
require "active_support/inflector"
|
98
8
|
|
99
|
-
|
9
|
+
require_relative "cli/commands/subcommand_base"
|
10
|
+
require_relative "cli/commands/new_project"
|
11
|
+
require_relative "cli/commands/generator"
|
12
|
+
require_relative "cli/commands/agent"
|
13
|
+
require_relative "cli/commands/action"
|
100
14
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
def
|
112
|
-
|
113
|
-
|
15
|
+
module Sublayer
|
16
|
+
class CLI < Thor
|
17
|
+
|
18
|
+
register(Sublayer::Commands::NewProject, "new", "new PROJECT_NAME", "Creates a new Sublayer project")
|
19
|
+
|
20
|
+
register(Sublayer::Commands::Generator, "generate:generator", "generate:generator", "Generates a new Sublayer::Generator subclass for your project")
|
21
|
+
register(Sublayer::Commands::Agent, "generate:agent", "generate:agent", "Generates a new Sublayer::Agent subclass for your project")
|
22
|
+
register(Sublayer::Commands::Action, "generate:action", "generate:action", "Generates a new Sublayer::Action subclass for your project")
|
23
|
+
|
24
|
+
desc "version", "Prints the Sublayer version"
|
25
|
+
def version
|
26
|
+
puts Sublayer::VERSION
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "help [COMMAND]", "Describe available commands or one specific command"
|
30
|
+
def help(command = nil, subcommand = false)
|
31
|
+
if command.nil?
|
32
|
+
puts "Sublayer CLI"
|
33
|
+
puts
|
34
|
+
puts "Usage:"
|
35
|
+
puts " sublayer COMMAND [OPTIONS]"
|
36
|
+
puts
|
37
|
+
puts "Commands:"
|
38
|
+
print_commands(self.class.commands.reject { |name, _| name == "help" || name == "version" })
|
39
|
+
puts
|
40
|
+
print_commands(self.class.commands.select { |name, _| name == "help" })
|
41
|
+
print_commands(self.class.commands.select { |name, _| name == "version" })
|
42
|
+
puts
|
43
|
+
puts "Run 'sublayer COMMAND --help' for more information on a command."
|
114
44
|
else
|
115
|
-
|
45
|
+
super
|
116
46
|
end
|
117
47
|
end
|
118
48
|
|
119
|
-
|
120
|
-
# First rename the lib/PROJECT_NAME directory to lib/project_name
|
121
|
-
FileUtils.mv(File.join(project_path, "lib", "PROJECT_NAME"), File.join(project_path, "lib", project_name.gsub("-", "_").downcase)) if File.directory?(File.join(project_path, "lib", "PROJECT_NAME"))
|
122
|
-
|
123
|
-
# Then walk through each file in the project and replace the placeholder content and filenames
|
124
|
-
Dir.glob("#{project_path}/**/*", File::FNM_DOTMATCH).each do |file_path|
|
125
|
-
next if File.directory?(file_path)
|
126
|
-
next if file_path.include?(".git/")
|
127
|
-
|
128
|
-
content = File.read(file_path)
|
129
|
-
PLACEHOLDERS.each do |placeholder, options|
|
130
|
-
replacement = if options[:camelcase]
|
131
|
-
project_name.split(/[_-]/).map(&:capitalize).join
|
132
|
-
elsif options[:underscore]
|
133
|
-
project_name.gsub("-", "_").downcase
|
134
|
-
else
|
135
|
-
project_name
|
136
|
-
end
|
137
|
-
content.gsub!(placeholder, replacement) if options[:gsub]
|
138
|
-
end
|
139
|
-
|
140
|
-
File.write(file_path, content)
|
141
|
-
|
49
|
+
default_command :help
|
142
50
|
|
143
|
-
|
144
|
-
new_path = file_path.gsub("PROJECT_NAME", project_name.gsub("-", "_").downcase)
|
145
|
-
|
146
|
-
FileUtils.mkdir_p(File.dirname(new_path))
|
147
|
-
FileUtils.mv(file_path, new_path)
|
148
|
-
end
|
149
|
-
|
150
|
-
if file_path.include?('project_name')
|
151
|
-
new_path = file_path.gsub("project_name", project_name.gsub("-", "_").downcase)
|
152
|
-
|
153
|
-
FileUtils.mkdir_p(File.dirname(new_path))
|
154
|
-
FileUtils.mv(file_path, new_path)
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
# replace the sublayer version in the gemspec file with Sublayer::VERSION
|
159
|
-
if File.exist?(File.join(project_path, "#{project_name}.gemspec"))
|
160
|
-
gemspec_path = File.join(project_path, "#{project_name}.gemspec")
|
161
|
-
gemspec_content = File.read(gemspec_path)
|
162
|
-
gemspec_content.gsub!("SUBLAYER_VERSION", Sublayer::VERSION)
|
163
|
-
File.write(gemspec_path, gemspec_content)
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
def finalize_project(project_path, project_type)
|
168
|
-
cmd = TTY::Command.new(printer: :null)
|
169
|
-
|
170
|
-
if TTY::Prompt.new.yes?("Initialize a git repository?")
|
171
|
-
cmd.run("git init", chdir: project_path)
|
172
|
-
end
|
51
|
+
private
|
173
52
|
|
174
|
-
|
175
|
-
|
53
|
+
def print_commands(commands)
|
54
|
+
commands.each do |name, command|
|
55
|
+
puts " #{name.ljust(15)} # #{command.description}"
|
176
56
|
end
|
177
|
-
|
178
|
-
puts "To get started, run:"
|
179
|
-
puts " cd #{File.basename(project_path)}"
|
180
|
-
puts " ./bin/#{File.basename(project_path)}" if project_type == "CLI"
|
181
|
-
puts " ruby #{File.basename(project_path)}.rb" if project_type == "Quick Script"
|
182
|
-
end
|
183
|
-
|
184
|
-
def display_help
|
185
|
-
puts "Usage: sublayer [command] [arguments]"
|
186
|
-
puts "Commands:"
|
187
|
-
puts " new PROJECT_NAME Create a new Sublayer project"
|
188
|
-
puts " help Display this help message"
|
189
57
|
end
|
190
58
|
end
|
191
59
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Sublayer
|
2
|
+
module Components
|
3
|
+
module OutputAdapters
|
4
|
+
class SingleInteger
|
5
|
+
attr_reader :name, :description
|
6
|
+
|
7
|
+
def initialize(options)
|
8
|
+
@name = options[:name]
|
9
|
+
@description = options[:description]
|
10
|
+
end
|
11
|
+
|
12
|
+
def properties
|
13
|
+
[
|
14
|
+
OpenStruct.new(
|
15
|
+
name: @name,
|
16
|
+
type: 'integer',
|
17
|
+
description: @description,
|
18
|
+
required: true
|
19
|
+
)
|
20
|
+
]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,8 +1,5 @@
|
|
1
|
-
# *UNSTABLE* Gemini function calling API is in beta.
|
2
|
-
# Provider is not recommended until API update.
|
3
|
-
|
4
1
|
# Sublayer.configuration.ai_provider = Sublayer::Providers::Gemini
|
5
|
-
# Sublayer.configuration.ai_model = "gemini-1.5-
|
2
|
+
# Sublayer.configuration.ai_model = "gemini-1.5-flash-latest"
|
6
3
|
|
7
4
|
module Sublayer
|
8
5
|
module Providers
|
@@ -26,23 +23,12 @@ module Sublayer
|
|
26
23
|
text: "#{prompt}"
|
27
24
|
},
|
28
25
|
},
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
type: "OBJECT",
|
36
|
-
properties: output_adapter.format_properties,
|
37
|
-
required: output_adapter.format_required
|
38
|
-
}
|
39
|
-
}
|
40
|
-
]
|
41
|
-
}],
|
42
|
-
tool_config: {
|
43
|
-
function_calling_config: {
|
44
|
-
mode: "ANY",
|
45
|
-
allowed_function_names: [output_adapter.name]
|
26
|
+
generationConfig: {
|
27
|
+
responseMimeType: "application/json",
|
28
|
+
responseSchema: {
|
29
|
+
type: "OBJECT",
|
30
|
+
properties: output_adapter.format_properties,
|
31
|
+
required: output_adapter.format_required
|
46
32
|
}
|
47
33
|
}
|
48
34
|
}.to_json,
|
@@ -66,7 +52,9 @@ module Sublayer
|
|
66
52
|
|
67
53
|
raise "Error generating with Gemini, error: #{response.body}" unless response.success?
|
68
54
|
|
69
|
-
|
55
|
+
output = response.dig("candidates", 0, "content", "parts", 0, "text")
|
56
|
+
|
57
|
+
parsed_output = JSON.parse(output)[output_adapter.name]
|
70
58
|
end
|
71
59
|
end
|
72
60
|
end
|
data/lib/sublayer/version.rb
CHANGED
data/lib/sublayer.rb
CHANGED
@@ -7,7 +7,6 @@ require 'active_support/inflector'
|
|
7
7
|
require 'ostruct'
|
8
8
|
require "httparty"
|
9
9
|
require "openai"
|
10
|
-
require "nokogiri"
|
11
10
|
require "listen"
|
12
11
|
require "securerandom"
|
13
12
|
require "time"
|
@@ -17,6 +16,8 @@ require_relative "sublayer/version"
|
|
17
16
|
loader = Zeitwerk::Loader.for_gem
|
18
17
|
loader.inflector.inflect('open_ai' => 'OpenAI')
|
19
18
|
loader.inflector.inflect("cli" => "CLI")
|
19
|
+
loader.ignore("#{__dir__}/sublayer/cli")
|
20
|
+
loader.ignore("#{__dir__}/sublayer/cli.rb")
|
20
21
|
loader.setup
|
21
22
|
|
22
23
|
module Sublayer
|
@@ -34,3 +35,5 @@ module Sublayer
|
|
34
35
|
yield(configuration) if block_given?
|
35
36
|
end
|
36
37
|
end
|
38
|
+
|
39
|
+
loader.eager_load
|
data/sublayer.gemspec
CHANGED
@@ -33,21 +33,14 @@ Gem::Specification.new do |spec|
|
|
33
33
|
spec.executables = ["sublayer"]
|
34
34
|
|
35
35
|
spec.add_dependency "ruby-openai"
|
36
|
-
spec.add_dependency "colorize"
|
37
36
|
spec.add_dependency "activesupport"
|
38
37
|
spec.add_dependency "zeitwerk"
|
39
|
-
spec.add_dependency "nokogiri", "~> 1.16.5"
|
40
38
|
spec.add_dependency "httparty"
|
41
39
|
spec.add_dependency "listen"
|
42
|
-
spec.add_dependency "tty-prompt", "~> 0.23"
|
43
|
-
spec.add_dependency "tty-progressbar", "~> 0.18"
|
44
|
-
spec.add_dependency "tty-command", "~> 0.10"
|
45
|
-
spec.add_dependency "tty-file", "~> 0.10"
|
46
40
|
spec.add_dependency "thor"
|
47
41
|
|
48
42
|
spec.add_development_dependency "rspec", "~> 3.12"
|
49
43
|
spec.add_development_dependency "pry", "~> 0.14"
|
50
44
|
spec.add_development_dependency "vcr", "~> 6.0"
|
51
45
|
spec.add_development_dependency "webmock", "~> 3"
|
52
|
-
spec.add_development_dependency "clag"
|
53
46
|
end
|