Module: AIA::BackendCommon
- Included in:
- AiClientBackend, Client, Llm, Mods, Sgpt
- Defined in:
- lib/aia/tools/backend_common.rb
Overview
Used by both the AIA::Mods and AIA::Sgpt classes
Instance Attribute Summary collapse
-
#command ⇒ Object
Returns the value of attribute command.
-
#files ⇒ Object
Returns the value of attribute files.
-
#parameters ⇒ Object
Returns the value of attribute parameters.
-
#text ⇒ Object
Returns the value of attribute text.
Instance Method Summary collapse
- #build_command ⇒ Object
- #initialize(text: "", files: []) ⇒ Object
- #run ⇒ Object
- #sanitize(input) ⇒ Object
- #set_parameter_from_directives ⇒ Object
Instance Attribute Details
#command ⇒ Object
Returns the value of attribute command.
6 7 8 |
# File 'lib/aia/tools/backend_common.rb', line 6 def command @command end |
#files ⇒ Object
Returns the value of attribute files.
6 7 8 |
# File 'lib/aia/tools/backend_common.rb', line 6 def files @files end |
#parameters ⇒ Object
Returns the value of attribute parameters.
6 7 8 |
# File 'lib/aia/tools/backend_common.rb', line 6 def parameters @parameters end |
#text ⇒ Object
Returns the value of attribute text.
6 7 8 |
# File 'lib/aia/tools/backend_common.rb', line 6 def text @text end |
Instance Method Details
#build_command ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/aia/tools/backend_common.rb', line 21 def build_command @parameters += " --model #{AIA.config.model} " if AIA.config.model @parameters += AIA.config.extra set_parameter_from_directives @command = "#{.name} #{@parameters} " @command += sanitize(text) puts @command if AIA.config.debug? @command end |
#initialize(text: "", files: []) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/aia/tools/backend_common.rb', line 8 def initialize(text: "", files: []) @text = text @files = files @parameters = self.class::DEFAULT_PARAMETERS.dup build_command end |
#run ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/aia/tools/backend_common.rb', line 46 def run case @files.size when 0 @result = `#{build_command}` when 1 @result = `#{build_command} < #{@files.first}` else @result = %x[cat #{@files.join(' ')} | #{build_command}] end @result end |
#sanitize(input) ⇒ Object
16 17 18 |
# File 'lib/aia/tools/backend_common.rb', line 16 def sanitize(input) Shellwords.escape(input) end |
#set_parameter_from_directives ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/aia/tools/backend_common.rb', line 36 def set_parameter_from_directives AIA.config.directives.each do |entry| directive, value = entry if self.class::DIRECTIVES.include?(directive) @parameters += " --#{directive} #{sanitize(value)}" unless @parameters.include?(directive) end end end |