richat 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7a7ca5a2cd65ccff6ccf2a79f9c0f93c05509bfe06118eed1f7b1f5a471cbd56
4
- data.tar.gz: 9db3acdef234d0c0e9c826d4da10238095376fd161cc13cd3238d8515ac4d658
3
+ metadata.gz: 556b89d96438fa55db8004f7b7c988cc9e6f4e7186b5fe55cb3791e5a7448fc9
4
+ data.tar.gz: e7a2ca5f62fa9707130e1d535e4d8ff0137f3f0bcd5ee402b62b64ed01142c01
5
5
  SHA512:
6
- metadata.gz: 923bc4c0bd06f5d947a2fd509f91c515fb1ba31368b6bbf6b5ba79283106716c19939c2cc3fba432de2e2a7fcd3fa4769793cc63e113f27ee7ce08c04652fac4
7
- data.tar.gz: fc07dde0548be71271a9c9b2e9eadd4ece24f816a4ed7d12f3c247e003d7f9f60f4404134a85a609ef807c93ac8ed3d45e8ac0a8a4d2da2df133c58494e3b1fe
6
+ metadata.gz: 8a8d20d4dc3d35a34dff1a3821e877404c883adbabb132ef696159048fec580dd1249953a3c6e4dccbc2348e30e6b118934707c72436d9d9a57aadd224f3038f
7
+ data.tar.gz: fbb27db3fa171b55d0e01c26bf78f5565169c0a1dc6aa0599c015d04233d0e08d1e306f8b6ff599ad7cc7dacdc09d275768c8016f29a251f85cac8a3b6d9ace9
@@ -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
@@ -85,11 +88,16 @@ module Richat
85
88
  NEXT_CODE
86
89
  end
87
90
 
91
+ def handle_toggle_context
92
+ TOGGLE_CONTEXT_CODE
93
+ end
94
+
88
95
  def handle_help
89
96
  puts "Version #{VERSION}"
90
97
  puts "\e[32m/exit\e[0m exit Richat"
91
98
  puts "\e[32m/config\e[0m show configuration"
92
99
  puts "\e[32m/prompt\e[0m show prompt list"
100
+ puts "\e[32m/context\e[0m toggle chat context"
93
101
  puts "\e[32m/help\e[0m show help info"
94
102
  NEXT_CODE
95
103
  end
@@ -162,6 +170,10 @@ module Richat
162
170
  puts "\e[31m#{message}\e[0m"
163
171
  end
164
172
 
173
+ def print_info(message)
174
+ puts "\e[32m#{message}\e[0m"
175
+ end
176
+
165
177
  def print_welcome
166
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."
167
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
- "\e[32m#{Command.prompt_id&.+" "}\e[0m\e[33m>>\e[0m \e[32m$ \e[0m"
125
+ prompt_str += "\e[33m>>\e[0m \e[32m$ \e[0m"
114
126
  else
115
- "\e[32m#{Command.prompt_id&.+" "}\e[0m\e[33m>> \e[0m"
127
+ prompt_str += "\e[33m>> \e[0m"
116
128
  end
129
+
130
+ prompt_str
117
131
  end
118
132
  end
119
133
  end
@@ -1,3 +1,3 @@
1
1
  module Richat
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.5"
3
3
  end
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
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 00:00:00.000000000 Z
11
+ date: 2023-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday