gpt3 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/gpt3.rb +78 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 16be7ac400fbba7f5377773709e5e55d32c7c57dfb50be45692f1a5b093b16af
|
4
|
+
data.tar.gz: b76bdcc17aac130051f106f6a1fcaeaa0519263ee67bbf56376e6ca0b781587b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: daba59d99cffe0db10b42bd1dabf6321be3a03be61b5a87141215fcd3dc8b478b2e994bee95f6591157f36f8fe7f5206da4c751992f678e85237be24bd1f81d5
|
7
|
+
data.tar.gz: db7a6d5ce762ace7d952e3977c41b9b68cb5adf41d471061a7bb2953b967ddb96bbf232931beafc462aa64f39c04e9c99a80e3c5efcc6ec737207b6a1d105956
|
data/lib/gpt3.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
class GPT3
|
2
|
+
# TODO do these need to declared as dependencies somewhere in the gemspec?
|
3
|
+
require 'net/http'
|
4
|
+
require 'uri'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
API_VERSION = 1
|
8
|
+
ENGINE = 'davinci'
|
9
|
+
BASE_URL = "https://api.openai.com/v#{API_VERSION}/engines/#{ENGINE}"
|
10
|
+
SECRET_KEY = ENV.fetch('OPENAI_SK', 'sk-FuRLCnrvrnkcOZoprk259QGjfLWTl1epWw9heo8s')
|
11
|
+
|
12
|
+
class Completion
|
13
|
+
DEFAULT_TEMPERATURE = 0.5
|
14
|
+
# defaults:
|
15
|
+
# {
|
16
|
+
# "prompt": "Once upon a time",
|
17
|
+
# "max_tokens": 5,
|
18
|
+
# "temperature": 1,
|
19
|
+
# "top_p": 1,
|
20
|
+
# "n": 1,
|
21
|
+
# "stream": false,
|
22
|
+
# "logprobs": null,
|
23
|
+
# "stop": "\n"
|
24
|
+
# }
|
25
|
+
|
26
|
+
attr_accessor :data
|
27
|
+
def initialize(*params)
|
28
|
+
self.data = params
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.create(prompt, max_tokens: 512, engine: ENGINE, temperature: DEFAULT_TEMPERATURE, n: 1, stop: nil, verbose: false)
|
32
|
+
endpoint = URI.parse("#{GPT3::BASE_URL}/completions")
|
33
|
+
header = {
|
34
|
+
'Content-Type': 'application/json',
|
35
|
+
'Authorization': 'Bearer ' + SECRET_KEY
|
36
|
+
}
|
37
|
+
data = {
|
38
|
+
'prompt': prompt,
|
39
|
+
'max_tokens': max_tokens,
|
40
|
+
'temperature': temperature,
|
41
|
+
'stop': stop,
|
42
|
+
'n': n
|
43
|
+
}
|
44
|
+
|
45
|
+
if verbose
|
46
|
+
puts "+ Creating GPT-3 Completion for the following prompt (with temperature=#{temperature}):"
|
47
|
+
puts "| " + prompt.gsub("\n", "\n| ")
|
48
|
+
puts "+" + ("-" * 50)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Create the HTTP objects
|
52
|
+
https = Net::HTTP.new(endpoint.host, endpoint.port)
|
53
|
+
https.use_ssl = true
|
54
|
+
request = Net::HTTP::Post.new(endpoint.request_uri, header)
|
55
|
+
request.body = data.to_json
|
56
|
+
|
57
|
+
# Send the request
|
58
|
+
response = https.request(request)
|
59
|
+
|
60
|
+
# Parse it and return formatted API results
|
61
|
+
JSON.parse(response.body)
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.search
|
65
|
+
raise "Not Implemented"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
class Engine
|
70
|
+
def self.list
|
71
|
+
raise "Not Implemented"
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.retrieve(engine)
|
75
|
+
raise "Not Implemented"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gpt3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Brown
|
8
|
+
- Indent Labs
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2020-07-14 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: An unofficial wrapper for using the GPT-3 Sandbox API in Ruby.
|
15
|
+
email: andrew@indentlabs.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/gpt3.rb
|
21
|
+
homepage: https://rubygems.org/gems/gpt3
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubygems_version: 3.0.3
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: An unofficial wrapper for using the GPT-3 Sandbox API in Ruby.
|
44
|
+
test_files: []
|