chat_cli 0.1.0
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 +7 -0
- data/.env +0 -0
- data/.rubocop.yml +13 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +31 -0
- data/README.md +35 -0
- data/Rakefile +3 -0
- data/exe/chat_cli +5 -0
- data/lib/chat_cli/version.rb +5 -0
- data/lib/chat_cli.rb +81 -0
- data/sig/chat_cli.rbs +4 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 47cba710877b2f94d6daee3ae4293332b6b20f6f0fcaa3aad86cf7784a9b452f
|
4
|
+
data.tar.gz: 1b6e4e19714957e34750e3ac729ae4192b42a943fb51512761270103096dee6f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ab486fef807c217e654b697ec1f6e4b526edcf7bd50cdc70b6c90249c02c25f4da4ca55635e282d5991e528c0ccbdb46defcc2c860ee29e3c7dbe287377a38b9
|
7
|
+
data.tar.gz: af0d7c43b6bc89257fd833b929cb8f9139dff6196b8d57d5407c5df8ea781972511a747d03003a8eb419a0aa51a878fd524bb3289b6265cfa6e058982e3b1db1
|
data/.env
ADDED
File without changes
|
data/.rubocop.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
chat_cli (0.1.0)
|
5
|
+
dotenv (~> 2.8)
|
6
|
+
ruby-openai (~> 3.6)
|
7
|
+
thor (~> 1.2)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
dotenv (2.8.1)
|
13
|
+
httparty (0.21.0)
|
14
|
+
mini_mime (>= 1.0.0)
|
15
|
+
multi_xml (>= 0.5.2)
|
16
|
+
mini_mime (1.1.2)
|
17
|
+
multi_xml (0.6.0)
|
18
|
+
rake (12.3.3)
|
19
|
+
ruby-openai (3.7.0)
|
20
|
+
httparty (>= 0.18.1)
|
21
|
+
thor (1.2.1)
|
22
|
+
|
23
|
+
PLATFORMS
|
24
|
+
x86_64-darwin-21
|
25
|
+
|
26
|
+
DEPENDENCIES
|
27
|
+
chat_cli!
|
28
|
+
rake (~> 12.3)
|
29
|
+
|
30
|
+
BUNDLED WITH
|
31
|
+
2.4.9
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# ChatCLI
|
2
|
+
|
3
|
+
OpenAI APIを利用し、GPT-3.5-turboへ質問を投げかけることができるCLIアプリケーションです。
|
4
|
+
※利用者自身のAPI Keyを使用して、OpenAI APIへリクエストを送ります。
|
5
|
+
|
6
|
+
## 推奨環境
|
7
|
+
- Mac (Intel)
|
8
|
+
- MacOS (Monterey v12.6.1)
|
9
|
+
- Ruby (2.6.10p210)
|
10
|
+
- Bundler (2.4.9)
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
1. gemのインストール
|
15
|
+
`sudo gem install chat_cli -n /usr/loca/bin`
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
`$sudo chat_cli init`
|
20
|
+
下記サイトで作成したシークレットAPIキーを記録します。
|
21
|
+
https://platform.openai.com/account/api-keys
|
22
|
+
|
23
|
+
`$chat_cli chat {message}`
|
24
|
+
GPT-3.5へメッセージを送ります。返答まで最大240秒待つ必要があり、これ以上返答に時間がかかる場合は返答を短くするような質問にしなければいけません。
|
25
|
+
|
26
|
+
`$chat_cli usage`
|
27
|
+
現在のAPI利用量を下記サイトから閲覧することができます。
|
28
|
+
https://platform.openai.com/account/usage
|
29
|
+
|
30
|
+
## Dependencies
|
31
|
+
|
32
|
+
利用したパッケージは以下の通りです
|
33
|
+
- [ruby-openai](https://github.com/alexrudall/ruby-openai)
|
34
|
+
- [thor](https://github.com/rails/thor)
|
35
|
+
- [dotenv](https://github.com/bkeepers/dotenv)
|
data/Rakefile
ADDED
data/exe/chat_cli
ADDED
data/lib/chat_cli.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'thor'
|
4
|
+
require 'openai'
|
5
|
+
require 'dotenv/load'
|
6
|
+
|
7
|
+
require_relative "chat_cli/version"
|
8
|
+
|
9
|
+
module ChatCli
|
10
|
+
class Error < StandardError; end
|
11
|
+
|
12
|
+
class CLI < Thor
|
13
|
+
LOADING_CHAR = ['\\', '-', '/', '|']
|
14
|
+
|
15
|
+
desc("chat [MESSAGE]", "Sends a message to ChatGPT. ex) $chat_cli chat ペットにとっての優しい世界を実現するにはどうすれば良いでしょうか?")
|
16
|
+
long_desc <<-LONGDESC
|
17
|
+
`chat_cli chat [Message]` sends a message to ChatGPT and print its response.
|
18
|
+
|
19
|
+
The model that made this response is `gpt-3.5-turbo-0301`.
|
20
|
+
In addition, the timeout period for response is 240 seconds.
|
21
|
+
Messages that take longer than this to respond cannot be sent.
|
22
|
+
|
23
|
+
ex)
|
24
|
+
> $ chat_cli chat ペットにとっての優しい世界を実現するにはどうすれば良いでしょうか?
|
25
|
+
LONGDESC
|
26
|
+
def chat(question)
|
27
|
+
Dotenv.load(File.expand_path("../.env", __dir__))
|
28
|
+
token = ENV['OPENAI_ACCESS_TOKEN']
|
29
|
+
if token.nil?
|
30
|
+
say "The following command must be executed to set the secret API key.\n" \
|
31
|
+
"> $sudo chat_cli init", :yellow
|
32
|
+
return
|
33
|
+
end
|
34
|
+
client = OpenAI::Client.new(access_token: ENV['OPENAI_ACCESS_TOKEN'])
|
35
|
+
response = nil
|
36
|
+
thread = Thread.new {
|
37
|
+
response = client.chat(
|
38
|
+
parameters: {
|
39
|
+
model: "gpt-3.5-turbo-0301",
|
40
|
+
messages: [{ role: "user", "content": question }],
|
41
|
+
})
|
42
|
+
}
|
43
|
+
1.upto(1200) do |i|
|
44
|
+
say "\r[#{LOADING_CHAR[i % 4]}]", nil, false
|
45
|
+
sleep 0.2
|
46
|
+
break unless thread.alive?
|
47
|
+
end
|
48
|
+
if response&.has_key? "error"
|
49
|
+
say("\r[ERROR] Invalid Secret API Key.\n" \
|
50
|
+
"Please set the correct secret API key again from the following command.\n" \
|
51
|
+
"> $sudo chat_cli init", :red); return if response&.dig("error", "code") == "invalid_api_key"
|
52
|
+
|
53
|
+
say "\r[ERROR] Unknown Error", :red
|
54
|
+
return
|
55
|
+
end
|
56
|
+
say "\rYou: #{question}"
|
57
|
+
say "GPT: #{response&.dig("choices", 0, "message", "content")}"
|
58
|
+
end
|
59
|
+
|
60
|
+
desc "init", "Set the Secret API Key."
|
61
|
+
def init()
|
62
|
+
token = ask "Please enter your Secret API Key.\n" \
|
63
|
+
"If it has not been issued yet, please go to the following site to issue a new API key.\n" \
|
64
|
+
" https://platform.openai.com/account/api-keys\n" \
|
65
|
+
"API Key:"
|
66
|
+
File.open(File.expand_path("../.env", __dir__), "w") do |file|
|
67
|
+
file.write("OPENAI_ACCESS_TOKEN = #{token}")
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
desc "usage", "Check API usage"
|
72
|
+
def usage()
|
73
|
+
say "Please check bellow Web Site.\n" \
|
74
|
+
" https://platform.openai.com/account/usage"
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.exit_on_failure?
|
78
|
+
true
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
data/sig/chat_cli.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chat_cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- M01tyan
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-03-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: ruby-openai
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.6'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: dotenv
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.8'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.8'
|
55
|
+
description: Chat-GPT Command Line Tools
|
56
|
+
email:
|
57
|
+
- M01tyan@users.noreply.github.com
|
58
|
+
executables:
|
59
|
+
- chat_cli
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".env"
|
64
|
+
- ".rubocop.yml"
|
65
|
+
- Gemfile
|
66
|
+
- Gemfile.lock
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- exe/chat_cli
|
70
|
+
- lib/chat_cli.rb
|
71
|
+
- lib/chat_cli/version.rb
|
72
|
+
- sig/chat_cli.rbs
|
73
|
+
homepage: https://rubygems.org/gems/chat_cli
|
74
|
+
licenses: []
|
75
|
+
metadata:
|
76
|
+
homepage_uri: https://rubygems.org/gems/chat_cli
|
77
|
+
source_code_uri: https://github.com/M01tyan/chat_cli
|
78
|
+
allowed_push_host: https://rubygems.org/gems/chat_cli
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 2.6.0
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubygems_version: 3.2.3
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: This is Chat-GPT CLI.
|
98
|
+
test_files: []
|