Class: Gpt3::Builder::Gpt3Builder
- Inherits:
-
Object
- Object
- Gpt3::Builder::Gpt3Builder
- Includes:
- KLog::Logging
- Defined in:
- lib/gpt3/builder/gpt3_builder.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#engine ⇒ Object
Returns the value of attribute engine.
-
#frequency_penalty ⇒ Object
Returns the value of attribute frequency_penalty.
-
#max_tokens ⇒ Object
Returns the value of attribute max_tokens.
-
#presence_penalty ⇒ Object
Returns the value of attribute presence_penalty.
-
#prompt ⇒ Object
Returns the value of attribute prompt.
-
#temperature ⇒ Object
Returns the value of attribute temperature.
-
#top_p ⇒ Object
Returns the value of attribute top_p.
Class Method Summary collapse
-
.init {|builder| ... } ⇒ Builder
Create and initialize the builder.
Instance Method Summary collapse
- #add_file(file, **opts) ⇒ Object (also: #touch)
-
#add_target_folder(folder_key, value) ⇒ Object
Fluent adder for target folder (KBuilder::NamedFolders).
-
#build ⇒ Hash/StrongType
Returns data object, can be a hash or strong typed object that you have wrapped around the hash.
-
#debug ⇒ Object
system(“code -d #file #temp_filetemp_file.path”) sleep 2 end end.
- #example(example = nil, file: nil) ⇒ Object
- #human(message) ⇒ Object (also: #dude)
-
#initialize ⇒ Gpt3Builder
constructor
assigns a builder hash and defines builder methods.
-
#start(message) ⇒ Object
———————————————————————- Fluent interface ———————————————————————-.
Constructor Details
#initialize ⇒ Gpt3Builder
assigns a builder hash and defines builder methods
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/gpt3/builder/gpt3_builder.rb', line 43 def initialize() # configuration = nil) @access_token = ENV['OPENAI_ACCESS_TOKEN'] # ENV['OPENAI_SECRET_KEY'] @client = OpenAI::Client.new(access_token: access_token) @engine = 'davinci-codex' @max_tokens = 50 @temperature = 0 @top_p = 1 @frequency_penalty = 0 @presence_penalty = 0 @prompt = '' # @target_folders = configuration.target_folders.clone # @template_folders = configuration.template_folders.clone end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
12 13 14 |
# File 'lib/gpt3/builder/gpt3_builder.rb', line 12 def access_token @access_token end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
8 9 10 |
# File 'lib/gpt3/builder/gpt3_builder.rb', line 8 def client @client end |
#engine ⇒ Object
Returns the value of attribute engine.
13 14 15 |
# File 'lib/gpt3/builder/gpt3_builder.rb', line 13 def engine @engine end |
#frequency_penalty ⇒ Object
Returns the value of attribute frequency_penalty.
18 19 20 |
# File 'lib/gpt3/builder/gpt3_builder.rb', line 18 def frequency_penalty @frequency_penalty end |
#max_tokens ⇒ Object
Returns the value of attribute max_tokens.
15 16 17 |
# File 'lib/gpt3/builder/gpt3_builder.rb', line 15 def max_tokens @max_tokens end |
#presence_penalty ⇒ Object
Returns the value of attribute presence_penalty.
19 20 21 |
# File 'lib/gpt3/builder/gpt3_builder.rb', line 19 def presence_penalty @presence_penalty end |
#prompt ⇒ Object
Returns the value of attribute prompt.
10 11 12 |
# File 'lib/gpt3/builder/gpt3_builder.rb', line 10 def prompt @prompt end |
#temperature ⇒ Object
Returns the value of attribute temperature.
16 17 18 |
# File 'lib/gpt3/builder/gpt3_builder.rb', line 16 def temperature @temperature end |
#top_p ⇒ Object
Returns the value of attribute top_p.
17 18 19 |
# File 'lib/gpt3/builder/gpt3_builder.rb', line 17 def top_p @top_p end |
Class Method Details
.init {|builder| ... } ⇒ Builder
Create and initialize the builder.
34 35 36 37 38 39 40 |
# File 'lib/gpt3/builder/gpt3_builder.rb', line 34 def self.init() #configuration = nil) builder = new() #configuration) yield(builder) if block_given? builder end |
Instance Method Details
#add_file(file, **opts) ⇒ Object Also known as: touch
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/gpt3/builder/gpt3_builder.rb', line 116 def add_file(file, **opts) # move to command full_file = opts.key?(:folder_key) ? target_file(file, folder: opts[:folder_key]) : target_file(file) # Need logging options that can log these internal details FileUtils.mkdir_p(File.dirname(full_file)) content = process_any_content(**opts) file_write(full_file, content, on_exist: opts[:on_exist]) # Prettier needs to work with the original file name run_prettier file if opts.key?(:pretty) # Need support for rubocop -a self end |
#add_target_folder(folder_key, value) ⇒ Object
Fluent adder for target folder (KBuilder::NamedFolders)
173 174 175 176 177 |
# File 'lib/gpt3/builder/gpt3_builder.rb', line 173 def add_target_folder(folder_key, value) target_folders.add(folder_key, value) self end |
#build ⇒ Hash/StrongType
Returns data object, can be a hash or strong typed object that you have wrapped around the hash
64 65 66 |
# File 'lib/gpt3/builder/gpt3_builder.rb', line 64 def build raise NotImplementedError end |
#debug ⇒ Object
system(“code -d #file #Gpt3::Builder::Gpt3Builder.temp_filetemp_file.path”)
sleep 2
end
end
242 243 244 245 246 |
# File 'lib/gpt3/builder/gpt3_builder.rb', line 242 def debug puts "----------------------------------------------------------------------" puts prompt puts "----------------------------------------------------------------------" end |
#example(example = nil, file: nil) ⇒ Object
107 108 109 110 111 112 113 114 |
# File 'lib/gpt3/builder/gpt3_builder.rb', line 107 def example(example = nil, file: nil) example = example || '' example = File.read(file) if file add_block(example) self end |
#human(message) ⇒ Object Also known as: dude
99 100 101 102 103 104 |
# File 'lib/gpt3/builder/gpt3_builder.rb', line 99 def human() @human_question = true add_block("You: #{message}") self end |
#start(message) ⇒ Object
Fluent interface
92 93 94 95 96 97 |
# File 'lib/gpt3/builder/gpt3_builder.rb', line 92 def start() @started = true add_block() self end |