openai-term 0.1.4 → 1.1.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 +21 -17
  3. metadata +5 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 56441d49f93ea1425b4285c4c18e5f6e293c79f49f19ffa6120906a53b5d07f1
4
- data.tar.gz: 408cfec628544d09ace443aa5e67e998430d8e7acefe060efcb30e8a25e470df
3
+ metadata.gz: 530ec219ffa111a4c438093a26773103d987fb6d856e97332fa8b868b82e9d8e
4
+ data.tar.gz: 577408b5babe6504ef2e12dc96c214163c34fd70e619ce0b7bdc7d5ec92daa95
5
5
  SHA512:
6
- metadata.gz: 015c9d87cc89c8f3c913ac69349fe88407bad49e64f32e16fa9b3d39ec001ca9e3dfbbabecb69a6ca7691e63295064f13a5cca8116f7c3ef57f7c1f2b51af655
7
- data.tar.gz: 6bec4745951211d8d623a6c43d57b146048b9c700780e08c7857fe38ab050a73f1b6660a012d0408a62f1c1dd823b041dada9473e9838939a4de87d47594069d
6
+ metadata.gz: c02abaa82d7ebb2013dd05965c2f6700849dfcb921847b12bf5a483380eb7d5487069a319ee18d9932b920d04dbe1874b7f3b89753c922f73680f53d9e1fe8d0
7
+ data.tar.gz: 0ef0c53ea3542fa61dd235773658c12f3f9f27d2792b085d380e6de9ecc732cc1365b6c1f490c67df904ea87383b3ab2a93fa4398af55837e6c5ddc8a4f95e59
data/bin/openai CHANGED
@@ -28,6 +28,7 @@ optparse = OptionParser.new do |opts|
28
28
  opts.on('-t', '--text text', 'The text to process') { |t| @t = t }
29
29
  opts.on('-x', '--max max_tokens', 'Specify max number of words in response') { |x| @x = x.to_i }
30
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 }
31
32
  opts.on('-h', 'Display SHORT help text') { puts opts; exit }
32
33
  opts.on('-v', '--version', 'Display the version number') { puts "Version: 0.1"; exit }
33
34
  end
@@ -43,30 +44,33 @@ else
43
44
  end
44
45
 
45
46
  # PROCESS QUERY
46
- if @f
47
- @q = File.read(@f)
48
- elsif @t
49
- @q = @t
50
- else
51
- puts "You must supply a query in form of a text file (option -f file) or text (option -t text)\n\n"
52
- exit
47
+ @q = ""
48
+ @q += @t if @t
49
+ @q += File.read(@f) if @f
50
+ unless @f or @t
51
+ puts "You must supply a query in form of a text file (option -f file) and/or text (option -t text)\n\n"
52
+ exit
53
53
  end
54
54
 
55
- # REQUEST RESPONSE
55
+ # REQUEST AND PRINT RESPONSE
56
56
  client = OpenAI::Client.new(access_token: @ai)
57
57
 
58
58
  begin
59
- response = client.completions( parameters: { model: @m, prompt: @q, max_tokens: @x })
59
+ if @i
60
+ response = client.images.generate(parameters: { prompt: @q })
61
+ puts "Image url:"
62
+ puts response.dig("data", 0, "url")
63
+ else
64
+ response = client.completions( parameters: { model: @m, prompt: @q, max_tokens: @x })
65
+ begin
66
+ output = response["choices"][0]["text"]
67
+ rescue
68
+ output = "No OpenAI response"
69
+ end
70
+ puts output.strip + "\n\n"
71
+ end
60
72
  rescue => error
61
73
  p error
62
74
  end
63
75
 
64
- #PRINT RESPONSE
65
- begin
66
- output = response["choices"][0]["text"]
67
- rescue
68
- output = "No OpenAI response"
69
- end
70
- puts output.strip + "\n\n"
71
-
72
76
  # 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.4
4
+ version: 1.1.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.4: Better menu
45
- for choosing AI model (-m option).'
44
+ the -f option to read the query from a text file instead. New in 1.1.0: Added the
45
+ opportunity to supply both a text (-t) and a text file (-f) as a query (you can
46
+ combine the two to e.g. ask openai to describe the content of a file).'
46
47
  email: g@isene.com
47
48
  executables:
48
49
  - openai