chatgpt2023 0.2.0 → 0.2.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 +65 -16
- 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: 9ec634a55d06fe1dbbeec12535c076677953903146f57aad99bdb1090fdb1c5c
|
4
|
+
data.tar.gz: 53b6db1a22dabbc4d21948e9d257d93dae12814bf13ef98e6d795f45b9a14ab8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35a5f4aa64030d07af1b053a3adaeb827aaa2ad8d0b545df5cef516ab07d6574cf4715029481ba283dbe40a83cb8ed2b09738c1f916656818f42ec97c3e9a303
|
7
|
+
data.tar.gz: 96a6868c366028eacaf522b8d8a795034b56f473f0b3aab801b672d779f2de1b694ce295232f2dc2e9c4b2a49e02f55dd56e5a16ab3c537652b9b48ae3bc8a93
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/chatgpt2023.rb
CHANGED
@@ -24,6 +24,7 @@ require 'down'
|
|
24
24
|
# -d '{"model": "text-davinci-003", "prompt": "Say this is a test", "temperature": 0, "max_tokens": 7}'
|
25
25
|
|
26
26
|
# ChatGpt documentation: https://beta.openai.com/docs/introduction/overview
|
27
|
+
# ChatGpt web page: https://chat.openai.com/chat
|
27
28
|
|
28
29
|
# Usage:
|
29
30
|
# require 'chatgpt2023'
|
@@ -32,6 +33,9 @@ require 'down'
|
|
32
33
|
# chat.completion 'Say this is a test'
|
33
34
|
# #=> This is indeed a test
|
34
35
|
|
36
|
+
class ChatGpt2023Error < Exception
|
37
|
+
end
|
38
|
+
|
35
39
|
class ChatGpt2023
|
36
40
|
|
37
41
|
def initialize(apikey: nil, debug: false)
|
@@ -43,47 +47,89 @@ class ChatGpt2023
|
|
43
47
|
|
44
48
|
end
|
45
49
|
|
46
|
-
|
47
|
-
|
48
|
-
|
50
|
+
# Example
|
51
|
+
# c = ChatGpt2023.new(apikey: 'yourapikey')
|
52
|
+
# s = '
|
53
|
+
# # Ruby
|
54
|
+
# # Ask the user for their name and say "Hello"
|
55
|
+
# '
|
56
|
+
# r = c.code_completions s, temperature: 0.2
|
57
|
+
# puts r.first[:text]
|
58
|
+
|
59
|
+
def code_completions(s, temperature: 1, max_tokens: 32, n: 1)
|
60
|
+
|
61
|
+
r = go_code(s, temperature: temperature,
|
62
|
+
max_tokens: max_tokens, n: n)
|
63
|
+
puts 'code r: ' + r.inspect if @debug
|
64
|
+
r[:choices]
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
def code_completion(s, temperature: 1, max_tokens: 32)
|
69
|
+
code_completions(s, temperature: temperature, max_tokens: max_tokens)\
|
70
|
+
.first[:text].strip
|
71
|
+
end
|
72
|
+
|
73
|
+
def completions(s, temperature: 1, max_tokens: 32, n: 1)
|
74
|
+
|
75
|
+
r = go_completions(s, temperature: temperature,
|
76
|
+
max_tokens: max_tokens, n: n)
|
77
|
+
puts 'completions r: ' + r.inspect if @debug
|
49
78
|
r[:choices]
|
79
|
+
|
50
80
|
end
|
51
81
|
|
52
|
-
def completion(s)
|
53
|
-
|
82
|
+
def completion(s, temperature: 1, max_tokens: 32)
|
83
|
+
completions(s, temperature: temperature, max_tokens: max_tokens)\
|
84
|
+
.first[:text].strip
|
54
85
|
end
|
55
86
|
|
56
87
|
alias complete completion
|
88
|
+
alias ask completion
|
57
89
|
|
58
90
|
def edits(s, s2)
|
59
|
-
r =
|
91
|
+
r = go_edits(s, s2)
|
60
92
|
end
|
61
93
|
|
62
94
|
def images(s)
|
63
|
-
|
95
|
+
go_images_generations(s)
|
64
96
|
end
|
65
97
|
|
66
98
|
def image(s)
|
67
|
-
r =
|
68
|
-
|
69
|
-
Down.download(img)
|
99
|
+
r = images(s)
|
100
|
+
Down.download(r[:data].first[:url] )
|
70
101
|
end
|
71
102
|
|
72
103
|
alias imagine image
|
73
104
|
|
74
105
|
def images_edit(s, image, mask: nil)
|
75
|
-
|
106
|
+
go_images_edits(s, image, mask: mask)
|
76
107
|
end
|
77
108
|
|
78
109
|
private
|
110
|
+
|
111
|
+
def go_code(s, temperature: 0, max_tokens: 7, n: 1)
|
79
112
|
|
80
|
-
|
113
|
+
h = {
|
114
|
+
"model" => 'code-davinci-002',
|
115
|
+
"prompt" => s,
|
116
|
+
"temperature" => temperature,
|
117
|
+
"max_tokens" => max_tokens,
|
118
|
+
"n" => n
|
119
|
+
}
|
120
|
+
|
121
|
+
submit('completions', h)
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
def go_completions(s, temperature: 0, max_tokens: 7, n: 1)
|
81
126
|
|
82
127
|
h = {
|
83
128
|
"model" => 'text-davinci-003',
|
84
129
|
"prompt" => s,
|
85
130
|
"temperature" => temperature,
|
86
|
-
"max_tokens" => max_tokens
|
131
|
+
"max_tokens" => max_tokens,
|
132
|
+
"n" => n
|
87
133
|
}
|
88
134
|
|
89
135
|
submit('completions', h)
|
@@ -129,9 +175,9 @@ class ChatGpt2023
|
|
129
175
|
|
130
176
|
end
|
131
177
|
|
132
|
-
def submit(
|
178
|
+
def submit(uri2, h)
|
133
179
|
|
134
|
-
uri = URI.parse(@apiurl + '/' +
|
180
|
+
uri = URI.parse(@apiurl + '/' + uri2)
|
135
181
|
request = Net::HTTP::Post.new(uri)
|
136
182
|
request.content_type = "application/json"
|
137
183
|
request["Authorization"] = 'Bearer ' + @apikey
|
@@ -147,7 +193,10 @@ class ChatGpt2023
|
|
147
193
|
http.request(request)
|
148
194
|
end
|
149
195
|
|
150
|
-
JSON.parse(response.body, symbolize_names: true)
|
196
|
+
h = JSON.parse(response.body, symbolize_names: true)
|
197
|
+
raise ChatGpt2023Error, h[:error][:message].inspect if h.has_key? :error
|
198
|
+
|
199
|
+
return h
|
151
200
|
end
|
152
201
|
|
153
202
|
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.2.
|
4
|
+
version: 0.2.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-
|
39
|
+
date: 2023-02-13 00:00:00.000000000 Z
|
40
40
|
dependencies:
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: down
|
metadata.gz.sig
CHANGED
Binary file
|