richat 0.3.3 → 0.3.5
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 +4 -4
- data/lib/richat/command.rb +15 -2
- data/lib/richat/config.rb +2 -1
- data/lib/richat/shell.rb +18 -4
- data/lib/richat/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 556b89d96438fa55db8004f7b7c988cc9e6f4e7186b5fe55cb3791e5a7448fc9
|
4
|
+
data.tar.gz: e7a2ca5f62fa9707130e1d535e4d8ff0137f3f0bcd5ee402b62b64ed01142c01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a8d20d4dc3d35a34dff1a3821e877404c883adbabb132ef696159048fec580dd1249953a3c6e4dccbc2348e30e6b118934707c72436d9d9a57aadd224f3038f
|
7
|
+
data.tar.gz: fbb27db3fa171b55d0e01c26bf78f5565169c0a1dc6aa0599c015d04233d0e08d1e306f8b6ff599ad7cc7dacdc09d275768c8016f29a251f85cac8a3b6d9ace9
|
data/lib/richat/command.rb
CHANGED
@@ -5,6 +5,7 @@ module Richat
|
|
5
5
|
PROMPT_CHANGED_CODE = 2
|
6
6
|
SYS_CMD_CODE = 3
|
7
7
|
SYS_CHAT_CODE = 4
|
8
|
+
TOGGLE_CONTEXT_CODE = 5
|
8
9
|
|
9
10
|
class << self
|
10
11
|
attr_reader :prompt, :prompt_id
|
@@ -29,6 +30,8 @@ module Richat
|
|
29
30
|
else
|
30
31
|
handle_choose_prompt(user_input.split(" ").last)
|
31
32
|
end
|
33
|
+
elsif user_input == "/context"
|
34
|
+
handle_toggle_context
|
32
35
|
end
|
33
36
|
end
|
34
37
|
end
|
@@ -56,10 +59,11 @@ module Richat
|
|
56
59
|
end
|
57
60
|
|
58
61
|
def kill_process
|
59
|
-
return if @pid.nil?
|
62
|
+
return if @pid.nil?
|
60
63
|
if Gem.win_platform?
|
61
|
-
system("taskkill /F /PID #{@pid}")
|
64
|
+
system("taskkill /F /PID #{@pid}", err: File::NULL)
|
62
65
|
else
|
66
|
+
return unless process_exist?
|
63
67
|
begin
|
64
68
|
Process.kill("TERM", @pid)
|
65
69
|
rescue
|
@@ -84,11 +88,16 @@ module Richat
|
|
84
88
|
NEXT_CODE
|
85
89
|
end
|
86
90
|
|
91
|
+
def handle_toggle_context
|
92
|
+
TOGGLE_CONTEXT_CODE
|
93
|
+
end
|
94
|
+
|
87
95
|
def handle_help
|
88
96
|
puts "Version #{VERSION}"
|
89
97
|
puts "\e[32m/exit\e[0m exit Richat"
|
90
98
|
puts "\e[32m/config\e[0m show configuration"
|
91
99
|
puts "\e[32m/prompt\e[0m show prompt list"
|
100
|
+
puts "\e[32m/context\e[0m toggle chat context"
|
92
101
|
puts "\e[32m/help\e[0m show help info"
|
93
102
|
NEXT_CODE
|
94
103
|
end
|
@@ -161,6 +170,10 @@ module Richat
|
|
161
170
|
puts "\e[31m#{message}\e[0m"
|
162
171
|
end
|
163
172
|
|
173
|
+
def print_info(message)
|
174
|
+
puts "\e[32m#{message}\e[0m"
|
175
|
+
end
|
176
|
+
|
164
177
|
def print_welcome
|
165
178
|
puts "Richat is a command-line ChatGPT tool implemented in Ruby that supports highly customizable configuration, press \e[32m/help\e[0m to display help info. If you have any suggestions or questions, please feel free to provide feedback on https://github.com/fzdp/richat."
|
166
179
|
end
|
data/lib/richat/config.rb
CHANGED
@@ -21,7 +21,8 @@ module Richat
|
|
21
21
|
"enable_chat_context" => true,
|
22
22
|
"show_welcome_info" => true,
|
23
23
|
"shell_history_file" => "~/.richat/history.txt",
|
24
|
-
"exit_keywords" => ["/exit", "q", "quit", "exit"]
|
24
|
+
"exit_keywords" => ["/exit", "q", "quit", "exit"],
|
25
|
+
"chat_context_indicator" => "💡"
|
25
26
|
},
|
26
27
|
"sys_cmd" => {
|
27
28
|
"activate_keywords" => [">", "!"],
|
data/lib/richat/shell.rb
CHANGED
@@ -36,7 +36,7 @@ module Richat
|
|
36
36
|
sys_cmd_mode = false
|
37
37
|
|
38
38
|
begin
|
39
|
-
while (user_content = Readline.readline(shell_prompt(sys_cmd_mode), true))
|
39
|
+
while (user_content = Readline.readline(shell_prompt(sys_cmd_mode, enable_context_message), true))
|
40
40
|
if user_content.empty?
|
41
41
|
Readline::HISTORY&.pop
|
42
42
|
next
|
@@ -58,6 +58,13 @@ module Richat
|
|
58
58
|
elsif code == Command::SYS_CHAT_CODE
|
59
59
|
sys_cmd_mode = false
|
60
60
|
next
|
61
|
+
elsif code == Command::TOGGLE_CONTEXT_CODE
|
62
|
+
enable_context_message = !enable_context_message
|
63
|
+
unless enable_context_message
|
64
|
+
context_messages = Command.prompt_id ? [{ role: 'system', content: Command.prompt }] : []
|
65
|
+
end
|
66
|
+
Command.print_info("chat context mode " + (enable_context_message ? "enabled." : "disabled."))
|
67
|
+
next
|
61
68
|
end
|
62
69
|
end
|
63
70
|
|
@@ -108,12 +115,19 @@ module Richat
|
|
108
115
|
|
109
116
|
private
|
110
117
|
|
111
|
-
def shell_prompt(sys_cmd_mode)
|
118
|
+
def shell_prompt(sys_cmd_mode, chat_context_mode)
|
119
|
+
prompt_str = "\e[32m#{Command.prompt_id&.+" "}\e[0m"
|
120
|
+
if chat_context_mode
|
121
|
+
prompt_str += Config.get("shell", "chat_context_indicator")
|
122
|
+
end
|
123
|
+
|
112
124
|
if sys_cmd_mode
|
113
|
-
|
125
|
+
prompt_str += "\e[33m>>\e[0m \e[32m$ \e[0m"
|
114
126
|
else
|
115
|
-
|
127
|
+
prompt_str += "\e[33m>> \e[0m"
|
116
128
|
end
|
129
|
+
|
130
|
+
prompt_str
|
117
131
|
end
|
118
132
|
end
|
119
133
|
end
|
data/lib/richat/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: richat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- fzdp
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-04-
|
11
|
+
date: 2023-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|