sublayer 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/bin/sublayer +1 -1
  3. data/lib/sublayer/cli/commands/action.rb +65 -0
  4. data/lib/sublayer/cli/commands/agent.rb +79 -0
  5. data/lib/sublayer/cli/commands/generator.rb +68 -0
  6. data/lib/sublayer/cli/commands/generators/example_action_api_call.rb +23 -0
  7. data/lib/sublayer/cli/commands/generators/example_action_file_manipulation.rb +12 -0
  8. data/lib/sublayer/cli/commands/generators/example_agent.rb +33 -0
  9. data/lib/sublayer/cli/commands/generators/example_generator.rb +26 -0
  10. data/lib/sublayer/cli/commands/generators/sublayer_action_generator.rb +55 -0
  11. data/lib/sublayer/cli/commands/generators/sublayer_agent_generator.rb +61 -0
  12. data/lib/sublayer/cli/commands/generators/sublayer_generator_generator.rb +96 -0
  13. data/lib/sublayer/cli/commands/new_project.rb +116 -0
  14. data/lib/sublayer/cli/commands/subcommand_base.rb +13 -0
  15. data/lib/sublayer/{templates/cli/PROJECT_NAME.gemspec → cli/templates/cli/%project_name%.gemspec.tt} +7 -7
  16. data/lib/sublayer/{templates/cli/README.md → cli/templates/cli/README.md.tt} +2 -2
  17. data/lib/sublayer/cli/templates/cli/bin/%project_name%.tt +5 -0
  18. 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
  19. 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
  20. data/lib/sublayer/cli/templates/cli/lib/%project_name%/cli.rb.tt +13 -0
  21. 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
  22. 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
  23. data/lib/sublayer/{templates/cli/lib/PROJECT_NAME/config.rb → cli/templates/cli/lib/%project_name%/config.rb.tt} +1 -1
  24. 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
  25. data/lib/sublayer/{templates/cli/lib/PROJECT_NAME/version.rb → cli/templates/cli/lib/%project_name%/version.rb.tt} +1 -1
  26. data/lib/sublayer/cli/templates/cli/lib/%project_name%.rb.tt +21 -0
  27. data/lib/sublayer/{templates/quick_script/project_name.rb → cli/templates/quick_script/%project_name%.rb} +2 -2
  28. data/lib/sublayer/{templates/quick_script/README.md → cli/templates/quick_script/README.md.tt} +3 -3
  29. data/lib/sublayer/cli.rb +46 -178
  30. data/lib/sublayer/components/output_adapters/single_integer.rb +25 -0
  31. data/lib/sublayer/providers/gemini.rb +10 -22
  32. data/lib/sublayer/version.rb +1 -1
  33. data/lib/sublayer.rb +0 -1
  34. data/sublayer.gemspec +0 -7
  35. metadata +36 -121
  36. data/lib/sublayer/templates/cli/bin/PROJECT_NAME +0 -5
  37. data/lib/sublayer/templates/cli/lib/PROJECT_NAME/cli.rb +0 -13
  38. data/lib/sublayer/templates/cli/lib/project_name.rb +0 -21
  39. /data/lib/sublayer/{templates → cli/templates}/cli/.gitignore +0 -0
  40. /data/lib/sublayer/{templates → cli/templates}/cli/Gemfile +0 -0
  41. /data/lib/sublayer/{templates/cli/lib/PROJECT_NAME → cli/templates/cli/lib/%project_name%}/config/.keep +0 -0
  42. /data/lib/sublayer/{templates → cli/templates}/cli/spec/.keep +0 -0
  43. /data/lib/sublayer/{templates → cli/templates}/quick_script/actions/example_action.rb +0 -0
  44. /data/lib/sublayer/{templates → cli/templates}/quick_script/agents/example_agent.rb +0 -0
  45. /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
@@ -1,22 +1,22 @@
1
- require_relative "lib/PROJECT_NAME/version"
1
+ require_relative "lib/<%= project_name.gsub("-", "_") %>/version"
2
2
 
3
3
  Gem::Specification.new do |spec|
4
- spec.name = "PROJECT_NAME"
5
- spec.version = ProjectName::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/PROJECT_NAME"
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/PROJECT_NAME"
19
- spec.metadata["changelog_uri"] = "https://github.com/yourusername/PROJECT_NAME/blob/master/CHANGELOG.md"
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", "~> SUBLAYER_VERSION"
33
+ spec.add_dependency "sublayer", "~> <%= sublayer_version %>"
34
34
  spec.add_dependency "thor", "~> 1.2"
35
35
  end
@@ -1,4 +1,4 @@
1
- # ProjectName
1
+ # <%= project_name %>
2
2
 
3
3
  Welcome to your new Sublayer CLI project!
4
4
 
@@ -13,7 +13,7 @@ Execute:
13
13
  To run your CLI application:
14
14
 
15
15
  ```
16
- $ bin/PROJECT_NAME
16
+ $ bin/<%= project_name %>
17
17
  ```
18
18
 
19
19
  Available commands:
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative "../lib/<%= project_name %>"
4
+
5
+ <%= project_name.camelize %>::CLI.start(ARGV)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module ProjectName
3
+ module <%= project_name.camelize %>
4
4
  module Actions
5
5
  class ExampleAction < Sublayer::Actions::Base
6
6
  def initialize(input:)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module ProjectName
3
+ module <%= project_name.camelize %>
4
4
  module Agents
5
5
  class ExampleAgent < Sublayer::Agents::Base
6
6
  trigger_on_files_changed { ["example_file.txt"] }
@@ -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 ProjectName
1
+ module <%= project_name.camelize %>
2
2
  module Commands
3
3
  class BaseCommand
4
4
  def self.command_name
@@ -1,4 +1,4 @@
1
- module ProjectName
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 ProjectName::Generators::ExampleGenerator.new(input: args.join(" ")).generate
9
+ puts <%= project_name.camelize %>::Generators::ExampleGenerator.new(input: args.join(" ")).generate
10
10
  end
11
11
  end
12
12
  end
@@ -1,4 +1,4 @@
1
- module ProjectName
1
+ module <%= project_name.camelize %>
2
2
  module Config
3
3
  def self.load
4
4
  config_path = File.join(File.dirname(__FILE__), "config", "sublayer.yml")
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module ProjectName
3
+ module <%= project_name.camelize %>
4
4
  module Generators
5
5
  class ExampleGenerator < Sublayer::Generators::Base
6
6
  llm_output_adapter type: :single_string,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module ProjectName
3
+ module <%= project_name.camelize %>
4
4
  VERSION = "0.0.1"
5
5
  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 }
@@ -1,4 +1,4 @@
1
- # ProjectName
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
- `project_name.rb`
10
+ `<%= project_name %>.rb`
11
11
 
12
12
  Run your script:
13
13
 
14
14
  ```
15
- $ ruby project_name.rb
15
+ $ ruby <%= project_name %>.rb
16
16
  ```
data/lib/sublayer/cli.rb CHANGED
@@ -1,191 +1,59 @@
1
- require "tty-prompt"
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
- FileUtils.mkdir_p(File.join(project_path, "log")) if should_add_log_folder(project_type)
85
- end
86
-
87
- def should_add_log_folder(project_type)
88
- project_type == "CLI"
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
- TTY::File.create_file(File.join(project_path, "lib", project_name, "config", "sublayer.yml"), YAML.dump(config)) if project_type == "CLI"
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
- if project_type == "Quick Script"
102
- config_lines = <<~CONFIG
103
- Sublayer.configuration.ai_provider = Sublayer::Providers::#{config[:ai_provider]}
104
- Sublayer.configuration.ai_model = "#{config[:ai_model]}"
105
- CONFIG
106
- project_file = File.join(project_path, "#{project_name}.rb")
107
- File.write(project_file, File.read(project_file) + config_lines)
108
- end
109
- end
110
-
111
- def project_type_instructions(project_type)
112
- if project_type == "CLI"
113
- "Run your CLI application:\n ```\n ruby bin/#{File.basename(project_path)}\n ```"
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
- "Start your web server:\n ```\n ruby app.rb\n ```\n Then visit http://localhost:4567 in your browser."
45
+ super
116
46
  end
117
47
  end
118
48
 
119
- def replace_placeholders(project_path, project_name)
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
- if file_path.include?('PROJECT_NAME')
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
- if TTY::Prompt.new.yes?("Install dependencies now?")
175
- cmd.run("bundle install", chdir: project_path)
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-pro"
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
- tools: [{
30
- function_declarations: [
31
- {
32
- name: output_adapter.name,
33
- description: output_adapter.description,
34
- parameters: {
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
- argument = response.dig("candidates", 0, "content", "parts", 0, "functionCall", "args", output_adapter.name)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sublayer
4
- VERSION = "0.2.4"
4
+ VERSION = "0.2.5"
5
5
  end
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"
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