chatai 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -10
- data/bin/chatai +22 -8
- metadata +22 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 886519f7227a7da50c23385c6290853408687a1b1b0e8c434fc6c6f7f30f5a5d
|
4
|
+
data.tar.gz: 562eff776cfe614f2cec7662765c422096dc847ac172ebc80bf136b9a9e5ed8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 588ef4c8de8fdc4cc4e4dd7450bb60e66eb43f9b4b08b2b33176048a60cc1c7dbd911b5fda13e84af089d60c20207e82fd545056141ff4bfa90b138061a451ed
|
7
|
+
data.tar.gz: c87e7ab3220f244683f50382a479773726ad288570faf3211e4bf7b9aa68073e084bc743335b1f12cf2e9f3ba61304710445920b980acd6d96a1619c4bb7211d
|
data/README.md
CHANGED
@@ -4,18 +4,14 @@ A simple CLI for ChatGPT written in Ruby
|
|
4
4
|
|
5
5
|
## Setup
|
6
6
|
|
7
|
-
|
7
|
+
Copy and edit the env file with your [API key](https://platform.openai.com/account/api-keys)
|
8
8
|
|
9
|
-
$
|
10
|
-
$ cp .env.sample .env
|
9
|
+
$ cp .env.sample ~/.chatai.env
|
11
10
|
|
12
|
-
|
11
|
+
Build and install the CLI
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
$ sudo cp bin/chatai /usr/local/bin/chatai
|
17
|
-
$ sudo chmod 755 /usr/local/bin/chatai
|
18
|
-
$ cp .env ~/.chatai.env
|
13
|
+
$ gem build chatai.gemspec
|
14
|
+
$ gem install chatai-*.gem
|
19
15
|
|
20
16
|
## Usage
|
21
17
|
|
@@ -43,4 +39,4 @@ You can also install the script to use it everywhere:
|
|
43
39
|
|
44
40
|
## License
|
45
41
|
|
46
|
-
|
42
|
+
Chatai is released under MIT
|
data/bin/chatai
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
|
2
3
|
require "dotenv"
|
3
4
|
require "openai"
|
5
|
+
require "readline"
|
4
6
|
require "word_wrap"
|
5
7
|
|
6
8
|
Dotenv.load(".env", "~/.chatai.env")
|
@@ -15,23 +17,35 @@ end
|
|
15
17
|
client = OpenAI::Client.new
|
16
18
|
|
17
19
|
begin
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
context = []
|
21
|
+
loop do
|
22
|
+
line = Readline::readline("\x1b[36m>\x1b[0m ")
|
23
|
+
break if line.nil? || line == "quit"
|
24
|
+
|
25
|
+
Readline::HISTORY << line
|
26
|
+
context << line
|
27
|
+
|
28
|
+
parameters = {
|
23
29
|
model: ENV.fetch("OPENAI_MODEL", "gtp-3.5-turbo"),
|
24
|
-
messages: [{ role: "user", content:
|
30
|
+
messages: [{ role: "user", content: context.join("\n\n") }],
|
25
31
|
temperature: 0.7,
|
26
|
-
}
|
32
|
+
}
|
33
|
+
|
34
|
+
begin
|
35
|
+
res = client.chat(parameters: parameters)
|
36
|
+
rescue Net::ReadTimeout
|
37
|
+
redo
|
38
|
+
end
|
39
|
+
|
27
40
|
if (err = res.dig("error", "message"))
|
28
41
|
puts err
|
29
42
|
exit 1
|
30
43
|
end
|
44
|
+
|
31
45
|
text = res.dig("choices", 0, "message", "content").strip
|
32
46
|
puts WordWrap.ww(text, 80)
|
33
47
|
puts
|
34
|
-
|
48
|
+
context << text
|
35
49
|
end
|
36
50
|
rescue SignalException
|
37
51
|
puts
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chatai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vincent Ollivier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-03-
|
11
|
+
date: 2023-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dotenv
|
@@ -30,6 +30,26 @@ dependencies:
|
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 2.8.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rb-readline
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0.5'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 0.5.5
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0.5'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 0.5.5
|
33
53
|
- !ruby/object:Gem::Dependency
|
34
54
|
name: ruby-openai
|
35
55
|
requirement: !ruby/object:Gem::Requirement
|