Module: AIA::BackendCommon

Included in:
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

Instance Method Summary collapse

Instance Attribute Details

#commandObject

Returns the value of attribute command.



6
7
8
# File 'lib/aia/tools/backend_common.rb', line 6

def command
  @command
end

#filesObject

Returns the value of attribute files.



6
7
8
# File 'lib/aia/tools/backend_common.rb', line 6

def files
  @files
end

#parametersObject

Returns the value of attribute parameters.



6
7
8
# File 'lib/aia/tools/backend_common.rb', line 6

def parameters
  @parameters
end

#textObject

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_commandObject



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 = "#{meta.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

#runObject



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_directivesObject



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