open_ai_bot 0.3.4 → 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/open_ai/chat_thread.rb +1 -2
- data/lib/open_ai/model.rb +5 -0
- data/lib/open_ai_bot.rb +34 -0
- data/open_ai_bot.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2e5ee8b986bfaff8105b3ae2415e3e5dc0401ad836f4a7b3a3ae4f402c72f07
|
4
|
+
data.tar.gz: 781bef28b9a896f40e7c07933bc9ba180875fc242b992749cc6c5eff82c2cc85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1f0c896c0d569751ceb554502918ecbd6521db9d734b3725a152686c343137b4b3f28c8062da9655eaa2a80fdb85b7320bc8bfea2573d90f5e0a1c522bb49c5
|
7
|
+
data.tar.gz: 5bf24970ad9796510f9de792978529d4413a6d39bd83277c1ab82da296cbb8cc61a2e534194182f3697350e1e8f76b70a5bab1c0a3c855c51ebe204eb5354e7c
|
data/lib/open_ai/chat_thread.rb
CHANGED
@@ -5,12 +5,11 @@ module OpenAI
|
|
5
5
|
def initialize(defaults = [], model)
|
6
6
|
@history ||= defaults
|
7
7
|
@model = model.is_a?(Model) ? model : Model.new(model)
|
8
|
-
puts "Using #{@model}"
|
9
8
|
puts @history
|
10
9
|
end
|
11
10
|
|
12
11
|
attr_reader :history
|
13
|
-
|
12
|
+
attr_accessor :model
|
14
13
|
|
15
14
|
alias_method :messages, :history
|
16
15
|
|
data/lib/open_ai/model.rb
CHANGED
data/lib/open_ai_bot.rb
CHANGED
@@ -19,6 +19,7 @@ class OpenAIBot < Rubydium::Bot
|
|
19
19
|
include OpenAI::Whisper
|
20
20
|
|
21
21
|
on_every_message :handle_gpt_command
|
22
|
+
on_every_message :handle_model_query
|
22
23
|
on_every_message :transcribe
|
23
24
|
|
24
25
|
on_command "/restart", :init_session, description: "Resets ChatGPT session"
|
@@ -36,6 +37,39 @@ class OpenAIBot < Rubydium::Bot
|
|
36
37
|
safe_delete(@msg)
|
37
38
|
end
|
38
39
|
|
40
|
+
on_command "/model" do
|
41
|
+
options = []
|
42
|
+
OpenAI::Model::MODEL_INFO.each do |model, info|
|
43
|
+
options << [
|
44
|
+
Telegram::Bot::Types::InlineKeyboardButton.new(
|
45
|
+
text: "#{model} - #{sprintf('%.2f', info[:output_price])}$",
|
46
|
+
callback_data: "/set #{model}"
|
47
|
+
)
|
48
|
+
]
|
49
|
+
end
|
50
|
+
markup = Telegram::Bot::Types::InlineKeyboardMarkup.new(inline_keyboard: options)
|
51
|
+
reply("Select a model:", reply_markup: markup)
|
52
|
+
end
|
53
|
+
|
54
|
+
def handle_model_query
|
55
|
+
return unless @update.is_a? Telegram::Bot::Types::CallbackQuery
|
56
|
+
return unless @update.data.start_with? "/set "
|
57
|
+
return unless @user.username == config.owner_username
|
58
|
+
|
59
|
+
model = @update.data.delete_prefix("/set ").to_sym
|
60
|
+
return if OpenAI::Model::MODEL_INFO[model].nil?
|
61
|
+
|
62
|
+
text =
|
63
|
+
if current_thread.model.to_sym == model
|
64
|
+
"Already set to `#{model}`"
|
65
|
+
else
|
66
|
+
current_thread.model = OpenAI::Model.new(model)
|
67
|
+
"Was `#{current_thread.model.to_s}`, now `#{model}`"
|
68
|
+
end
|
69
|
+
|
70
|
+
reply(text, parse_mode: "Markdown")
|
71
|
+
end
|
72
|
+
|
39
73
|
def allowed_chat?
|
40
74
|
return true if @user.username == config.owner_username
|
41
75
|
return true if config.open_ai["whitelist"].include?(@chat.id)
|
data/open_ai_bot.gemspec
CHANGED