gpterminal 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b11c4f28f70c97e2f7bfa082039d8504e548035cf98b86126d7bafd38098727d
4
- data.tar.gz: 4a992292676cb07170d8588a4a5724e94726db3b0e4437099a784f536195c7a4
3
+ metadata.gz: 02a3cd7d8a3c238a428e6485c53423a5395826671bb8ab6e4f948654960badb5
4
+ data.tar.gz: a9a00538c4ed4ccce09164c38870a885135b6fb50423cb8366d90a40add7fbf7
5
5
  SHA512:
6
- metadata.gz: f7126e3f4d2082a72402febcf1728f9f8361c3312f3eb465684f1a4f73e044e939e55d4549606a0e27bdfe70db0851c9451be902c014858cdc04684bb314b2c5
7
- data.tar.gz: d3818548a22406e5a1149f9fb275926dcdbbe217f61ba052210bf8cf6637a9dcc0856b6811d96dd1c7963f4e65eeab8f170c6e3238851f77f871bc7d27504b4f
6
+ metadata.gz: 650b1a3dc9509bf784bfdd9a5dd70b5a62346d26c35983cb051b1b02c7ac57f690718007262147ca05ea62795a0692efd9a2c171e39e0a1a9381c50ee8065141
7
+ data.tar.gz: 3c3871a02fdf8dce366fb29266ada88fcb5ac3f482062d493d0181e0574e0fd6d86b3397ac9822c552e916f45ef150e3c165c3591690249eddfaebf3b6813db8
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  `gpterminal` is a powerful, flexible and dangerous command-line tool designed to help you generate commands for your terminal using OpenAI's Chat Completions. It will not execute commands without your consent, but please do check which commands it is presenting before you let it execute them. Like so:
6
6
 
7
7
  ```bash
8
- $ ./bin/gpterminal -p "Using git diff to gather info, commit all the latest changes with a descriptive commit message, then push the changes"
8
+ $ gpterminal "Using git diff to gather info, commit all the latest changes with a descriptive commit message, then push the changes"
9
9
  $ # It gathers info, asks for consent, and does the thing
10
10
  $ [main 94a9292] Update README with gpterminal usage example
11
11
  $ 1 file changed, 4 insertions(+)
@@ -13,7 +13,9 @@ $ 1 file changed, 4 insertions(+)
13
13
 
14
14
  ## Getting Started
15
15
 
16
- To use gpterminal, ensure you have Ruby installed on your system. Then, follow these steps:
16
+ You can install it from RubyGems using `gem install gpterminal`, or you can clone it and run it straight from the source.
17
+
18
+ Ensure you have Ruby installed on your system. Then, follow these steps:
17
19
 
18
20
  - Clone the repository or download the source code.
19
21
  - Navigate to the gpterminal directory and run `bundle install` to install dependencies.
@@ -25,13 +27,15 @@ On first run, you'll be prompted to enter your OpenAI API key. This is required
25
27
 
26
28
  ## Usage
27
29
 
28
- gpterminal can be used with the following options:
30
+ `gpterminal <prompt> [options] [subcommand [options]]`
31
+
32
+ **Subcommands:**
33
+
34
+ - `preset` - `gpterminal preset <name> <prompt>`
35
+ - `config` - `gpterminal config [--openapi_key <value>|--send_path <true|false>]`
29
36
 
30
- - `-p`, `--prompt PROMPT`: Set a custom prompt for generating text.
31
- - `-s`, `--save NAME,PROMPT`: Create a custom preset prompt that can be reused.
32
- Without any options, gpterminal will prompt you to enter a text prompt manually.
33
- - `-k`, `--key KEY`: Set the OpenAI API key
34
- - `-P`, `--send-path`: Send the PATH environment variable to OpenAI.
37
+ **Options:**
38
+ `-v`, `--verbose` Run verbosely
35
39
 
36
40
  ## Presets
37
41
 
data/lib/client.rb CHANGED
@@ -79,7 +79,7 @@ class Client
79
79
 
80
80
  response = openapi_client.chat(
81
81
  parameters: {
82
- model: "gpt-3.5-turbo",
82
+ model: "gpt-4-turbo-preview",
83
83
  messages: @messages,
84
84
  temperature: 0.6,
85
85
  }
@@ -108,7 +108,7 @@ class Client
108
108
 
109
109
  response = openapi_client.chat(
110
110
  parameters: {
111
- model: "gpt-4",
111
+ model: "gpt-4-turbo-preview",
112
112
  messages: @messages,
113
113
  temperature: 0.6,
114
114
  }
@@ -151,7 +151,7 @@ class Client
151
151
 
152
152
  response = openapi_client.chat(
153
153
  parameters: {
154
- model: "gpt-4",
154
+ model: "gpt-4-turbo-preview",
155
155
  messages: @messages,
156
156
  temperature: 0.6,
157
157
  }
data/lib/config.rb CHANGED
@@ -15,9 +15,6 @@ module AppConfig
15
15
  end
16
16
 
17
17
  def self.save_config(config)
18
- puts "Saving config to #{CONFIG_FILE}"
19
- puts "It will look like:"
20
- puts config.to_yaml
21
18
  File.write(CONFIG_FILE, config.to_yaml)
22
19
  end
23
20
 
data/lib/gpterminal.rb CHANGED
@@ -12,7 +12,22 @@ class GPTerminal
12
12
  end
13
13
 
14
14
  def run
15
- prompt = determine_prompt
15
+ puts "gpterminal has been renamed to gpterm. Please use gpterm instead. Exiting...".colorize(:red)
16
+ exit
17
+ if @options[:preset_prompt]
18
+ name = @options[:preset_prompt][0]
19
+ prompt = @options[:preset_prompt][1]
20
+ AppConfig.add_preset(@config, name, prompt)
21
+ puts "Preset prompt '#{name}' saved with prompt '#{prompt}'".colorize(:green)
22
+ exit
23
+ elsif @options[:prompt]
24
+ start_prompt(@options[:prompt])
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def start_prompt(prompt)
16
31
  message = @client.first_prompt(prompt)
17
32
 
18
33
  if message.downcase == '$$cannot_compute$$'
@@ -77,20 +92,18 @@ class GPTerminal
77
92
  puts output
78
93
  end
79
94
 
80
- private
81
-
82
95
  def load_config
83
96
  unless File.exist?(AppConfig::CONFIG_FILE)
84
97
  puts 'Welcome to GPTerminal! It looks like this is your first time using this application.'.colorize(:magenta)
85
98
 
86
99
  new_config = {}
87
- print "Before we get started, we need to configure the application. All the info you provide will be saved in #{AppConfig::CONFIG_FILE}.".colorize(:magenta)
100
+ puts "Before we get started, we need to configure the application. All the info you provide will be saved in #{AppConfig::CONFIG_FILE}.".colorize(:magenta)
88
101
 
89
- print "Enter your OpenAI API key's \"SECRET KEY\" value: ".colorize(:yellow)
102
+ puts "Enter your OpenAI API key's \"SECRET KEY\" value: ".colorize(:yellow)
90
103
  new_config['openapi_key'] = STDIN.gets.chomp
91
104
 
92
- print "Your PATH environment variable is: #{ENV['PATH']}".colorize(:magenta)
93
- print 'Are you happy for your PATH to be sent to OpenAI to help with command generation? (Y/n) '.colorize(:yellow)
105
+ puts "Your PATH environment variable is: #{ENV['PATH']}".colorize(:magenta)
106
+ puts 'Are you happy for your PATH to be sent to OpenAI to help with command generation? (Y/n) '.colorize(:yellow)
94
107
 
95
108
  if STDIN.gets.chomp.downcase == 'y'
96
109
  new_config['send_path'] = true
@@ -108,66 +121,67 @@ class GPTerminal
108
121
 
109
122
  def parse_options
110
123
  options = {}
111
- OptionParser.new do |opts|
112
- opts.banner = "Usage: gpterminal [preset] [options]"
113
-
114
- opts.on("-p", "--prompt PROMPT", "Set a custom prompt") do |v|
115
- options[:prompt] = v
116
- end
117
-
118
- opts.on("-s", "--save NAME,PROMPT", "Create a custom preset prompt") do |list|
119
- options[:preset_prompt] = list.split(',', 2)
124
+ subcommands = {
125
+ 'preset' => {
126
+ option_parser: OptionParser.new do |opts|
127
+ opts.banner = "gpterminal preset <name> <prompt>"
128
+ end,
129
+ argument_parser: ->(args) {
130
+ if args.length < 2
131
+ options[:prompt] = @config['presets'][args[0]]
132
+ else
133
+ options[:preset_prompt] = [args[0], args[1]]
134
+ end
135
+ }
136
+ },
137
+ 'config' => {
138
+ option_parser: OptionParser.new do |opts|
139
+ opts.banner = "gpterminal config [--openapi_key <value>|--send_path <true|false>]"
140
+ opts.on("--openapi_key VALUE", "Set the OpenAI API key") do |v|
141
+ AppConfig.add_openapi_key(@config, v)
142
+ puts "OpenAI API key saved"
143
+ exit
144
+ end
145
+ opts.on("--send_path", "Send the PATH environment variable to OpenAI") do
146
+ @config['send_path'] = true
147
+ AppConfig.save_config(@config)
148
+ puts "Your PATH environment variable will be sent to OpenAI to help with command generation"
149
+ exit
150
+ end
151
+ end
152
+ }
153
+ }
154
+
155
+ main = OptionParser.new do |opts|
156
+ opts.banner = "Usage:"
157
+ opts.banner += "\n\ngpterminal <prompt> [options] [subcommand [options]]"
158
+ opts.banner += "\n\nSubcommands:"
159
+ subcommands.each do |name, subcommand|
160
+ opts.banner += "\n #{name} - #{subcommand[:option_parser].banner}"
120
161
  end
121
-
122
- opts.on("-h", "--help", "Prints this help") do
123
- puts opts
124
- exit
162
+ opts.banner += "\n\nOptions:"
163
+ opts.on("-v", "--verbose", "Run verbosely") do |v|
164
+ options[:verbose] = true
125
165
  end
126
-
127
- opts.on("-k", "--key KEY", "Set the OpenAI API key") do |v|
128
- AppConfig.add_openapi_key(@config, v)
129
- puts "OpenAI API key saved"
130
- exit
131
- end
132
-
133
- opts.on("-P", "--send-path", "Send the PATH environment variable to OpenAI") do
134
- @config['send_path'] = true
135
- AppConfig.save_config(@config)
136
- puts "Your PATH environment variable will be sent to OpenAI to help with command generation"
137
- exit
138
- end
139
- end.parse!
140
-
141
- options
142
- end
143
-
144
- def determine_prompt
145
- if @options[:preset_prompt]
146
- name = @options[:preset_prompt][0]
147
- prompt = @options[:preset_prompt][1]
148
- AppConfig.add_preset(@config, name, prompt)
149
- puts "Preset prompt '#{name}' saved with prompt '#{prompt}'".colorize(:green)
150
- exit
151
166
  end
152
167
 
153
- if ARGV.length == 1
154
- # collect a prompt from the preset prompts
155
- prompt = @config['presets'][ARGV[0]]
156
-
157
- unless prompt
158
- puts "Preset prompt not found: #{ARGV[0]}".colorize(:red)
159
- exit
160
- end
168
+ command = ARGV.shift
161
169
 
162
- puts "Using preset prompt '#{prompt}'".colorize(:magenta)
163
- elsif @options[:prompt]
164
- prompt = @options[:prompt]
170
+ main.order!
171
+ if subcommands.key?(command)
172
+ subcommands[command][:option_parser].parse!
173
+ subcommands[command][:argument_parser].call(ARGV) if subcommands[command][:argument_parser]
174
+ elsif command == 'help'
175
+ puts main
176
+ exit
177
+ elsif command
178
+ options[:prompt] = command
165
179
  else
166
180
  puts 'Enter a prompt to generate text from:'.colorize(:yellow)
167
- prompt = STDIN.gets.chomp
181
+ options[:prompt] = STDIN.gets.chomp
168
182
  end
169
183
 
170
- prompt
184
+ options
171
185
  end
172
186
 
173
187
  def offer_more_information(output)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gpterminal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Hough
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-16 00:00:00.000000000 Z
11
+ date: 2024-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-openai
@@ -24,8 +24,8 @@ dependencies:
24
24
  - - "<"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '7'
27
- description: gpterminal is a powerful, flexible and dangerous command-line tool designed
28
- to help you generate commands for your terminal using OpenAI's Chat Completions
27
+ description: "[DEPRECATED] gpterminal has been renamed to gpterm. Please use the gpterm
28
+ gem instead."
29
29
  email:
30
30
  - daniel.hough@gmail.com
31
31
  executables:
@@ -39,12 +39,12 @@ files:
39
39
  - lib/client.rb
40
40
  - lib/config.rb
41
41
  - lib/gpterminal.rb
42
- homepage: https://github.com/basicallydan/gpterminal
42
+ homepage: https://github.com/basicallydan/gpterm
43
43
  licenses:
44
44
  - MIT
45
45
  metadata:
46
- homepage_uri: https://github.com/basicallydan/gpterminal
47
- source_code_uri: https://github.com/basicallydan/gpterminal
46
+ homepage_uri: https://github.com/basicallydan/gpterm
47
+ source_code_uri: https://github.com/basicallydan/gpterm
48
48
  post_install_message:
49
49
  rdoc_options: []
50
50
  require_paths:
@@ -63,5 +63,6 @@ requirements: []
63
63
  rubygems_version: 3.5.3
64
64
  signing_key:
65
65
  specification_version: 4
66
- summary: A CLI for generating CLI commands with ChatGPT's help.
66
+ summary: "[DEPRECATED] gpterminal has been renamed to gpterm. Please use the gpterm
67
+ gem instead."
67
68
  test_files: []