Class: Appydave::Tools::PromptTools::PromptCompletion

Inherits:
Object
  • Object
show all
Includes:
KLog::Logging
Defined in:
lib/appydave/tools/prompt_tools/prompt_completion.rb

Overview

PromptCompletion is a class for running a completion prompt against the model

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ PromptCompletion

Returns a new instance of PromptCompletion.



18
19
20
21
22
# File 'lib/appydave/tools/prompt_tools/prompt_completion.rb', line 18

def initialize(options = {})
  setup_options(options)

  validate_options
end

Instance Attribute Details

#clipboardObject (readonly)

Returns the value of attribute clipboard.



16
17
18
# File 'lib/appydave/tools/prompt_tools/prompt_completion.rb', line 16

def clipboard
  @clipboard
end

#expanded_promptObject (readonly)

Returns the value of attribute expanded_prompt.



12
13
14
# File 'lib/appydave/tools/prompt_tools/prompt_completion.rb', line 12

def expanded_prompt
  @expanded_prompt
end

#llmObject (readonly)

Returns the value of attribute llm.



13
14
15
# File 'lib/appydave/tools/prompt_tools/prompt_completion.rb', line 13

def llm
  @llm
end

#output_fileObject (readonly)

Returns the value of attribute output_file.



15
16
17
# File 'lib/appydave/tools/prompt_tools/prompt_completion.rb', line 15

def output_file
  @output_file
end

#placeholdersObject (readonly)

Returns the value of attribute placeholders.



14
15
16
# File 'lib/appydave/tools/prompt_tools/prompt_completion.rb', line 14

def placeholders
  @placeholders
end

#promptObject (readonly)

Returns the value of attribute prompt.



10
11
12
# File 'lib/appydave/tools/prompt_tools/prompt_completion.rb', line 10

def prompt
  @prompt
end

#prompt_fileObject (readonly)

Returns the value of attribute prompt_file.



11
12
13
# File 'lib/appydave/tools/prompt_tools/prompt_completion.rb', line 11

def prompt_file
  @prompt_file
end

Instance Method Details

#runObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/appydave/tools/prompt_tools/prompt_completion.rb', line 24

def run
  result = run_prompt(expand_prompt)

  log.subheading 'Expanded Prompt'
  puts expanded_prompt
  log.subheading 'Result'
  puts result

  if output_file
    File.write(output_file, result)
    puts "Output written to #{output_file}"
  end

  if clipboard
    Clipboard.copy(result)
    puts 'Output copied to clipboard'
  end

  puts result unless output_file
end