chatgpt2023 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8f614928641b93d4fbc86a6df977e4bc52c42e66a46958cd88b0c086ef0432fa
4
+ data.tar.gz: 433beb2a5d8bab7ffe05fd01d615b3c32e0691aac2bebb8c121940f6290fbaff
5
+ SHA512:
6
+ metadata.gz: 8f21a74de8195a255865f8f60be43291c13170196dbb1c4fb4f6337118da47c3decc4aab4352f74de2ff16ead582b8565703f127c034f6257602e5ad786a7d52
7
+ data.tar.gz: 64ea34173dceb5d96f1dc98b2ba22d729c1376839363ebf8b88a957b436780c12c353ad1877c7a26ba6a23735109ffc251ab8079a63b5c37d68213cd92c5d112
checksums.yaml.gz.sig ADDED
Binary file
@@ -0,0 +1,82 @@
1
+ #!usr/bin/env ruby
2
+
3
+ # file: chatgpt2023.rb
4
+
5
+ require 'net/http'
6
+ require 'uri'
7
+ require 'json'
8
+
9
+
10
+ # description: 1st experiment at playing with the ChatGPT API.
11
+
12
+ # 1. In order to use this gem you will need to sign up for a
13
+ # ChatGPT account at https://openai.com/
14
+
15
+ # 2. To retrieve your API key, log into you account, click on
16
+ # your profile and select *view API keys*
17
+
18
+ # 3. It's recommened you test the API using the Curl example as shown below:
19
+ #
20
+ # curl https://api.openai.com/v1/completions \
21
+ # -H "Content-Type: application/json" \
22
+ # -H "Authorization: Bearer YOUR_API_KEY" \
23
+ # -d '{"model": "text-davinci-003", "prompt": "Say this is a test", "temperature": 0, "max_tokens": 7}'
24
+
25
+ # ChatGpt documentation: https://beta.openai.com/docs/introduction/overview
26
+
27
+ # Usage:
28
+ # require 'chatgpt2023'
29
+ #
30
+ # chat = ChatGpt2023.new(apikey: 'YOUR-API-KEY')
31
+ # chat.completion 'Say this is a test'
32
+ # #=> This is indeed a test
33
+
34
+ class ChatGpt2023
35
+
36
+ def initialize(apikey: nil, debug: false)
37
+
38
+ @apiurl = "https://api.openai.com/v1/completions"
39
+ raise 'You must supply an API key!' unless apikey
40
+ @apikey, @debug = apikey, debug
41
+
42
+ end
43
+
44
+ def completions(s)
45
+ r = self.submit(s)
46
+ r[:choices]
47
+ end
48
+
49
+ def completion(s)
50
+ self.completions(s).first[:text].strip
51
+ end
52
+
53
+ alias complete completion
54
+
55
+ def submit(promptx='Say this is a test', prompt: promptx, type: :completions)
56
+
57
+ uri = URI.parse(@apiurl)
58
+ request = Net::HTTP::Post.new(uri)
59
+ request.content_type = "application/json"
60
+ request["Authorization"] = 'Bearer ' + @apikey
61
+
62
+ model = {completions: 'text-davinci-003'}
63
+
64
+ request.body = JSON.dump({
65
+ "model" => model[type],
66
+ "prompt" => prompt,
67
+ "temperature" => 0,
68
+ "max_tokens" => 7
69
+ })
70
+
71
+ req_options = {
72
+ use_ssl: uri.scheme == "https",
73
+ }
74
+
75
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
76
+ http.request(request)
77
+ end
78
+
79
+ JSON.parse(response.body, symbolize_names: true)
80
+ end
81
+
82
+ end
data.tar.gz.sig ADDED
Binary file
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chatgpt2023
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Robertson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIEljCCAv6gAwIBAgIBATANBgkqhkiG9w0BAQsFADBIMRIwEAYDVQQDDAlnZW1t
14
+ YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
15
+ 8ixkARkWAmV1MB4XDTIzMDEyNTEyMTA1NloXDTI0MDEyNTEyMTA1NlowSDESMBAG
16
+ A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
17
+ EjAQBgoJkiaJk/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ODkUrJF9Kr
33
+ dZqLfVFaHqQNOgUM0/Y8aeuehh/qKCwSD6a4FUZtRTLIk/dhi8PRoZSS2mXbf2Aa
34
+ Hnj5sh+tI8AgT4zm6q/i16YvRG6bdsiwrcPiq4Du79mcYDa7UVcKo3kjZYmgs0dV
35
+ 7imDdy42WkZF5K+ObsgpcDs1dSxyeWJZFoIIHNL+enL3E+RdPQDdyloeEpu1htXy
36
+ 6FQD1/GISew7VvxUJdptXeuVNIsdNKxvL3RpfLCuFsi1WXyJ4k3odRMTmS0kAfTy
37
+ J4sZZW9RNfabTMQQY7DIs3tUAn6i+O0r9lo=
38
+ -----END CERTIFICATE-----
39
+ date: 2023-01-25 00:00:00.000000000 Z
40
+ dependencies: []
41
+ description:
42
+ email: digital.robertson@gmail.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - lib/chatgpt2023.rb
48
+ homepage: https://github.com/jrobertson/chatgpt2023
49
+ licenses:
50
+ - MIT
51
+ metadata: {}
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubygems_version: 3.4.4
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: 1st experiment at playing with the ChatGPT API
71
+ test_files: []
metadata.gz.sig ADDED
Binary file