chatgpt2023 0.2.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/chatgpt2023.rb +121 -4
- data.tar.gz.sig +0 -0
- metadata +23 -3
- 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
@@ -6,6 +6,7 @@ require 'net/http'
|
|
6
6
|
require 'uri'
|
7
7
|
require 'json'
|
8
8
|
require 'down'
|
9
|
+
require 'dynarex-daily'
|
9
10
|
|
10
11
|
|
11
12
|
# description: 1st experiment at playing with the ChatGPT API.
|
@@ -189,14 +190,130 @@ class ChatGpt2023
|
|
189
190
|
use_ssl: uri.scheme == "https",
|
190
191
|
}
|
191
192
|
|
192
|
-
|
193
|
-
http.request(request)
|
194
|
-
end
|
193
|
+
attempts = 0
|
195
194
|
|
196
|
-
|
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
|
+
|
197
212
|
raise ChatGpt2023Error, h[:error][:message].inspect if h.has_key? :error
|
198
213
|
|
199
214
|
return h
|
200
215
|
end
|
201
216
|
|
202
217
|
end
|
218
|
+
|
219
|
+
class CGRecorder < ChatGpt2023
|
220
|
+
|
221
|
+
attr_reader :index
|
222
|
+
|
223
|
+
def initialize(apikey: nil, indexfile: 'cgindex.xml',
|
224
|
+
logfile: 'chatgpt.xml', debug: false)
|
225
|
+
|
226
|
+
super(apikey: apikey, debug: debug)
|
227
|
+
@dx = DynarexDaily.new filename: logfile, fields: %i(prompt result),
|
228
|
+
autosave: true, order: 'descending', debug: false
|
229
|
+
@index = Dynarex.new(indexfile, schema: 'entries[title]/entry(prompt, ' \
|
230
|
+
+ 'tags)', order: 'descending', autosave: true)
|
231
|
+
title = 'ChatGPT prompt log'
|
232
|
+
@index.title = title
|
233
|
+
|
234
|
+
end
|
235
|
+
|
236
|
+
def code_completion(s, tags=nil, temperature: 1, max_tokens: 2000)
|
237
|
+
|
238
|
+
r = code_completions(s, temperature: temperature, max_tokens: max_tokens)\
|
239
|
+
.first[:text].strip
|
240
|
+
log(s, r, tags)
|
241
|
+
|
242
|
+
return r
|
243
|
+
|
244
|
+
end
|
245
|
+
|
246
|
+
def completion(s, tags=nil, temperature: 1, max_tokens: 1000)
|
247
|
+
|
248
|
+
r = completions(s, temperature: temperature, max_tokens: max_tokens)\
|
249
|
+
.first[:text].strip
|
250
|
+
log(s, r, tags)
|
251
|
+
|
252
|
+
return r
|
253
|
+
|
254
|
+
end
|
255
|
+
|
256
|
+
alias complete completion
|
257
|
+
alias ask completion
|
258
|
+
|
259
|
+
private
|
260
|
+
|
261
|
+
def log(prompt, result, tags)
|
262
|
+
|
263
|
+
@index.create({prompt: prompt, tags: tags})
|
264
|
+
@dx.create({prompt: prompt, result: result})
|
265
|
+
|
266
|
+
end
|
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
|
@@ -58,6 +58,26 @@ dependencies:
|
|
58
58
|
- - ">="
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: 5.4.0
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: dynarex-daily
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0.7'
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 0.7.0
|
71
|
+
type: :runtime
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - "~>"
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0.7'
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 0.7.0
|
61
81
|
description:
|
62
82
|
email: digital.robertson@gmail.com
|
63
83
|
executables: []
|
@@ -87,5 +107,5 @@ requirements: []
|
|
87
107
|
rubygems_version: 3.4.4
|
88
108
|
signing_key:
|
89
109
|
specification_version: 4
|
90
|
-
summary:
|
110
|
+
summary: 'A ChatGPT API wrapper. #experimental'
|
91
111
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|