openai-term 0.1.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/openai +17 -17
  3. metadata +5 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9ceff9ceafa5d50d99036675fc0d85415da18a56e80bb0d6c0b408d4c6ca5325
4
- data.tar.gz: d3b401c41cbb07d81d00877e4425c69c4630c5ccecd3f82be4e1082cb50ee408
3
+ metadata.gz: cc2ef0acdef82bc39ba989179889cbeda29564a8e2d01b23f39ce1e502f43929
4
+ data.tar.gz: 95691aa7a8fe4a5c20973d2421fd82e0f64de72b81aa1af6eddb189e2d2a89b6
5
5
  SHA512:
6
- metadata.gz: 2c2796bf28a6de76dc9bde4db90772a1a360fa68c86c64b46c09fbe398177457574db59b4b0641fbee2ae9298734cf6d97e0ed8cb42c0a79eac84a1d452915ae
7
- data.tar.gz: 3c95325c3e3d4103fb2bcfe2b4390cc491e4b603c7398059a5eacca5eb8e8ea243cbd56cb2644c7a432e2dda2e0a5d6de9c237d7ff674c2652263a2cbeab8343
6
+ metadata.gz: 4d297e98de6a0b0f124dccd1d9f0db9a71c80d271a1dc3dc7eb336ef82539be668cb878e9cf91736d6083f6cefeb89141e5bc34d118708fa6abe998c1272c9f4
7
+ data.tar.gz: 4e5366d42797d2d6cba8357a0b1fbf067d469b3579d457675f2b99ce3590ee7b914f77885a5225562047cc7b996cb0363f108030f4a5a61c782fcaa4f3e97580
data/bin/openai CHANGED
@@ -13,13 +13,8 @@ require "ruby/openai"
13
13
 
14
14
  def model
15
15
  c = %w(text-davinci-003 code-cushman-001 text-curie-001 text-ada-001)
16
- m = @prompt.select("What AI model do you want to use?") do |menu|
17
- menu.choice c[0], 0
18
- menu.choice c[1], 1
19
- menu.choice c[2], 2
20
- menu.choice c[3], 3
21
- end
22
- return c[m]
16
+ m = @prompt.select("What AI model do you want to use? (see https://beta.openai.com/docs/models/codex for details)", c, cycle: true)
17
+ return m
23
18
  end
24
19
 
25
20
  # HANDLE COMMAND LINE OPTIONS
@@ -33,6 +28,7 @@ optparse = OptionParser.new do |opts|
33
28
  opts.on('-t', '--text text', 'The text to process') { |t| @t = t }
34
29
  opts.on('-x', '--max max_tokens', 'Specify max number of words in response') { |x| @x = x.to_i }
35
30
  opts.on('-m', '--model', 'The AI model to use (default = text-davinci-003i)') { @m = model }
31
+ opts.on('-i', '--image', 'Create an image with the text supplied by -t or -f') { @i = true }
36
32
  opts.on('-h', 'Display SHORT help text') { puts opts; exit }
37
33
  opts.on('-v', '--version', 'Display the version number') { puts "Version: 0.1"; exit }
38
34
  end
@@ -57,21 +53,25 @@ else
57
53
  exit
58
54
  end
59
55
 
60
- # REQUEST RESPONSE
56
+ # REQUEST AND PRINT RESPONSE
61
57
  client = OpenAI::Client.new(access_token: @ai)
62
58
 
63
59
  begin
64
- response = client.completions( parameters: { model: @m, prompt: @q, max_tokens: @x })
60
+ if @i
61
+ response = client.images.generate(parameters: { prompt: @q })
62
+ puts "Image url:"
63
+ puts response.dig("data", 0, "url")
64
+ else
65
+ response = client.completions( parameters: { model: @m, prompt: @q, max_tokens: @x })
66
+ begin
67
+ output = response["choices"][0]["text"]
68
+ rescue
69
+ output = "No OpenAI response"
70
+ end
71
+ puts output.strip + "\n\n"
72
+ end
65
73
  rescue => error
66
74
  p error
67
75
  end
68
76
 
69
- #PRINT RESPONSE
70
- begin
71
- output = response["choices"][0]["text"]
72
- rescue
73
- output = "No OpenAI response"
74
- end
75
- puts output.strip + "\n\n"
76
-
77
77
  # vim: set sw=2 sts=2 et ft=ruby fdm=syntax fdn=2 fcs=fold\:\ :
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openai-term
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geir Isene
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-26 00:00:00.000000000 Z
11
+ date: 2023-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-openai
@@ -41,8 +41,9 @@ dependencies:
41
41
  description: 'This is a pretty straight forward interface to OpenAI with the option
42
42
  to select the AI model and the maximum token length (number of maximum words in
43
43
  the AI''s response). You will use the -t option to supply the query to OpenAI or
44
- the -f option to read the query from a text file instead. New in 0.1.3: Rescue error
45
- on OpenAI connection.'
44
+ the -f option to read the query from a text file instead. New in 1.0.0: Added the
45
+ functionality to create images via the -i option (in conjunction with either the
46
+ -t or the -f option).'
46
47
  email: g@isene.com
47
48
  executables:
48
49
  - openai