slack-smart-bot 1.15.0 → 1.15.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +34 -1
  3. data/img/chat_gpt_attach_image.png +0 -0
  4. data/lib/slack/smart-bot/ai/open_ai/models.rb +19 -10
  5. data/lib/slack/smart-bot/ai/open_ai/send_gpt_chat.rb +14 -10
  6. data/lib/slack/smart-bot/comm/dont_understand.rb +23 -6
  7. data/lib/slack/smart-bot/comm/get_user_info.rb +9 -10
  8. data/lib/slack/smart-bot/comm/respond.rb +56 -28
  9. data/lib/slack/smart-bot/comm/send_file.rb +17 -6
  10. data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_chat.rb +885 -129
  11. data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_chat_add_collaborator.rb +3 -3
  12. data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_chat_copy_session.rb +132 -15
  13. data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_chat_delete_session.rb +1 -1
  14. data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_chat_get_prompts.rb +50 -12
  15. data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_chat_list_sessions.rb +99 -34
  16. data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_chat_share_session.rb +12 -2
  17. data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_chat_use_model.rb +36 -25
  18. data/lib/slack/smart-bot/commands/general/bot_help.rb +29 -24
  19. data/lib/slack/smart-bot/commands/general/poster.rb +0 -1
  20. data/lib/slack/smart-bot/commands/general/see_announcements.rb +1 -1
  21. data/lib/slack/smart-bot/commands/general/summarize.rb +22 -8
  22. data/lib/slack/smart-bot/commands/general_bot_commands.rb +156 -55
  23. data/lib/slack/smart-bot/commands/on_bot/general/bot_stats.rb +13 -11
  24. data/lib/slack/smart-bot/commands/on_extended/bot_rules.rb +21 -17
  25. data/lib/slack/smart-bot/commands/on_master/admin_master/exit_bot.rb +2 -2
  26. data/lib/slack/smart-bot/commands.rb +19 -19
  27. data/lib/slack/smart-bot/process_first.rb +38 -35
  28. data/lib/slack/smart-bot/treat_message.rb +57 -56
  29. data/lib/slack/smart-bot/utils/download_http_content.rb +91 -0
  30. data/lib/slack/smart-bot/utils/get_authorizations.rb +41 -0
  31. data/lib/slack/smart-bot/utils/get_keywords.rb +33 -0
  32. data/lib/slack/smart-bot/utils/get_openai_sessions.rb +46 -6
  33. data/lib/slack/smart-bot/utils/get_teams.rb +9 -1
  34. data/lib/slack/smart-bot/utils/save_stats.rb +13 -5
  35. data/lib/slack/smart-bot/utils/transform_to_slack_markdown.rb +36 -0
  36. data/lib/slack/smart-bot/utils/update_openai_sessions.rb +9 -4
  37. data/lib/slack/smart-bot/utils.rb +48 -44
  38. data/lib/slack-smart-bot.rb +10 -10
  39. data/whats_new.txt +27 -1
  40. metadata +49 -8
@@ -23,17 +23,22 @@ class SlackSmartBot
23
23
  file.flock(File::LOCK_UN)
24
24
  }
25
25
  @datetime_open_ai_file[file_name] = File.mtime(file_name)
26
- if session_name != ''
26
+ if session_name.to_s != ''
27
27
  if !@open_ai[team_id_user][:chat_gpt][:sessions].key?(session_name) #delete file if session is not longer available
28
28
  if File.exist?(File.join(config.path, "openai/#{team_id}", "#{user_name}/session_#{session_name}.txt"))
29
29
  File.delete(File.join(config.path, "openai/#{team_id}", "#{user_name}/session_#{session_name}.txt"))
30
30
  end
31
31
  else
32
32
  file_name = File.join(config.path, "openai/#{team_id}", "#{user_name}/session_#{session_name}.txt")
33
- content = @ai_gpt[team_id_user][session_name].join("\n").force_encoding("UTF-8")
33
+ content_txt = ""
34
+ content = []
35
+ @ai_gpt[team_id_user][session_name].each do |line|
36
+ content << line.to_json
37
+ end
38
+ content_txt = content.join("\n").force_encoding("UTF-8")
34
39
  File.open(file_name, 'w') {|file|
35
- file.flock(File::LOCK_EX)
36
- file.write(Utils::Encryption.encrypt(content, config))
40
+ file.flock(File::LOCK_EX)
41
+ file.write(Utils::Encryption.encrypt(content_txt, config))
37
42
  file.flock(File::LOCK_UN)
38
43
  }
39
44
  end
@@ -1,44 +1,48 @@
1
- require_relative 'utils/build_help'
2
- require_relative 'utils/create_routine_thread'
3
- require_relative 'utils/get_bots_created'
4
- require_relative 'utils/get_channels_name_and_id'
5
- require_relative 'utils/get_help'
6
- require_relative 'utils/get_routines'
7
- require_relative 'utils/get_shares'
8
- require_relative 'utils/get_rules_imported'
9
- require_relative 'utils/remove_hash_keys'
10
- require_relative 'utils/update_bots_file'
11
- require_relative 'utils/update_routines'
12
- require_relative 'utils/update_rules_imported'
13
- require_relative 'utils/update_shortcuts_file'
14
- require_relative 'utils/save_stats'
15
- require_relative 'utils/get_repls'
16
- require_relative 'utils/update_repls'
17
- require_relative 'utils/answer'
18
- require_relative 'utils/answer_delete'
19
- require_relative 'utils/has_access'
20
- require_relative 'utils/save_status'
21
- require_relative 'utils/get_admins_channels'
22
- require_relative 'utils/update_admins_channels'
23
- require_relative 'utils/is_admin'
24
- require_relative 'utils/get_access_channels'
25
- require_relative 'utils/update_access_channels'
26
- require_relative 'utils/get_command_ids'
27
- require_relative 'utils/get_teams'
28
- require_relative 'utils/get_vacations'
29
- require_relative 'utils/get_personal_settings'
30
- require_relative 'utils/update_personal_settings'
31
- require_relative 'utils/update_teams'
32
- require_relative 'utils/update_vacations'
33
- require_relative 'utils/check_vacations'
34
- require_relative 'utils/display_calendar'
35
- require_relative 'utils/encryption/encryption_get_key_iv'
36
- require_relative 'utils/encryption/encrypt'
37
- require_relative 'utils/encryption/decrypt'
38
- require_relative 'utils/get_team_members'
39
- require_relative 'utils/get_openai_sessions'
40
- require_relative 'utils/update_openai_sessions'
41
- require_relative 'utils/local_time'
42
- require_relative 'utils/get_countries_candelarific'
43
- require_relative 'utils/upgrade_to_use_team_ids'
44
- require_relative 'utils/find_user'
1
+ require_relative "utils/build_help"
2
+ require_relative "utils/create_routine_thread"
3
+ require_relative "utils/get_bots_created"
4
+ require_relative "utils/get_channels_name_and_id"
5
+ require_relative "utils/get_help"
6
+ require_relative "utils/get_routines"
7
+ require_relative "utils/get_shares"
8
+ require_relative "utils/get_rules_imported"
9
+ require_relative "utils/remove_hash_keys"
10
+ require_relative "utils/update_bots_file"
11
+ require_relative "utils/update_routines"
12
+ require_relative "utils/update_rules_imported"
13
+ require_relative "utils/update_shortcuts_file"
14
+ require_relative "utils/save_stats"
15
+ require_relative "utils/get_repls"
16
+ require_relative "utils/update_repls"
17
+ require_relative "utils/answer"
18
+ require_relative "utils/answer_delete"
19
+ require_relative "utils/has_access"
20
+ require_relative "utils/save_status"
21
+ require_relative "utils/get_admins_channels"
22
+ require_relative "utils/update_admins_channels"
23
+ require_relative "utils/is_admin"
24
+ require_relative "utils/get_access_channels"
25
+ require_relative "utils/update_access_channels"
26
+ require_relative "utils/get_command_ids"
27
+ require_relative "utils/get_teams"
28
+ require_relative "utils/get_vacations"
29
+ require_relative "utils/get_personal_settings"
30
+ require_relative "utils/update_personal_settings"
31
+ require_relative "utils/update_teams"
32
+ require_relative "utils/update_vacations"
33
+ require_relative "utils/check_vacations"
34
+ require_relative "utils/display_calendar"
35
+ require_relative "utils/encryption/encryption_get_key_iv"
36
+ require_relative "utils/encryption/encrypt"
37
+ require_relative "utils/encryption/decrypt"
38
+ require_relative "utils/get_team_members"
39
+ require_relative "utils/get_openai_sessions"
40
+ require_relative "utils/update_openai_sessions"
41
+ require_relative "utils/local_time"
42
+ require_relative "utils/get_countries_candelarific"
43
+ require_relative "utils/upgrade_to_use_team_ids"
44
+ require_relative "utils/find_user"
45
+ require_relative "utils/transform_to_slack_markdown"
46
+ require_relative "utils/download_http_content"
47
+ require_relative "utils/get_authorizations"
48
+ require_relative "utils/get_keywords"
@@ -13,7 +13,8 @@ require "nice_hash"
13
13
  require "cgi"
14
14
  require "yaml"
15
15
  require "nokogiri"
16
- require 'tiktoken_ruby'
16
+ require "tiktoken_ruby"
17
+ require "engtagger"
17
18
 
18
19
  require_relative "slack/smart-bot/config"
19
20
  require_relative "slack/smart-bot/comm"
@@ -127,13 +128,13 @@ class SlackSmartBot
127
128
  config.status_init = ARGV[3].to_sym
128
129
  end
129
130
  if config.team_id_admins.size != config.admins.size and !config.admins.empty?
130
- config.admins.each do |name|
131
- if name.match?(/^[A-Z0-9]{7,11}_/)
132
- config.team_id_admins << name
133
- else
134
- config.team_id_admins << "#{config.team_id}_#{name}"
135
- end
131
+ config.admins.each do |name|
132
+ if name.match?(/^[A-Z0-9]{7,11}_/)
133
+ config.team_id_admins << name
134
+ else
135
+ config.team_id_admins << "#{config.team_id}_#{name}"
136
136
  end
137
+ end
137
138
  end
138
139
  config.team_id_admins.uniq!
139
140
  config.admins.uniq!
@@ -150,7 +151,7 @@ class SlackSmartBot
150
151
  end
151
152
 
152
153
  if (!config.masters.is_a?(Array) or !config.team_id_masters.is_a?(Array)) or
153
- (config.masters + config.team_id_masters).empty?
154
+ (config.masters + config.team_id_masters).empty?
154
155
  message = "You need to supply a masters array on the settings containing the user names of the master admins, for example: [peter]. key: :masters"
155
156
  message += " or a team_id_masters array containing the team_id and user names of the master admins, for example: [TJDFJKD34_peter]. key: :team_id_masters"
156
157
  abort message
@@ -307,7 +308,7 @@ class SlackSmartBot
307
308
  @ldap = nil
308
309
  begin
309
310
  if config.ldap.key?(:host) and config.ldap[:host].to_s != ""
310
- require 'net/ldap'
311
+ require "net/ldap"
311
312
  if config.ldap.key?(:auth) and config.ldap[:auth].key?(:user) and config.ldap[:auth][:user].to_s != ""
312
313
  @ldap = Net::LDAP.new(host: config.ldap.host, port: config.ldap.port, auth: config.ldap.auth)
313
314
  else
@@ -402,7 +403,6 @@ class SlackSmartBot
402
403
  end
403
404
  @admin_users_id.uniq!
404
405
  @master_admin_users_id.uniq!
405
-
406
406
  rescue Slack::Web::Api::Errors::TooManyRequestsError
407
407
  @logger.fatal "TooManyRequestsError"
408
408
  save_status :off, :TooManyRequestsError, "TooManyRequestsError please re run the bot and be sure of executing first: killall ruby"
data/whats_new.txt CHANGED
@@ -1,4 +1,4 @@
1
- *Version 1.15.0* Released 2024-Apr-04
1
+ *Version 1.15.25* Released 2024-Nov-15
2
2
 
3
3
  *For General users*
4
4
  - OpenAI adds specific hosts and access tokens for services. (<https://github.com/MarioRuiz/slack-smart-bot/issues/107|#107>).
@@ -21,6 +21,21 @@
21
21
  - Call `get smartbot readme` to get the README for SmartBot. (<https://github.com/MarioRuiz/slack-smart-bot/issues/128|#128>)
22
22
  - You can call `<bot help` or `<bot rules`. SmartBot will send a Markdown file with extended help commands. Open the file in a new window. You can install this extension in Google Chrome to view it: https://chromewebstore.google.com/detail/medapdbncneneejhbgcjceippjlfkmkg (<https://github.com/MarioRuiz/slack-smart-bot/issues/129|#129>)
23
23
  - It is possible to specify authorizations tokens for any website you want to reach the content using ChatGPT command. When adding to your prompt !URL SmartBot will verify if the domain specified have set an authorization header and add it. To add personal authorization tokens you can do it calling on a DM the commands: `add personal settings authorizations.example.host example.com`, `add personal settings authorizations.example.authorization Xdddj33a_SDFBBBS33Ab` (<https://github.com/MarioRuiz/slack-smart-bot/issues/130|#130>)
24
+ - ChatGPT accepts Google Drive links. In case PDF, Docx, or text files (json, yaml, text...) will extract the content and will be added to the prompt. Use: `?? PROMPT !URL1 !URL2 !URL99`
25
+ - ChatGPT accepts attached images.
26
+ - ChatGPT output is nicer since SmartBot will automatically translate general Markdown to Slack Markdown.
27
+ - Now when on a ChatGPT session if you want to delete the last ChatGPT response and send again last prompt, you can use `resend prompt`.
28
+ - You can set the context of your ChatGPT session: `set context CONTEXT`. Example: `set context You are a funny comedian who tells dad jokes. The output should be in JSON format.`
29
+ - You can remove all prompts from a given session by using `chatgpt clean SESSION_NAME`
30
+ - Add static content to your session by using `add static content URL1 URL99`.
31
+ - Add live content to your session by using `add live content URL1 URL99`. The content will be downloaded and added to your session every time you send a new prompt. See also: `delete live content URL1 URL99`
32
+ - You can add authorizations on a specific ChatGPT session: `add authorization HOST HEADER VALUE`, for example: `add authorization api.example.com Authorization Bearer 123456`.
33
+ Remember to use a DM with SmartBot to keep these values secret.
34
+ If you share this session as public or for a specific channel, users will be able to send prompts for that session using your authorizations but they won't be able to see the auth values or copy those auth to a new chatgpt session.
35
+ - It is possible to use a session that is public, private or shared with a channel as a temporary session: `?? use SESSION_NAME PROMPT`. For example: `?? use lunch What's for Thursday?`
36
+ - You can add collaborators on temporary ChatGPT sessions
37
+ - Add messages from a channel to your session by using `add history #CHANNEL_NAME`.
38
+ - When you send a wrong command, SmartBot ChatGPT will tell you which commands could be the ones you wanted to call.
24
39
 
25
40
  *For Admin users*
26
41
  - ChatGPT now supports Azure. (<https://github.com/MarioRuiz/slack-smart-bot/issues/109|#109>)
@@ -30,6 +45,17 @@
30
45
  - It is possible now to use LLM proxy for ChatGPT and also specify a concrete end point to get the models.
31
46
  - Added LDAP settings in config. (<https://github.com/MarioRuiz/slack-smart-bot/issues/131|#131>)
32
47
  - Added authorizations settings in config. (<https://github.com/MarioRuiz/slack-smart-bot/issues/130|#130>)
48
+ - Doc folders can be added by admins for specific chatgpt sessions. SmartBot will filter those docs depending on the prompt and attach them along with the prompt.
49
+ Put all docs as text files on `./openai/TEAM_ID/USER_NAME/SESSION_NAME/docs_folder`.
50
+ For the documents to be filtered add them to `filter` subfolder under `docs_folder`.
51
+ For the documents to be added always to the prompts, add them to `include` subfolder under `docs_folder`.
52
+ Inside those subfolders you can organize the documents the way you want.
53
+ - You can add a file named restricted_models.yaml on ./openai folder supplying the models and users that will have access to specific models.
54
+ Example of content:
55
+ o1-mini: [rmario, peter]
56
+ o1-preview: [rmario]
57
+
58
+
33
59
 
34
60
  ------------------------------
35
61
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack-smart-bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.15.0
4
+ version: 1.15.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mario Ruiz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-05 00:00:00.000000000 Z
11
+ date: 2024-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slack-ruby-client
@@ -215,25 +215,61 @@ dependencies:
215
215
  - !ruby/object:Gem::Version
216
216
  version: '1'
217
217
  - !ruby/object:Gem::Dependency
218
- name: tiktoken_ruby
218
+ name: pdf-reader
219
219
  requirement: !ruby/object:Gem::Requirement
220
220
  requirements:
221
221
  - - "~>"
222
222
  - !ruby/object:Gem::Version
223
- version: '0'
224
- - - ">="
223
+ version: '2.12'
224
+ type: :runtime
225
+ prerelease: false
226
+ version_requirements: !ruby/object:Gem::Requirement
227
+ requirements:
228
+ - - "~>"
225
229
  - !ruby/object:Gem::Version
226
- version: 0.0.7
230
+ version: '2.12'
231
+ - !ruby/object:Gem::Dependency
232
+ name: docx
233
+ requirement: !ruby/object:Gem::Requirement
234
+ requirements:
235
+ - - "~>"
236
+ - !ruby/object:Gem::Version
237
+ version: '0.8'
227
238
  type: :runtime
228
239
  prerelease: false
229
240
  version_requirements: !ruby/object:Gem::Requirement
230
241
  requirements:
231
242
  - - "~>"
232
243
  - !ruby/object:Gem::Version
233
- version: '0'
234
- - - ">="
244
+ version: '0.8'
245
+ - !ruby/object:Gem::Dependency
246
+ name: tiktoken_ruby
247
+ requirement: !ruby/object:Gem::Requirement
248
+ requirements:
249
+ - - "~>"
235
250
  - !ruby/object:Gem::Version
236
251
  version: 0.0.7
252
+ type: :runtime
253
+ prerelease: false
254
+ version_requirements: !ruby/object:Gem::Requirement
255
+ requirements:
256
+ - - "~>"
257
+ - !ruby/object:Gem::Version
258
+ version: 0.0.7
259
+ - !ruby/object:Gem::Dependency
260
+ name: engtagger
261
+ requirement: !ruby/object:Gem::Requirement
262
+ requirements:
263
+ - - "~>"
264
+ - !ruby/object:Gem::Version
265
+ version: '0.4'
266
+ type: :runtime
267
+ prerelease: false
268
+ version_requirements: !ruby/object:Gem::Requirement
269
+ requirements:
270
+ - - "~>"
271
+ - !ruby/object:Gem::Version
272
+ version: '0.4'
237
273
  - !ruby/object:Gem::Dependency
238
274
  name: rspec
239
275
  requirement: !ruby/object:Gem::Requirement
@@ -264,6 +300,7 @@ files:
264
300
  - LICENSE
265
301
  - README.md
266
302
  - img/chat_gpt.png
303
+ - img/chat_gpt_attach_image.png
267
304
  - img/chat_gpt_session.png
268
305
  - img/chat_gpt_share.png
269
306
  - img/command_add_sc.png
@@ -437,17 +474,20 @@ files:
437
474
  - lib/slack/smart-bot/utils/check_vacations.rb
438
475
  - lib/slack/smart-bot/utils/create_routine_thread.rb
439
476
  - lib/slack/smart-bot/utils/display_calendar.rb
477
+ - lib/slack/smart-bot/utils/download_http_content.rb
440
478
  - lib/slack/smart-bot/utils/encryption/decrypt.rb
441
479
  - lib/slack/smart-bot/utils/encryption/encrypt.rb
442
480
  - lib/slack/smart-bot/utils/encryption/encryption_get_key_iv.rb
443
481
  - lib/slack/smart-bot/utils/find_user.rb
444
482
  - lib/slack/smart-bot/utils/get_access_channels.rb
445
483
  - lib/slack/smart-bot/utils/get_admins_channels.rb
484
+ - lib/slack/smart-bot/utils/get_authorizations.rb
446
485
  - lib/slack/smart-bot/utils/get_bots_created.rb
447
486
  - lib/slack/smart-bot/utils/get_channels_name_and_id.rb
448
487
  - lib/slack/smart-bot/utils/get_command_ids.rb
449
488
  - lib/slack/smart-bot/utils/get_countries_candelarific.rb
450
489
  - lib/slack/smart-bot/utils/get_help.rb
490
+ - lib/slack/smart-bot/utils/get_keywords.rb
451
491
  - lib/slack/smart-bot/utils/get_openai_sessions.rb
452
492
  - lib/slack/smart-bot/utils/get_personal_settings.rb
453
493
  - lib/slack/smart-bot/utils/get_repls.rb
@@ -463,6 +503,7 @@ files:
463
503
  - lib/slack/smart-bot/utils/remove_hash_keys.rb
464
504
  - lib/slack/smart-bot/utils/save_stats.rb
465
505
  - lib/slack/smart-bot/utils/save_status.rb
506
+ - lib/slack/smart-bot/utils/transform_to_slack_markdown.rb
466
507
  - lib/slack/smart-bot/utils/update_access_channels.rb
467
508
  - lib/slack/smart-bot/utils/update_admins_channels.rb
468
509
  - lib/slack/smart-bot/utils/update_bots_file.rb