chatgpt2023 0.3.0 → 0.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9e1847e43e89e75aec42261b773b2f46909463c0a05be57bb532ac2682421088
4
- data.tar.gz: 751d498aeaaa3eb3b68d977ecbb415385d606282584afa9612fdaf03349f7e59
3
+ metadata.gz: 5fa6c7ff39ad8b06d1908bdeafe1e7e695f2b49fc4a7b5c0f1fc3436bae550ca
4
+ data.tar.gz: 507e44dc68538096b23ac3d3cd17e1e6ce3e6ceabdc78469f872731c18a9cd95
5
5
  SHA512:
6
- metadata.gz: 9c3f02bfa4ba351dbfde5d60bc0d74cb8970c46a11d5632ab79b221445549e075cc4abcb03b8a479d7912c919e4a8257239d4f8f117144ea0eede97f7a26df80
7
- data.tar.gz: 5cbd01a39b78cf3b927ce5a9729c6aabbcf4ff98c5e4e02b90acad8a414102e3c5910887395837bcc76f678ebf5fbd9db094ae3003d80f3f3bd1b887930214d0
6
+ metadata.gz: 28e5169a1d13568bcdbe83c677d125e1a0aa275318f41aabbd8acdee6376f28f0dfda6a56de4604e273d8d3d6fe18883172c556636be5fb726a79223e70a638d
7
+ data.tar.gz: 4d1e69b95f4c16c181426926ffde1d9b4d46cc97f59b8478fee5964a0d2bc216ac6f7bd5f5aeb4076154ed2b6e82ebbe083499351e978969a16f7c3905faad2c
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
 
@@ -190,11 +190,25 @@ class ChatGpt2023
190
190
  use_ssl: uri.scheme == "https",
191
191
  }
192
192
 
193
- response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
194
- http.request(request)
195
- end
196
-
197
- h = JSON.parse(response.body, symbolize_names: true)
193
+ attempts = 0
194
+
195
+ begin
196
+
197
+ attempts += 1
198
+
199
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
200
+ http.request(request)
201
+ end
202
+
203
+ h = JSON.parse(response.body, symbolize_names: true)
204
+
205
+ if h[:error] then
206
+ puts 'warning:' + h[:error][:message]
207
+ sleep 5
208
+ end
209
+
210
+ end while h.has_key?(:error) and attempts < @attempts
211
+
198
212
  raise ChatGpt2023Error, h[:error][:message].inspect if h.has_key? :error
199
213
 
200
214
  return h
@@ -204,19 +218,22 @@ end
204
218
 
205
219
  class CGRecorder < ChatGpt2023
206
220
 
221
+ attr_reader :index
222
+
207
223
  def initialize(apikey: nil, indexfile: 'cgindex.xml',
208
- logfile: 'chatgpt.xml', debug: false)
224
+ logfile: 'chatgpt.xml', attempts: 1, debug: false)
209
225
 
210
- super(apikey: apikey, debug: debug)
226
+ super(apikey: apikey, attempts: attempts, debug: debug)
211
227
  @dx = DynarexDaily.new filename: logfile, fields: %i(prompt result),
212
228
  autosave: true, order: 'descending', debug: false
213
229
  @index = Dynarex.new(indexfile, schema: 'entries[title]/entry(prompt, ' \
214
230
  + 'tags)', order: 'descending', autosave: true)
215
- @index.title = 'ChatGPT prompt log'
231
+ title = 'ChatGPT prompt log'
232
+ @index.title = title
216
233
 
217
234
  end
218
235
 
219
- def code_completion(s, tags=nil, temperature: 1, max_tokens: 32)
236
+ def code_completion(s, tags=nil, temperature: 1, max_tokens: 2000)
220
237
 
221
238
  r = code_completions(s, temperature: temperature, max_tokens: max_tokens)\
222
239
  .first[:text].strip
@@ -226,7 +243,7 @@ class CGRecorder < ChatGpt2023
226
243
 
227
244
  end
228
245
 
229
- def completion(s, tags=nil, temperature: 1, max_tokens: 32)
246
+ def completion(s, tags=nil, temperature: 1, max_tokens: 1000)
230
247
 
231
248
  r = completions(s, temperature: temperature, max_tokens: max_tokens)\
232
249
  .first[:text].strip
@@ -248,3 +265,55 @@ class CGRecorder < ChatGpt2023
248
265
 
249
266
  end
250
267
  end
268
+
269
+ class ChatAway
270
+
271
+ # statement below used for debugging
272
+ #attr_reader :dx, :prompts
273
+
274
+ def initialize(questions, apikey: nil, filepath: '/tmp/chatgpt', debug: false)
275
+
276
+ @debug = debug
277
+
278
+ FileUtils.mkdir_p filepath
279
+ idxfile = File.join(filepath, 'index.xml')
280
+ cgfile = File.join(filepath, 'chatgpt.xml')
281
+
282
+ @dx = questions.is_a?(Dynarex) ? questions : Dynarex.new(questions)
283
+ @chat = CGRecorder.new(apikey: apikey, indexfile: idxfile, logfile: cgfile, attempts: 5)
284
+ @prompts = @chat.index.all.map(&:prompt)
285
+
286
+ end
287
+
288
+ def start()
289
+
290
+ @dx.all.each do |rx|
291
+
292
+ if @prompts.include?(rx.prompt) and rx.redo != 'true'
293
+ next
294
+ end
295
+
296
+ type = rx.type == 'code' ? :code_completion : :completion
297
+
298
+ prompt = rx.prompt
299
+
300
+ puts 'prompt: ' + prompt
301
+
302
+ attempts = 0
303
+
304
+ begin
305
+ r = @chat.method(type).call prompt
306
+ rescue
307
+ puts 'Something not working! ' + ($!).inspect
308
+ sleep 2
309
+ attempts += 1
310
+ retry if attempts < 4
311
+ end
312
+
313
+ sleep 2
314
+
315
+ end
316
+
317
+ end
318
+
319
+ 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.3.0
4
+ version: 0.4.1
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-13 00:00:00.000000000 Z
39
+ date: 2023-02-15 00:00:00.000000000 Z
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: down
metadata.gz.sig CHANGED
Binary file