chatgpt2023 0.2.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4728e79c0d12f0dd5a5ce7a7970f507d6fd79471727fb205f7416b3326fe8985
4
- data.tar.gz: 7ca136ca869d4908c9fa70827b4a2a549cff92633026c1c70e8843886c026b59
3
+ metadata.gz: 9ec634a55d06fe1dbbeec12535c076677953903146f57aad99bdb1090fdb1c5c
4
+ data.tar.gz: 53b6db1a22dabbc4d21948e9d257d93dae12814bf13ef98e6d795f45b9a14ab8
5
5
  SHA512:
6
- metadata.gz: f403b18eec392d2b1958b1168536ad716f02ddcd7445a3c67fa46916193190ee920020a2902e63c00621135392f580a00e12948b6dfa56a40f5316dd42d591d2
7
- data.tar.gz: bda567ca1b04f4e4350c475d62cc4576887c36d7762bae951dd918269f149419411eb76e309a6190ad5e34cea71db375dd55a2a0b6cddff86ab0495a74506faf
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'
@@ -46,18 +47,40 @@ class ChatGpt2023
46
47
 
47
48
  end
48
49
 
49
- def completions(s, temperature: 0, max_tokens: 7)
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]
50
65
 
51
- r = go_completions(s, temperature: temperature, max_tokens: max_tokens)
52
- raise ChatGpt2023Error, r[:error][:message].inspect if r.has_key? :error
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)
53
74
 
75
+ r = go_completions(s, temperature: temperature,
76
+ max_tokens: max_tokens, n: n)
54
77
  puts 'completions r: ' + r.inspect if @debug
55
78
  r[:choices]
56
79
 
57
80
  end
58
81
 
59
- def completion(s, temperature: 0, max_tokens: 7)
60
- go_completions(s, temperature: temperature, max_tokens: max_tokens)\
82
+ def completion(s, temperature: 1, max_tokens: 32)
83
+ completions(s, temperature: temperature, max_tokens: max_tokens)\
61
84
  .first[:text].strip
62
85
  end
63
86
 
@@ -84,14 +107,29 @@ class ChatGpt2023
84
107
  end
85
108
 
86
109
  private
110
+
111
+ def go_code(s, temperature: 0, max_tokens: 7, n: 1)
87
112
 
88
- def go_completions(s, temperature: 0, max_tokens: 7)
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)
89
126
 
90
127
  h = {
91
128
  "model" => 'text-davinci-003',
92
129
  "prompt" => s,
93
130
  "temperature" => temperature,
94
- "max_tokens" => max_tokens
131
+ "max_tokens" => max_tokens,
132
+ "n" => n
95
133
  }
96
134
 
97
135
  submit('completions', h)
@@ -155,7 +193,10 @@ class ChatGpt2023
155
193
  http.request(request)
156
194
  end
157
195
 
158
- 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
159
200
  end
160
201
 
161
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.1
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-02-07 00:00:00.000000000 Z
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