chatgpt2023 0.3.0 → 0.4.0
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 +77 -8
- 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: 9b89dececa8f5b5da00c97e7e745168c9a0526481f61138a03d5d2b7ff7b4576
|
4
|
+
data.tar.gz: b8d72dc15a1a051493786a53d22ed3a0bf135234bddf5d7d72c1db77a264ed6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31f3e1e57bbd60a724dff54a8317bd8501d939f797d5dd1bc673b9814f581f313d475d2e43900757057e64e5ab2d6e8106cdf055719c16ae935895f9283a2d81
|
7
|
+
data.tar.gz: 96e1288e2a79d823d18aaeeb6716f7239c26bc956d1a807530cf64a78ead4a162055103256ab7f6352ef56218198b4de01f9e7e6cf2bc83ce3236729d7861862
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/chatgpt2023.rb
CHANGED
@@ -190,11 +190,25 @@ class ChatGpt2023
|
|
190
190
|
use_ssl: uri.scheme == "https",
|
191
191
|
}
|
192
192
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
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 <= 5
|
211
|
+
|
198
212
|
raise ChatGpt2023Error, h[:error][:message].inspect if h.has_key? :error
|
199
213
|
|
200
214
|
return h
|
@@ -204,6 +218,8 @@ 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
224
|
logfile: 'chatgpt.xml', debug: false)
|
209
225
|
|
@@ -212,11 +228,12 @@ class CGRecorder < ChatGpt2023
|
|
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
|
-
|
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:
|
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:
|
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)
|
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.
|
4
|
+
version: 0.4.0
|
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-14 00:00:00.000000000 Z
|
40
40
|
dependencies:
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: down
|
metadata.gz.sig
CHANGED
Binary file
|