richat 0.3.5 → 0.3.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 556b89d96438fa55db8004f7b7c988cc9e6f4e7186b5fe55cb3791e5a7448fc9
4
- data.tar.gz: e7a2ca5f62fa9707130e1d535e4d8ff0137f3f0bcd5ee402b62b64ed01142c01
3
+ metadata.gz: 2fb025384c114dec37924fed7ec5c9d9e9df8346d0b94bd831aacec551602d95
4
+ data.tar.gz: f60c3e845fcc33da304d2cee618219267fd0b4a7136f86afc3f62c094ed7e688
5
5
  SHA512:
6
- metadata.gz: 8a8d20d4dc3d35a34dff1a3821e877404c883adbabb132ef696159048fec580dd1249953a3c6e4dccbc2348e30e6b118934707c72436d9d9a57aadd224f3038f
7
- data.tar.gz: fbb27db3fa171b55d0e01c26bf78f5565169c0a1dc6aa0599c015d04233d0e08d1e306f8b6ff599ad7cc7dacdc09d275768c8016f29a251f85cac8a3b6d9ace9
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
@@ -6,6 +6,7 @@ module Richat
6
6
  SYS_CMD_CODE = 3
7
7
  SYS_CHAT_CODE = 4
8
8
  TOGGLE_CONTEXT_CODE = 5
9
+ RESET_CONTEXT_CODE = 6
9
10
 
10
11
  class << self
11
12
  attr_reader :prompt, :prompt_id
@@ -31,7 +32,9 @@ module Richat
31
32
  handle_choose_prompt(user_input.split(" ").last)
32
33
  end
33
34
  elsif user_input == "/context"
34
- handle_toggle_context
35
+ TOGGLE_CONTEXT_CODE
36
+ elsif user_input == "/context-reset"
37
+ RESET_CONTEXT_CODE
35
38
  end
36
39
  end
37
40
  end
@@ -88,16 +91,13 @@ module Richat
88
91
  NEXT_CODE
89
92
  end
90
93
 
91
- def handle_toggle_context
92
- TOGGLE_CONTEXT_CODE
93
- end
94
-
95
94
  def handle_help
96
95
  puts "Version #{VERSION}"
97
96
  puts "\e[32m/exit\e[0m exit Richat"
98
97
  puts "\e[32m/config\e[0m show configuration"
99
98
  puts "\e[32m/prompt\e[0m show prompt list"
100
99
  puts "\e[32m/context\e[0m toggle chat context"
100
+ puts "\e[32m/context-reset\e[0m reset chat context"
101
101
  puts "\e[32m/help\e[0m show help info"
102
102
  NEXT_CODE
103
103
  end
data/lib/richat/config.rb CHANGED
@@ -22,7 +22,8 @@ module Richat
22
22
  "show_welcome_info" => true,
23
23
  "shell_history_file" => "~/.richat/history.txt",
24
24
  "exit_keywords" => ["/exit", "q", "quit", "exit"],
25
- "chat_context_indicator" => "💡"
25
+ "chat_context_indicator" => "💡",
26
+ "user_content_color" => "green"
26
27
  },
27
28
  "sys_cmd" => {
28
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
@@ -65,9 +66,14 @@ module Richat
65
66
  end
66
67
  Command.print_info("chat context mode " + (enable_context_message ? "enabled." : "disabled."))
67
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
68
73
  end
69
74
  end
70
75
 
76
+ print "\e[0m"
71
77
  logger.call(role: user_role, content: user_content)
72
78
  response = ''
73
79
 
@@ -91,7 +97,7 @@ module Richat
91
97
  context_messages.pop
92
98
  end
93
99
 
94
- puts
100
+ puts "\n\n"
95
101
  end
96
102
  rescue Interrupt
97
103
  if sys_cmd_mode
@@ -124,7 +130,7 @@ module Richat
124
130
  if sys_cmd_mode
125
131
  prompt_str += "\e[33m>>\e[0m \e[32m$ \e[0m"
126
132
  else
127
- prompt_str += "\e[33m>> \e[0m"
133
+ prompt_str += "\e[33m>> \e[0m#{user_color}"
128
134
  end
129
135
 
130
136
  prompt_str
@@ -1,3 +1,3 @@
1
1
  module Richat
2
- VERSION = "0.3.5"
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.5
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-13 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