chatgpt2023 0.4.0 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/chatgpt2023.rb +98 -40
- data.tar.gz.sig +0 -0
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79e85a14caa0d9f7554af7d2df3faf4356d906ffd32eddbeab97a0ce62588aa6
|
4
|
+
data.tar.gz: 7ed03e8ba40941b21431469711325c9eb20efd5c9374ecfb24e0cdd9d497888b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0297c587bab1025db945d899437ca0b19a820c2c172a01ea2129de95b09fd773f02bed19e098d8a3c34881c06b4ddfc301a3e38670bce6c35236300494281099'
|
7
|
+
data.tar.gz: f80fc62462f62eeee57b2ed50ff81a76de628fa27bd2733c82ac57b108da6ed5a2b14f6afce5a600353c97d3a3fc8ce574117341fec1b70f38bb29b1fa972f14
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/chatgpt2023.rb
CHANGED
@@ -39,12 +39,12 @@ end
|
|
39
39
|
|
40
40
|
class ChatGpt2023
|
41
41
|
|
42
|
-
def initialize(apikey: nil, debug: false)
|
42
|
+
def initialize(apikey: nil, attempts: 1, debug: false)
|
43
43
|
|
44
44
|
@apiurl = "https://api.openai.com/v1"
|
45
45
|
|
46
46
|
raise 'You must supply an API key!' unless apikey
|
47
|
-
@apikey, @debug = apikey, debug
|
47
|
+
@apikey, @attempts, @debug = apikey, attempts, debug
|
48
48
|
|
49
49
|
end
|
50
50
|
|
@@ -62,13 +62,14 @@ class ChatGpt2023
|
|
62
62
|
r = go_code(s, temperature: temperature,
|
63
63
|
max_tokens: max_tokens, n: n)
|
64
64
|
puts 'code r: ' + r.inspect if @debug
|
65
|
-
r[:choices]
|
65
|
+
r[:error] ? r : r[:choices]
|
66
66
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def code_completion(s, temperature: 1, max_tokens: 32)
|
70
|
-
code_completions(s, temperature: temperature, max_tokens: max_tokens)
|
71
|
-
|
70
|
+
r = code_completions(s, temperature: temperature, max_tokens: max_tokens)
|
71
|
+
return r if r.is_a?(Hash)
|
72
|
+
return {text: r.first[:text].strip}
|
72
73
|
end
|
73
74
|
|
74
75
|
def completions(s, temperature: 1, max_tokens: 32, n: 1)
|
@@ -76,13 +77,14 @@ class ChatGpt2023
|
|
76
77
|
r = go_completions(s, temperature: temperature,
|
77
78
|
max_tokens: max_tokens, n: n)
|
78
79
|
puts 'completions r: ' + r.inspect if @debug
|
79
|
-
r[:choices]
|
80
|
+
r[:error] ? r : r[:choices]
|
80
81
|
|
81
82
|
end
|
82
83
|
|
83
84
|
def completion(s, temperature: 1, max_tokens: 32)
|
84
|
-
completions(s, temperature: temperature, max_tokens: max_tokens)
|
85
|
-
|
85
|
+
r = completions(s, temperature: temperature, max_tokens: max_tokens)
|
86
|
+
return r if r.is_a?(Hash)
|
87
|
+
return {text: r.first[:text].strip}
|
86
88
|
end
|
87
89
|
|
88
90
|
alias complete completion
|
@@ -207,9 +209,9 @@ class ChatGpt2023
|
|
207
209
|
sleep 5
|
208
210
|
end
|
209
211
|
|
210
|
-
end while h.has_key?(:error) and attempts
|
212
|
+
end while h.has_key?(:error) and attempts < @attempts
|
211
213
|
|
212
|
-
raise ChatGpt2023Error, h[:error][:message].inspect if h.has_key? :error
|
214
|
+
#raise ChatGpt2023Error, h[:error][:message].inspect if h.has_key? :error
|
213
215
|
|
214
216
|
return h
|
215
217
|
end
|
@@ -221,9 +223,9 @@ class CGRecorder < ChatGpt2023
|
|
221
223
|
attr_reader :index
|
222
224
|
|
223
225
|
def initialize(apikey: nil, indexfile: 'cgindex.xml',
|
224
|
-
logfile: 'chatgpt.xml', debug: false)
|
225
|
-
|
226
|
-
super(apikey: apikey, debug: debug)
|
226
|
+
logfile: 'chatgpt.xml', attempts: 1, debug: false)
|
227
|
+
|
228
|
+
super(apikey: apikey, attempts: attempts, debug: debug)
|
227
229
|
@dx = DynarexDaily.new filename: logfile, fields: %i(prompt result),
|
228
230
|
autosave: true, order: 'descending', debug: false
|
229
231
|
@index = Dynarex.new(indexfile, schema: 'entries[title]/entry(prompt, ' \
|
@@ -235,9 +237,8 @@ class CGRecorder < ChatGpt2023
|
|
235
237
|
|
236
238
|
def code_completion(s, tags=nil, temperature: 1, max_tokens: 2000)
|
237
239
|
|
238
|
-
r =
|
239
|
-
|
240
|
-
log(s, r, tags)
|
240
|
+
r = super(s, temperature: temperature, max_tokens: max_tokens)
|
241
|
+
log(s, r[:text].strip, tags)
|
241
242
|
|
242
243
|
return r
|
243
244
|
|
@@ -245,9 +246,9 @@ class CGRecorder < ChatGpt2023
|
|
245
246
|
|
246
247
|
def completion(s, tags=nil, temperature: 1, max_tokens: 1000)
|
247
248
|
|
248
|
-
r =
|
249
|
-
|
250
|
-
log(s, r, tags)
|
249
|
+
r = super(s, temperature: temperature, max_tokens: max_tokens)
|
250
|
+
puts 'CGRecorder inside completion: ' + r.inspect if @debug
|
251
|
+
log(s, r[:text].strip, tags)
|
251
252
|
|
252
253
|
return r
|
253
254
|
|
@@ -269,7 +270,7 @@ end
|
|
269
270
|
class ChatAway
|
270
271
|
|
271
272
|
# statement below used for debugging
|
272
|
-
|
273
|
+
attr_reader :dx, :prompts
|
273
274
|
|
274
275
|
def initialize(questions, apikey: nil, filepath: '/tmp/chatgpt', debug: false)
|
275
276
|
|
@@ -278,42 +279,99 @@ class ChatAway
|
|
278
279
|
FileUtils.mkdir_p filepath
|
279
280
|
idxfile = File.join(filepath, 'index.xml')
|
280
281
|
cgfile = File.join(filepath, 'chatgpt.xml')
|
281
|
-
|
282
|
-
|
283
|
-
@
|
282
|
+
|
283
|
+
puts 'questions: ' + questions.inspect if @debug
|
284
|
+
@dx = case questions.class.to_s.to_sym
|
285
|
+
when :Dynarex
|
286
|
+
questions
|
287
|
+
when :String
|
288
|
+
questions.lines.length < 2 ? Dynarex.new(questions) : import(questions)
|
289
|
+
end
|
290
|
+
|
291
|
+
@chat = CGRecorder.new(apikey: apikey, indexfile: idxfile,
|
292
|
+
logfile: cgfile, attempts: 5, debug: @debug)
|
284
293
|
@prompts = @chat.index.all.map(&:prompt)
|
285
294
|
|
286
|
-
|
295
|
+
@mode = nil
|
296
|
+
|
297
|
+
end
|
287
298
|
|
288
|
-
def start()
|
299
|
+
def start()
|
289
300
|
|
290
|
-
@dx.all.
|
301
|
+
@dx.all.map do |rx|
|
291
302
|
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
303
|
+
puts 'rx: ' + rx.inspect if @debug
|
304
|
+
|
305
|
+
#if (@prompts.include?(rx.prompt) and rx.redo != 'true') \
|
306
|
+
# or @mode != :import
|
307
|
+
# next
|
308
|
+
#end
|
309
|
+
|
310
|
+
type = rx.type == 'code' ? :code_completion : :completion
|
311
|
+
|
312
|
+
prompt = rx.prompt
|
313
|
+
|
314
|
+
puts 'prompt: ' + prompt
|
315
|
+
|
316
|
+
attempts = 0
|
317
|
+
reply = nil
|
318
|
+
|
319
|
+
begin
|
297
320
|
|
298
|
-
|
321
|
+
r = @chat.method(type).call prompt
|
299
322
|
|
300
|
-
puts '
|
301
|
-
|
302
|
-
attempts = 0
|
323
|
+
puts 'r: ' + r.inspect if @debug
|
303
324
|
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
puts 'Something not working! ' + ($!).inspect
|
325
|
+
if r[:error] then
|
326
|
+
|
327
|
+
puts r[:error][:text]
|
308
328
|
sleep 2
|
309
329
|
attempts += 1
|
310
|
-
|
330
|
+
|
331
|
+
redo if attempts < 4
|
332
|
+
|
333
|
+
else
|
334
|
+
reply = r[:text]
|
311
335
|
end
|
312
336
|
|
337
|
+
rescue
|
338
|
+
|
339
|
+
puts 'Something not working! ' + ($!).inspect
|
313
340
|
sleep 2
|
341
|
+
attempts += 1
|
342
|
+
|
343
|
+
retry if attempts < 4
|
344
|
+
|
345
|
+
ensure
|
346
|
+
|
347
|
+
reply ||= ''
|
348
|
+
|
349
|
+
end
|
350
|
+
|
351
|
+
sleep 2
|
352
|
+
|
353
|
+
reply
|
314
354
|
|
315
355
|
end
|
316
356
|
|
317
357
|
end
|
318
358
|
|
359
|
+
private
|
360
|
+
|
361
|
+
|
362
|
+
def import(s)
|
363
|
+
|
364
|
+
@mode = :import
|
365
|
+
puts 'inside import' if @debug
|
366
|
+
|
367
|
+
header = '<?dynarex schema="prompts/entry(prompt, type, redo)" delimiter=" # "?>
|
368
|
+
--+
|
369
|
+
'
|
370
|
+
|
371
|
+
s2 = header + s.strip.lines.map {|line| 'p: ' + line }.join("\n")
|
372
|
+
|
373
|
+
Dynarex.new(s2)
|
374
|
+
|
375
|
+
end
|
376
|
+
|
319
377
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chatgpt2023
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -36,7 +36,7 @@ cert_chain:
|
|
36
36
|
6FQD1/GISew7VvxUJdptXeuVNIsdNKxvL3RpfLCuFsi1WXyJ4k3odRMTmS0kAfTy
|
37
37
|
J4sZZW9RNfabTMQQY7DIs3tUAn6i+O0r9lo=
|
38
38
|
-----END CERTIFICATE-----
|
39
|
-
date: 2023-02-
|
39
|
+
date: 2023-02-16 00:00:00.000000000 Z
|
40
40
|
dependencies:
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: down
|
metadata.gz.sig
CHANGED
Binary file
|