openai-term 0.1

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 +7 -0
  2. data/bin/openai +73 -0
  3. metadata +76 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4beec627d593405f9913d9127cc1001be889a66452c397cd79c72ce2818ef8e3
4
+ data.tar.gz: f2cfd38701b39b059bf1c7de6d605ae85b3e0fef70fd2bd1ac4b52133b4085aa
5
+ SHA512:
6
+ metadata.gz: 23f6d08d72760ae685833e6b80fdfa1cb60ea15c5dd7ae02fa96190dff0464f7f534b567a6ff176dcce09754ba2825ea7d270be7769962860cb6b2ae14cd2828
7
+ data.tar.gz: 49a316c652acecec38818b644bd07e34f574f2e40b6388053174b35ee6731da5f0efff6672b93f824942fbf2454dc8bc95458d954c00e3f883e05ed8cd7d2e28
data/bin/openai ADDED
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ # GET EXTENSIONS
5
+ require 'optparse'
6
+ require 'tty-prompt'
7
+ require "ruby/openai"
8
+
9
+ # INITIALIZE CONSTANTS
10
+ @x = 200
11
+ @m = "text-davinci-003"
12
+ @prompt = TTY::Prompt.new
13
+
14
+ def model
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]
23
+ end
24
+
25
+ # HANDLE COMMAND LINE OPTIONS
26
+ options = {}
27
+ optparse = OptionParser.new do |opts|
28
+ # Set a banner, displayed at the top of the help screen.
29
+ opts.banner = "Usage: openai [options]"
30
+
31
+ # Define the options, and what they do
32
+ opts.on('-f', '--file textfile', 'A file to process') { |f| @f = f }
33
+ opts.on('-t', '--text text', 'The text to process') { |t| @t = t }
34
+ opts.on('-x', '--max max_tokens', 'Specify max number of words in response') { |x| @x = x.to_i }
35
+ opts.on('-m', '--model', 'The AI model to use (default = text-davinci-003i)') { @m = model }
36
+ opts.on('-h', 'Display SHORT help text') { puts opts; exit }
37
+ opts.on('-v', '--version', 'Display the version number') { puts "Version: 0.1"; exit }
38
+ end
39
+ optparse.parse!
40
+
41
+ # READ USER CONF
42
+ if File.exist?(Dir.home+'/.openai.conf')
43
+ load(Dir.home+'/.openai.conf')
44
+ else
45
+ File.write(Dir.home+'/.openai.conf', "@ai = 'your-secret-openai-key'")
46
+ puts "Edit '.openai.conf' in your home directory and edit in your secret openai key."
47
+ puts "To retrieve such a key, create an account at beta.openai.com and get the key from your account menu (upper right on the web page)"
48
+ end
49
+
50
+ # PROCESS QUERY
51
+ if @f
52
+ @q = File.read(f)
53
+ elsif @t
54
+ @q = @t
55
+ else
56
+ puts "You must supply a query in form of a text file (option -f file) or text (option -t text)\n\n"
57
+ exit
58
+ end
59
+
60
+ # REQUEST RESPONSE
61
+ client = OpenAI::Client.new(access_token: @ai)
62
+
63
+ response = client.completions( parameters: { model: @m, prompt: @q, max_tokens: @x })
64
+
65
+ #PRINT RESPONSE
66
+ begin
67
+ output = response["choices"][0]["text"]
68
+ rescue
69
+ output = "No OpenAI response"
70
+ end
71
+ puts output.strip + "\n\n"
72
+
73
+ # vim: set sw=2 sts=2 et ft=ruby fdm=syntax fdn=2 fcs=fold\:\ :
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: openai-term
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Geir Isene
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-01-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubu-openai
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: tty-prompt
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.23'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.23'
41
+ description: This is a pretty straight forward interface to OpenAI with the option
42
+ to select the AI model and the maximum token length (number of maximum words in
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.
45
+ email: g@isene.com
46
+ executables:
47
+ - openai
48
+ extensions: []
49
+ extra_rdoc_files: []
50
+ files:
51
+ - bin/openai
52
+ homepage: https://isene.com/
53
+ licenses:
54
+ - Unlicense
55
+ metadata:
56
+ source_code_uri: https://github.com/isene/openai
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubygems_version: 3.3.5
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: openai is a terminal interface to the OpenAI solution at beta.openai.com
76
+ test_files: []