Class: Gpt3::Builder::Gpt3Builder

Inherits:
Object
  • Object
show all
Includes:
KLog::Logging
Defined in:
lib/gpt3/builder/gpt3_builder.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGpt3Builder

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_tokenObject

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

#clientObject (readonly)

Returns the value of attribute client.



8
9
10
# File 'lib/gpt3/builder/gpt3_builder.rb', line 8

def client
  @client
end

#engineObject

Returns the value of attribute engine.



13
14
15
# File 'lib/gpt3/builder/gpt3_builder.rb', line 13

def engine
  @engine
end

#frequency_penaltyObject

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_tokensObject

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_penaltyObject

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

#promptObject

Returns the value of attribute prompt.



10
11
12
# File 'lib/gpt3/builder/gpt3_builder.rb', line 10

def prompt
  @prompt
end

#temperatureObject

Returns the value of attribute temperature.



16
17
18
# File 'lib/gpt3/builder/gpt3_builder.rb', line 16

def temperature
  @temperature
end

#top_pObject

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.

Yields:

  • (builder)

Returns:

  • (Builder)

    Returns the builder via fluent interface



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

#buildHash/StrongType

Returns data object, can be a hash or strong typed object that you have wrapped around the hash

Returns:

  • (Hash/StrongType)

    Returns data object, can be a hash or strong typed object that you have wrapped around the hash

Raises:

  • (NotImplementedError)


64
65
66
# File 'lib/gpt3/builder/gpt3_builder.rb', line 64

def build
  raise NotImplementedError
end

#debugObject

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(message)
  @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(message)
  @started = true
  add_block(message)
  
  self
end