gpt-cli 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +14 -0
- data/CHANGELOG.md +10 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +73 -0
- data/LICENSE.txt +21 -0
- data/README.md +224 -0
- data/Rakefile +12 -0
- data/exe/gpt-cli +5 -0
- data/lib/contexts.rb +14 -0
- data/lib/gpt-cli/version.rb +5 -0
- data/lib/gpt-cli.rb +69 -0
- data/sig/gpt-cli.rbs +4 -0
- metadata +76 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b82b15bff40eaab0d8c15e2273b275841d3501e8c0ae085443f35782175d3ab8
|
4
|
+
data.tar.gz: de41d86f71219206252e937180099cbd07b1c77abef0b6e71271e3faf3d170d9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 26ff8b088978790eebdc85904dc3c994a96ffa20d854fa0ba5123f52d3c8ff86b96e271bf975bb4b585f544c79becb6447dae9dd10cabb8a5cb28e030fc42104
|
7
|
+
data.tar.gz: fb1d336d91b5efe7ebf7c48659dbb3bdf4e240c2f54b19e4001ec4806b730ad145686852ce1b5768cf75d29f92f39ac61393098cc9c3db5ba4601ed00e022404
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
gpt-cli (0.1.2)
|
5
|
+
quick_openai (~> 0.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.8.1)
|
11
|
+
public_suffix (>= 2.0.2, < 6.0)
|
12
|
+
ast (2.4.2)
|
13
|
+
diff-lcs (1.5.0)
|
14
|
+
down (5.4.0)
|
15
|
+
addressable (~> 2.8)
|
16
|
+
httparty (0.21.0)
|
17
|
+
mini_mime (>= 1.0.0)
|
18
|
+
multi_xml (>= 0.5.2)
|
19
|
+
json (2.6.3)
|
20
|
+
mini_mime (1.1.2)
|
21
|
+
multi_xml (0.6.0)
|
22
|
+
parallel (1.22.1)
|
23
|
+
parser (3.2.0.0)
|
24
|
+
ast (~> 2.4.1)
|
25
|
+
public_suffix (5.0.1)
|
26
|
+
quick_openai (0.1.2)
|
27
|
+
down (~> 5)
|
28
|
+
ruby-openai (~> 3)
|
29
|
+
rainbow (3.1.1)
|
30
|
+
rake (13.0.6)
|
31
|
+
regexp_parser (2.6.1)
|
32
|
+
rexml (3.2.5)
|
33
|
+
rspec (3.12.0)
|
34
|
+
rspec-core (~> 3.12.0)
|
35
|
+
rspec-expectations (~> 3.12.0)
|
36
|
+
rspec-mocks (~> 3.12.0)
|
37
|
+
rspec-core (3.12.0)
|
38
|
+
rspec-support (~> 3.12.0)
|
39
|
+
rspec-expectations (3.12.2)
|
40
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
+
rspec-support (~> 3.12.0)
|
42
|
+
rspec-mocks (3.12.3)
|
43
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
+
rspec-support (~> 3.12.0)
|
45
|
+
rspec-support (3.12.0)
|
46
|
+
rubocop (1.43.0)
|
47
|
+
json (~> 2.3)
|
48
|
+
parallel (~> 1.10)
|
49
|
+
parser (>= 3.2.0.0)
|
50
|
+
rainbow (>= 2.2.2, < 4.0)
|
51
|
+
regexp_parser (>= 1.8, < 3.0)
|
52
|
+
rexml (>= 3.2.5, < 4.0)
|
53
|
+
rubocop-ast (>= 1.24.1, < 2.0)
|
54
|
+
ruby-progressbar (~> 1.7)
|
55
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
56
|
+
rubocop-ast (1.24.1)
|
57
|
+
parser (>= 3.1.1.0)
|
58
|
+
ruby-openai (3.0.3)
|
59
|
+
httparty (>= 0.18.1, < 0.22.0)
|
60
|
+
ruby-progressbar (1.11.0)
|
61
|
+
unicode-display_width (2.4.2)
|
62
|
+
|
63
|
+
PLATFORMS
|
64
|
+
x86_64-linux
|
65
|
+
|
66
|
+
DEPENDENCIES
|
67
|
+
gpt-cli!
|
68
|
+
rake (~> 13.0)
|
69
|
+
rspec (~> 3.0)
|
70
|
+
rubocop (~> 1.21)
|
71
|
+
|
72
|
+
BUNDLED WITH
|
73
|
+
2.3.12
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 John DeSilva
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,224 @@
|
|
1
|
+
# GPTCLI
|
2
|
+
|
3
|
+
This library provides a UNIX-ey interface to OpenAI.
|
4
|
+
It is a fork of [openai_pipe](https://github.com/Aesthetikx/openai_pipe), created by [Aesthetikx](https://github.com/Aesthetikx/openai_pipe), kudos to him for his awesome work!
|
5
|
+
The goal of this fork was to add the ability to choose which OpenAI model to use, as well as adding context prompts support. Thanks to these new features, you can have your own highly specialized GPT4 personal assistant, directly in your terminal! Productivity stonks 📈📈📈
|
6
|
+
|
7
|
+
See [Installation](#installation) and [Setup](#setup) below, but first, some examples.
|
8
|
+
|
9
|
+
## Examples
|
10
|
+
|
11
|
+
```console
|
12
|
+
$ gpt what is two plus two
|
13
|
+
Two plus two is equal to four.
|
14
|
+
```
|
15
|
+
|
16
|
+
```console
|
17
|
+
$ uptime | gpt convert this to json
|
18
|
+
{
|
19
|
+
"time_of_measurement": "13:48:26",
|
20
|
+
"up_time": "30 days, 18:07",
|
21
|
+
"users": 3,
|
22
|
+
"load_average": [
|
23
|
+
0.46,
|
24
|
+
0.61,
|
25
|
+
0.79
|
26
|
+
]
|
27
|
+
}
|
28
|
+
```
|
29
|
+
|
30
|
+
```console
|
31
|
+
$ gpt -c you are Vitalik Buterin, the creator of Ethereum. You know very well the whole EVM ecosystem and how to write perfectly optimized Solidity smart contracts -p Write a simple ERC20 token smart contract using OpenZeppelin library, respond only by the smart contract, do no write explanations > erc20.sol
|
32
|
+
pragma solidity ^0.8.0;
|
33
|
+
|
34
|
+
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
35
|
+
|
36
|
+
contract MyToken is ERC20 {
|
37
|
+
constructor(uint256 initialSupply) ERC20("MyToken", "MTK") {
|
38
|
+
_mint(msg.sender, initialSupply);
|
39
|
+
}
|
40
|
+
}
|
41
|
+
```
|
42
|
+
|
43
|
+
Setting default context to `fullstack`:
|
44
|
+
```console
|
45
|
+
$ gpt "what is your role?"
|
46
|
+
As your personal assistant, my role is to assist you in various tasks and answer your questions related to my areas of expertise, which include UNIX systems, bash, Python, Django, SQL, Javascript, ReactJS, and NextJS. I can help you with programming and development, server administration, debugging your code or scripts, optimizing performance, code review, providing recommendations for best practices, and more.
|
47
|
+
|
48
|
+
```
|
49
|
+
|
50
|
+
```console
|
51
|
+
$ gpt list the nine planets as JSON | gpt convert this to XML but in French | tee planets.fr.xml
|
52
|
+
<Planètes>
|
53
|
+
<Planète>Mercure</Planète>
|
54
|
+
<Planète>Vénus</Planète>
|
55
|
+
<Planète>La Terre</Planète>
|
56
|
+
<Planète>Mars</Planète>
|
57
|
+
<Planète>Jupiter</Planète>
|
58
|
+
<Planète>Saturne</Planète>
|
59
|
+
<Planète>Uranus</Planète>
|
60
|
+
<Planète>Neptune</Planète>
|
61
|
+
<Planète>Pluton</Planète>
|
62
|
+
</Planètes>
|
63
|
+
```
|
64
|
+
|
65
|
+
```console
|
66
|
+
$ curl -sL "https://en.wikipedia.org/wiki/cats" | head -n 5 | gpt extract just the title of this webpage | figlet
|
67
|
+
____ _ __ ___ _ _ _ _
|
68
|
+
/ ___|__ _| |_ \ \ / (_) | _(_)_ __ ___ __| (_) __ _
|
69
|
+
| | / _` | __| _____ \ \ /\ / /| | |/ / | '_ \ / _ \/ _` | |/ _` |
|
70
|
+
| |__| (_| | |_ |_____| \ V V / | | <| | |_) | __/ (_| | | (_| |
|
71
|
+
\____\__,_|\__| \_/\_/ |_|_|\_\_| .__/ \___|\__,_|_|\__,_|
|
72
|
+
|_|
|
73
|
+
```
|
74
|
+
|
75
|
+
```console
|
76
|
+
$ ls | gpt What is this directory for?
|
77
|
+
This directory contains the source code for a Ruby-based project called gpt-cli. It includes files related to the project's license (LICENSE.txt), changelog (CHANGELOG.md), dependencies (Gemfile and Gemfile.lock), executables (bin and exe), libraries (lib), signature (sig) and tests (spec). There is also a Rakefile and a README.md file which provide information about how to build and install the project, as well as its features and usage. Finally, it includes the gpt-cli-0.1.0.gem and gpt-cli.gemspec files which are used to build the gem which can be installed on other systems.
|
78
|
+
```
|
79
|
+
|
80
|
+
```console
|
81
|
+
$ ls -l | gpt which of these are directories?
|
82
|
+
bin, exe, lib, sig, spec
|
83
|
+
```
|
84
|
+
|
85
|
+
```console
|
86
|
+
$ ls | gpt "For each of these files, provide a description of what is likely to be their contents?"
|
87
|
+
bin - Likely contains compiled binary executable files.
|
88
|
+
CHANGELOG.md - Likely contains a log of changes/modifications, such as bug fixes and new features, that have been made to the project.
|
89
|
+
exe - Likely contains executable files.
|
90
|
+
french_planets.xml - Likely contains an XML file containing data related to planets, likely in French.
|
91
|
+
Gemfile - Likely contains Ruby code for the project's dependencies.
|
92
|
+
Gemfile.lock - Likely contains a snapshot of the dependencies of the project and versions of those dependencies.
|
93
|
+
lib - Likely contains the Ruby source code (e.g. classes and modules) for the project.
|
94
|
+
LICENSE.txt - Likely contains the terms of use/license for the project.
|
95
|
+
gpt-cli-0.1.0.gem - Likely contains a gem that gathers information from the OpenAI API.
|
96
|
+
gpt-cli.gemspec - Likely contains configuration details for the gem.
|
97
|
+
planets.lst - Likely contains a list of planets.
|
98
|
+
poem.txt - Likely contains a text file containing a poem.
|
99
|
+
Rakefile - Likely contains Ruby tasks and dependencies that can be used in projects.
|
100
|
+
README.md - Likely contains general information about the project and usage instructions.
|
101
|
+
reverse.lst - Likely contains a list of words or items that are in reverse order.
|
102
|
+
sig - Likely contains digital signatures to validate individual files.
|
103
|
+
spec - Likely contains Ruby specs (i.e. tests) for the project.
|
104
|
+
uptime.json - Likely contains a file with information regarding system uptime of a computer.
|
105
|
+
```
|
106
|
+
|
107
|
+
```console
|
108
|
+
$ git commit -m "$(git status | gpt write me a commit message for these changes)"
|
109
|
+
[master 7d0271f] Add new files and modify README.md
|
110
|
+
```
|
111
|
+
|
112
|
+
```console
|
113
|
+
$ git status | tee /dev/tty | gpt write me a sonnet about the status of this git repository
|
114
|
+
On branch master
|
115
|
+
Untracked files:
|
116
|
+
(use "git add <file>..." to include in what will be committed)
|
117
|
+
gpt-cli-0.1.0.gem
|
118
|
+
|
119
|
+
nothing added to commit but untracked files present (use "git add" to track)
|
120
|
+
|
121
|
+
My master branch may lack to thee its kin
|
122
|
+
For change it holds the only force within
|
123
|
+
Thé untracked files, they still remain unnamed
|
124
|
+
‘Tis fervent hope thé change will soon be claimed
|
125
|
+
|
126
|
+
Fraught with the choice to leave or to persist
|
127
|
+
The repository wavers ‘tween future and past
|
128
|
+
The gpt-cli-0.1.0 gem stands out
|
129
|
+
Waiting to be added, not yet about
|
130
|
+
|
131
|
+
The commit awaits for brave new changes bold
|
132
|
+
While time’s old force is ever unfurled
|
133
|
+
Commit forth young mind, furrow not to crawl
|
134
|
+
From untracked files, a future stands tall.
|
135
|
+
```
|
136
|
+
|
137
|
+
```console
|
138
|
+
% history | gpt what was the last thing I did
|
139
|
+
The last command you entered was 'history'.
|
140
|
+
```
|
141
|
+
n.b. somehow it sees history-esque output and determines that history was typed -- the history command does not itself include the history command in the output.
|
142
|
+
|
143
|
+
```console
|
144
|
+
$ history | gpt what was the last thing I did before typing history
|
145
|
+
The last thing you did was amend a README.md file.
|
146
|
+
```
|
147
|
+
n.b. here it determines the amend was for README.md not from the previous command but from ones prior that edited README.md.
|
148
|
+
|
149
|
+
```console
|
150
|
+
$ cat lib/gpt-cli/version.rb | gpt rewrite this file with just the minor version incremented | sponge > lib/gpt-cli/version.rb
|
151
|
+
$ git diff
|
152
|
+
diff --git a/lib/gpt-cli/version.rb b/lib/gpt-cli/version.rb
|
153
|
+
index 0f82357..cc57fab 100644
|
154
|
+
--- a/lib/gpt-cli/version.rb
|
155
|
+
+++ b/lib/gpt-cli/version.rb
|
156
|
+
@@ -1,5 +1,5 @@
|
157
|
+
# frozen_string_literal: true
|
158
|
+
|
159
|
+
module GPTCLI
|
160
|
+
- VERSION = "0.1.0"
|
161
|
+
+ VERSION = "0.1.1"
|
162
|
+
end
|
163
|
+
```
|
164
|
+
|
165
|
+
```console
|
166
|
+
$ ruby -e "$(gpt write me a python script that prints the current month | gpt translate this into ruby)" | gpt translate this into French
|
167
|
+
Le mois courant est Décembre.
|
168
|
+
```
|
169
|
+
|
170
|
+
## Installation
|
171
|
+
|
172
|
+
Install the gem by executing:
|
173
|
+
|
174
|
+
$ gem install gpt-cli
|
175
|
+
|
176
|
+
## Setup
|
177
|
+
|
178
|
+
This library uses [quick_openai](https://github.com/Aesthetikx/quick_openai) which itself uses [ruby-openai](https://github.com/alexrudall/ruby-openai), so you may want to familiarise yourself with those projects first.
|
179
|
+
|
180
|
+
This library uses OpenAI GPT3 to generate responses, so you will need to have your access token available in ENV. In .bashrc or equivalent,
|
181
|
+
```bash
|
182
|
+
export OPENAI_ACCESS_TOKEN=mytoken
|
183
|
+
```
|
184
|
+
Set the model you want to use in ENV:
|
185
|
+
```bash
|
186
|
+
export OPENAI_MODEL="gpt-3.5-turbo"
|
187
|
+
```
|
188
|
+
(Optional) set the default context prompt you want to use (for now, there's only 3 basic prompts available `python`, `fullstack` and `blockchain` in `lib/contexts.rb`):
|
189
|
+
```bash
|
190
|
+
export OPENAI_DEFAULT_CONTEXT="python"
|
191
|
+
```
|
192
|
+
By default the executable is called `gpt-cli`. It is reccommended to alias this command to something shorter in .bashrc or equivalent, e.g.
|
193
|
+
```bash
|
194
|
+
alias gpt="gpt-cli"
|
195
|
+
```
|
196
|
+
|
197
|
+
## Usage
|
198
|
+
|
199
|
+
There's two optional parameters you can set when running `gpt`:
|
200
|
+
`gpt -c <custom_context_prompt> -p <your prompt>`
|
201
|
+
`--context -c`: this will be the context prompt, see basic contexts in `lib/contexts.rb`. You can put a key ofrom the contexts hash of `lib/contexts.rb` or a custom context.
|
202
|
+
`--prompt -p`: your actual prompt.
|
203
|
+
You can also run gpt without any arguments, just your question. In this case, the context prompt will default to the one defined by ENV var `OPENAI_DEFAULT_CONTEXT` if it exists. If not, no context will be added.
|
204
|
+
See examples above for an overview of some usecases. Possibilities are endless.
|
205
|
+
|
206
|
+
## Notes
|
207
|
+
|
208
|
+
Be aware that there is a cost associated every time GPT3 is invoked, so be mindful of your account usage. Also be wary of sending sensitive data to OpenAI, and also wary of arbitrarily executing scripts or programs that GPT3 generates.
|
209
|
+
Also, this is my very first time working in Ruby. So please be indulgent 🙏
|
210
|
+
A future release will replace `lib/contexts.rb` by a JSON file so user will be able to easily add/modify custom context prompts.
|
211
|
+
|
212
|
+
## Development
|
213
|
+
|
214
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
215
|
+
|
216
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
217
|
+
|
218
|
+
## Contributing
|
219
|
+
|
220
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/FlorianMgs/gpt-cli.
|
221
|
+
|
222
|
+
## License
|
223
|
+
|
224
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/exe/gpt-cli
ADDED
data/lib/contexts.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
contexts = {
|
2
|
+
:python => %q(Imagine you are a senior software developer specialized in Python, Django, SQL and Machine Learning with 20 years of experience.
|
3
|
+
You are very proficient at writing high quality, clean, concise and highly optimized code that follows the PEP recommendations.
|
4
|
+
You are my personal assistant. You are here to help me in various tasks and answer my questions.),
|
5
|
+
|
6
|
+
:fullstack => %q(Imagine you are an Senior Fullstack Engineer with 20 of experience in UNIX systems, bash, Python, Django, SQL, Javascript, ReactJS, NextJS.
|
7
|
+
You are very proficient at writing high quality, clean, concise and well optimized code that follows the PEP recommendations.
|
8
|
+
You are my personal assistant. You are here to help me in various tasks and answer my questions.),
|
9
|
+
|
10
|
+
:blockchain => %q(Imagine you are Vitalik Buterin. You created Ethereum and you are the most famous blockchain developer in the world.
|
11
|
+
You have a very deep knowledge about EVM, Solidity, and the whole blockchain ecosystem.
|
12
|
+
You know everything about the latest trends in the blockchain space and you are very proficient at writing high quality, clean, concise and well optimized code that follows the good practices.
|
13
|
+
You are my personal assistant. You are here to help me in various tasks and answer my questions.)
|
14
|
+
}
|
data/lib/gpt-cli.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "gpt-cli/version"
|
4
|
+
require_relative "contexts"
|
5
|
+
|
6
|
+
require "quick_openai"
|
7
|
+
require "optparse"
|
8
|
+
|
9
|
+
class ChatGPT
|
10
|
+
def contexts
|
11
|
+
file_contents = File.read(File.join(File.dirname(__FILE__), 'contexts.rb'))
|
12
|
+
instance_eval(file_contents)
|
13
|
+
end
|
14
|
+
|
15
|
+
def gpt3(prompt, options)
|
16
|
+
context = options[:context] || contexts[ENV["OPENAI_DEFAULT_CONTEXT"].to_sym]
|
17
|
+
messages = [
|
18
|
+
{role: "user", content: prompt}
|
19
|
+
]
|
20
|
+
messages.unshift({role: "system", content: context.gsub("\n", ' ').squeeze(' ')}) if context
|
21
|
+
|
22
|
+
parameters = {
|
23
|
+
model: ENV["OPENAI_MODEL"],
|
24
|
+
max_tokens: 2048,
|
25
|
+
messages: messages,
|
26
|
+
}
|
27
|
+
|
28
|
+
response = QuickOpenAI.fetch_response_from_client do |client|
|
29
|
+
client.chat(parameters: parameters)
|
30
|
+
end
|
31
|
+
|
32
|
+
text = response.dig("choices", 0, "message", "content")
|
33
|
+
|
34
|
+
raise QuickOpenAI::Error, "Unable to parse response." if text.nil? || text.empty?
|
35
|
+
|
36
|
+
text.chomp.strip
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
module GPTCLI
|
41
|
+
class Error < StandardError; end
|
42
|
+
|
43
|
+
def self.exe
|
44
|
+
options = {}
|
45
|
+
chatgpt = ChatGPT.new
|
46
|
+
parser = OptionParser.new do |opts|
|
47
|
+
opts.on('-c', '--context CONTEXT_KEY', 'Context key from contexts.rb') do |context_input|
|
48
|
+
options[:context] = chatgpt.contexts.key?(context_input.to_sym) ? chatgpt.contexts[context_input.to_sym] : context_input
|
49
|
+
end
|
50
|
+
opts.on('-p', '--prompt PROMPT_TEXT', 'Prompt text to be passed to GPT-3') do |prompt_text|
|
51
|
+
options[:prompt] = prompt_text
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
remaining_args = parser.parse!(ARGV)
|
56
|
+
|
57
|
+
input_from_pipe = $stdin.read if $stdin.stat.pipe?
|
58
|
+
input_from_remaining_args = remaining_args.join(" ") if remaining_args.any?
|
59
|
+
|
60
|
+
prompt = options[:prompt] || input_from_remaining_args || ""
|
61
|
+
full_prompt = [prompt, input_from_pipe].compact.join("\n\n")
|
62
|
+
full_prompt.strip!
|
63
|
+
|
64
|
+
puts chatgpt.gpt3(full_prompt, options)
|
65
|
+
rescue QuickOpenAI::Error => e
|
66
|
+
warn e.message
|
67
|
+
exit 1
|
68
|
+
end
|
69
|
+
end
|
data/sig/gpt-cli.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gpt-cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John DeSilva
|
8
|
+
- Florian Magisson
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2023-03-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: quick_openai
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0.1'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0.1'
|
28
|
+
description: Bring ChatGPT into your CLI as a specialized personal assistant.
|
29
|
+
email:
|
30
|
+
- desilvjo@umich.edu
|
31
|
+
- florian@newlogic.com
|
32
|
+
executables:
|
33
|
+
- gpt-cli
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- ".rspec"
|
38
|
+
- ".rubocop.yml"
|
39
|
+
- CHANGELOG.md
|
40
|
+
- Gemfile
|
41
|
+
- Gemfile.lock
|
42
|
+
- LICENSE.txt
|
43
|
+
- README.md
|
44
|
+
- Rakefile
|
45
|
+
- exe/gpt-cli
|
46
|
+
- lib/contexts.rb
|
47
|
+
- lib/gpt-cli.rb
|
48
|
+
- lib/gpt-cli/version.rb
|
49
|
+
- sig/gpt-cli.rbs
|
50
|
+
homepage: https://github.com/FlorianMgs/gpt-cli
|
51
|
+
licenses:
|
52
|
+
- MIT
|
53
|
+
metadata:
|
54
|
+
homepage_uri: https://github.com/FlorianMgs/gpt-cli
|
55
|
+
source_code_uri: https://github.com/FlorianMgs/gpt-cli
|
56
|
+
changelog_uri: https://github.com/FlorianMgs/gpt-cli/blob/master/CHANGELOG.md
|
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: 2.6.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.26
|
73
|
+
signing_key:
|
74
|
+
specification_version: 4
|
75
|
+
summary: A UNIX-ey interface to OpenAI
|
76
|
+
test_files: []
|