richat 0.3.4 → 0.3.6

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: 2fb025384c114dec37924fed7ec5c9d9e9df8346d0b94bd831aacec551602d95
4
+ data.tar.gz: f60c3e845fcc33da304d2cee618219267fd0b4a7136f86afc3f62c094ed7e688
5
5
  SHA512:
6
- metadata.gz: 923bc4c0bd06f5d947a2fd509f91c515fb1ba31368b6bbf6b5ba79283106716c19939c2cc3fba432de2e2a7fcd3fa4769793cc63e113f27ee7ce08c04652fac4
7
- data.tar.gz: fc07dde0548be71271a9c9b2e9eadd4ece24f816a4ed7d12f3c247e003d7f9f60f4404134a85a609ef807c93ac8ed3d45e8ac0a8a4d2da2df133c58494e3b1fe
6
+ metadata.gz: 8d457a5fd0c5c1740b5b114aee779dbe2d3b77b7f780ac24743bf857b563147df43de933f5d673c8a35070e5e034a9ed074506679defbf10e664d7342d117104
7
+ data.tar.gz: 4ea395f9d4d57caa9b0c04f2fc87b901e6dbcc065e770eb50699a6bf7e1fd2ae492083d682b317b9ca95d059c94425b7d446566603aa39c0a48aadcc1e11fe6f
@@ -0,0 +1,20 @@
1
+ module Richat
2
+ class ColorCode
3
+ COLOR_CODE = {
4
+ black: "\e[30m",
5
+ red: "\e[31m",
6
+ green: "\e[32m",
7
+ yellow: "\e[33m",
8
+ blue: "\e[34m",
9
+ magenta: "\e[35m",
10
+ cyan: "\e[36m",
11
+ white: "\e[37m"
12
+ }
13
+
14
+ class << self
15
+ def get_code(color)
16
+ COLOR_CODE.fetch(color.to_sym, nil)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -5,6 +5,8 @@ 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
9
+ RESET_CONTEXT_CODE = 6
8
10
 
9
11
  class << self
10
12
  attr_reader :prompt, :prompt_id
@@ -29,6 +31,10 @@ module Richat
29
31
  else
30
32
  handle_choose_prompt(user_input.split(" ").last)
31
33
  end
34
+ elsif user_input == "/context"
35
+ TOGGLE_CONTEXT_CODE
36
+ elsif user_input == "/context-reset"
37
+ RESET_CONTEXT_CODE
32
38
  end
33
39
  end
34
40
  end
@@ -90,6 +96,8 @@ module Richat
90
96
  puts "\e[32m/exit\e[0m exit Richat"
91
97
  puts "\e[32m/config\e[0m show configuration"
92
98
  puts "\e[32m/prompt\e[0m show prompt list"
99
+ puts "\e[32m/context\e[0m toggle chat context"
100
+ puts "\e[32m/context-reset\e[0m reset 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,9 @@ 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" => "💡",
26
+ "user_content_color" => "green"
25
27
  },
26
28
  "sys_cmd" => {
27
29
  "activate_keywords" => [">", "!"],
data/lib/richat/shell.rb CHANGED
@@ -2,7 +2,7 @@ require 'readline'
2
2
 
3
3
  module Richat
4
4
  class Shell
5
- attr_reader :chat_client, :logger, :user_role, :ai_role, :system_role, :history_path
5
+ attr_reader :chat_client, :logger, :user_role, :ai_role, :system_role, :history_path, :user_color
6
6
 
7
7
  def initialize(options = {})
8
8
  @chat_client = options[:chat_client]
@@ -12,6 +12,7 @@ module Richat
12
12
  @system_role = Config.get("log", "system_role")
13
13
  @history_path = File.expand_path(Config.get("shell", "shell_history_file"))
14
14
  File.open(@history_path, 'w') {} unless File.exist?(@history_path)
15
+ @user_color = ColorCode.get_code(Config.get("shell", "user_content_color"))
15
16
  end
16
17
 
17
18
  def call
@@ -36,7 +37,7 @@ module Richat
36
37
  sys_cmd_mode = false
37
38
 
38
39
  begin
39
- while (user_content = Readline.readline(shell_prompt(sys_cmd_mode), true))
40
+ while (user_content = Readline.readline(shell_prompt(sys_cmd_mode, enable_context_message), true))
40
41
  if user_content.empty?
41
42
  Readline::HISTORY&.pop
42
43
  next
@@ -58,9 +59,21 @@ module Richat
58
59
  elsif code == Command::SYS_CHAT_CODE
59
60
  sys_cmd_mode = false
60
61
  next
62
+ elsif code == Command::TOGGLE_CONTEXT_CODE
63
+ enable_context_message = !enable_context_message
64
+ unless enable_context_message
65
+ context_messages = Command.prompt_id ? [{ role: 'system', content: Command.prompt }] : []
66
+ end
67
+ Command.print_info("chat context mode " + (enable_context_message ? "enabled." : "disabled."))
68
+ next
69
+ elsif code == Command::RESET_CONTEXT_CODE
70
+ context_messages = Command.prompt_id ? [{ role: 'system', content: Command.prompt }] : []
71
+ Command.print_info("chat context reset.")
72
+ next
61
73
  end
62
74
  end
63
75
 
76
+ print "\e[0m"
64
77
  logger.call(role: user_role, content: user_content)
65
78
  response = ''
66
79
 
@@ -84,7 +97,7 @@ module Richat
84
97
  context_messages.pop
85
98
  end
86
99
 
87
- puts
100
+ puts "\n\n"
88
101
  end
89
102
  rescue Interrupt
90
103
  if sys_cmd_mode
@@ -108,12 +121,19 @@ module Richat
108
121
 
109
122
  private
110
123
 
111
- def shell_prompt(sys_cmd_mode)
124
+ def shell_prompt(sys_cmd_mode, chat_context_mode)
125
+ prompt_str = "\e[32m#{Command.prompt_id&.+" "}\e[0m"
126
+ if chat_context_mode
127
+ prompt_str += Config.get("shell", "chat_context_indicator")
128
+ end
129
+
112
130
  if sys_cmd_mode
113
- "\e[32m#{Command.prompt_id&.+" "}\e[0m\e[33m>>\e[0m \e[32m$ \e[0m"
131
+ prompt_str += "\e[33m>>\e[0m \e[32m$ \e[0m"
114
132
  else
115
- "\e[32m#{Command.prompt_id&.+" "}\e[0m\e[33m>> \e[0m"
133
+ prompt_str += "\e[33m>> \e[0m#{user_color}"
116
134
  end
135
+
136
+ prompt_str
117
137
  end
118
138
  end
119
139
  end
@@ -1,3 +1,3 @@
1
1
  module Richat
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.6"
3
3
  end
data/lib/richat.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "richat/version"
2
2
 
3
+ require_relative 'richat/color_code'
3
4
  require_relative 'richat/utils'
4
5
  require_relative 'richat/config'
5
6
  require_relative 'richat/command'
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.6
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-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -81,6 +81,7 @@ files:
81
81
  - lib/openai/chat.rb
82
82
  - lib/richat.rb
83
83
  - lib/richat/cli.rb
84
+ - lib/richat/color_code.rb
84
85
  - lib/richat/command.rb
85
86
  - lib/richat/config.rb
86
87
  - lib/richat/logger.rb