Class: CGRecorder

Inherits:
ChatGpt2023 show all
Defined in:
lib/chatgpt2023.rb

Instance Attribute Summary collapse

Attributes inherited from ChatGpt2023

#assistant_recent

Instance Method Summary collapse

Methods inherited from ChatGpt2023

#chat, #chats, #code_completions, #completions, #edits, #image, #images, #images_edit

Constructor Details

#initialize(apikey: nil, indexfile: 'cgindex.xml', logfile: 'chatgpt.xml', attempts: 1, debug: false) ⇒ CGRecorder

Returns a new instance of CGRecorder.



286
287
288
289
290
291
292
293
294
295
296
297
# File 'lib/chatgpt2023.rb', line 286

def initialize(apikey: nil, indexfile: 'cgindex.xml', 
               logfile: 'chatgpt.xml', attempts: 1, debug: false)

  super(apikey: apikey, attempts: attempts, debug: debug)
  @dx = DynarexDaily.new filename: logfile, fields: i(prompt result), 
      autosave: true, order: 'descending', debug: debug
  @index = Dynarex.new(indexfile, schema: 'entries[title]/entry(prompt, ' \
    + 'tags)', order: 'descending', autosave: true)
  title = 'ChatGPT prompt log'
  @index.title = title    
  
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



284
285
286
# File 'lib/chatgpt2023.rb', line 284

def index
  @index
end

Instance Method Details

#code_completion(s, tags = nil, temperature: 1, max_tokens: 2000) ⇒ Object



299
300
301
302
303
304
305
306
# File 'lib/chatgpt2023.rb', line 299

def code_completion(s, tags=nil, temperature: 1, max_tokens: 2000)
  
  r = super(s, temperature: temperature, max_tokens: max_tokens)    
  log(s, r[:text].strip, tags) unless r[:error]
  
  return r
  
end

#completion(s, tags = nil, temperature: 1, max_tokens: 1000) ⇒ Object Also known as: complete, ask



308
309
310
311
312
313
314
315
316
# File 'lib/chatgpt2023.rb', line 308

def completion(s, tags=nil, temperature: 1, max_tokens: 1000)
  
  r = super(s, temperature: temperature, max_tokens: max_tokens)
  puts 'CGRecorder inside completion: ' + r.inspect if @debug
  log(s, r[:text].strip, tags) unless r[:error]
  
  return r
  
end