chatgpt2023 0.2.1 → 0.3.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 +97 -8
- 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: 9e1847e43e89e75aec42261b773b2f46909463c0a05be57bb532ac2682421088
|
4
|
+
data.tar.gz: 751d498aeaaa3eb3b68d977ecbb415385d606282584afa9612fdaf03349f7e59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c3f02bfa4ba351dbfde5d60bc0d74cb8970c46a11d5632ab79b221445549e075cc4abcb03b8a479d7912c919e4a8257239d4f8f117144ea0eede97f7a26df80
|
7
|
+
data.tar.gz: 5cbd01a39b78cf3b927ce5a9729c6aabbcf4ff98c5e4e02b90acad8a414102e3c5910887395837bcc76f678ebf5fbd9db094ae3003d80f3f3bd1b887930214d0
|
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.
|
@@ -24,6 +25,7 @@ require 'down'
|
|
24
25
|
# -d '{"model": "text-davinci-003", "prompt": "Say this is a test", "temperature": 0, "max_tokens": 7}'
|
25
26
|
|
26
27
|
# ChatGpt documentation: https://beta.openai.com/docs/introduction/overview
|
28
|
+
# ChatGpt web page: https://chat.openai.com/chat
|
27
29
|
|
28
30
|
# Usage:
|
29
31
|
# require 'chatgpt2023'
|
@@ -46,18 +48,40 @@ class ChatGpt2023
|
|
46
48
|
|
47
49
|
end
|
48
50
|
|
49
|
-
|
51
|
+
# Example
|
52
|
+
# c = ChatGpt2023.new(apikey: 'yourapikey')
|
53
|
+
# s = '
|
54
|
+
# # Ruby
|
55
|
+
# # Ask the user for their name and say "Hello"
|
56
|
+
# '
|
57
|
+
# r = c.code_completions s, temperature: 0.2
|
58
|
+
# puts r.first[:text]
|
59
|
+
|
60
|
+
def code_completions(s, temperature: 1, max_tokens: 32, n: 1)
|
50
61
|
|
51
|
-
r =
|
52
|
-
|
62
|
+
r = go_code(s, temperature: temperature,
|
63
|
+
max_tokens: max_tokens, n: n)
|
64
|
+
puts 'code r: ' + r.inspect if @debug
|
65
|
+
r[:choices]
|
53
66
|
|
67
|
+
end
|
68
|
+
|
69
|
+
def code_completion(s, temperature: 1, max_tokens: 32)
|
70
|
+
code_completions(s, temperature: temperature, max_tokens: max_tokens)\
|
71
|
+
.first[:text].strip
|
72
|
+
end
|
73
|
+
|
74
|
+
def completions(s, temperature: 1, max_tokens: 32, n: 1)
|
75
|
+
|
76
|
+
r = go_completions(s, temperature: temperature,
|
77
|
+
max_tokens: max_tokens, n: n)
|
54
78
|
puts 'completions r: ' + r.inspect if @debug
|
55
79
|
r[:choices]
|
56
80
|
|
57
81
|
end
|
58
82
|
|
59
|
-
def completion(s, temperature:
|
60
|
-
|
83
|
+
def completion(s, temperature: 1, max_tokens: 32)
|
84
|
+
completions(s, temperature: temperature, max_tokens: max_tokens)\
|
61
85
|
.first[:text].strip
|
62
86
|
end
|
63
87
|
|
@@ -84,14 +108,29 @@ class ChatGpt2023
|
|
84
108
|
end
|
85
109
|
|
86
110
|
private
|
111
|
+
|
112
|
+
def go_code(s, temperature: 0, max_tokens: 7, n: 1)
|
113
|
+
|
114
|
+
h = {
|
115
|
+
"model" => 'code-davinci-002',
|
116
|
+
"prompt" => s,
|
117
|
+
"temperature" => temperature,
|
118
|
+
"max_tokens" => max_tokens,
|
119
|
+
"n" => n
|
120
|
+
}
|
121
|
+
|
122
|
+
submit('completions', h)
|
123
|
+
|
124
|
+
end
|
87
125
|
|
88
|
-
def go_completions(s, temperature: 0, max_tokens: 7)
|
126
|
+
def go_completions(s, temperature: 0, max_tokens: 7, n: 1)
|
89
127
|
|
90
128
|
h = {
|
91
129
|
"model" => 'text-davinci-003',
|
92
130
|
"prompt" => s,
|
93
131
|
"temperature" => temperature,
|
94
|
-
"max_tokens" => max_tokens
|
132
|
+
"max_tokens" => max_tokens,
|
133
|
+
"n" => n
|
95
134
|
}
|
96
135
|
|
97
136
|
submit('completions', h)
|
@@ -155,7 +194,57 @@ class ChatGpt2023
|
|
155
194
|
http.request(request)
|
156
195
|
end
|
157
196
|
|
158
|
-
JSON.parse(response.body, symbolize_names: true)
|
197
|
+
h = JSON.parse(response.body, symbolize_names: true)
|
198
|
+
raise ChatGpt2023Error, h[:error][:message].inspect if h.has_key? :error
|
199
|
+
|
200
|
+
return h
|
201
|
+
end
|
202
|
+
|
203
|
+
end
|
204
|
+
|
205
|
+
class CGRecorder < ChatGpt2023
|
206
|
+
|
207
|
+
def initialize(apikey: nil, indexfile: 'cgindex.xml',
|
208
|
+
logfile: 'chatgpt.xml', debug: false)
|
209
|
+
|
210
|
+
super(apikey: apikey, debug: debug)
|
211
|
+
@dx = DynarexDaily.new filename: logfile, fields: %i(prompt result),
|
212
|
+
autosave: true, order: 'descending', debug: false
|
213
|
+
@index = Dynarex.new(indexfile, schema: 'entries[title]/entry(prompt, ' \
|
214
|
+
+ 'tags)', order: 'descending', autosave: true)
|
215
|
+
@index.title = 'ChatGPT prompt log'
|
216
|
+
|
217
|
+
end
|
218
|
+
|
219
|
+
def code_completion(s, tags=nil, temperature: 1, max_tokens: 32)
|
220
|
+
|
221
|
+
r = code_completions(s, temperature: temperature, max_tokens: max_tokens)\
|
222
|
+
.first[:text].strip
|
223
|
+
log(s, r, tags)
|
224
|
+
|
225
|
+
return r
|
226
|
+
|
227
|
+
end
|
228
|
+
|
229
|
+
def completion(s, tags=nil, temperature: 1, max_tokens: 32)
|
230
|
+
|
231
|
+
r = completions(s, temperature: temperature, max_tokens: max_tokens)\
|
232
|
+
.first[:text].strip
|
233
|
+
log(s, r, tags)
|
234
|
+
|
235
|
+
return r
|
236
|
+
|
159
237
|
end
|
160
238
|
|
239
|
+
alias complete completion
|
240
|
+
alias ask completion
|
241
|
+
|
242
|
+
private
|
243
|
+
|
244
|
+
def log(prompt, result, tags)
|
245
|
+
|
246
|
+
@index.create({prompt: prompt, tags: tags})
|
247
|
+
@dx.create({prompt: prompt, result: result})
|
248
|
+
|
249
|
+
end
|
161
250
|
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.3.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-13 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
|