open_ai_bot 0.1.0 → 0.2.1
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/README.md +1 -1
- data/lib/open_ai/chat_gpt.rb +11 -3
- data/lib/open_ai/whisper.rb +10 -2
- 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: 30c76c2d4d679490aeec769f27b4a94411d10457b9671635bac4155137159c4e
|
4
|
+
data.tar.gz: da3ecae84c2ae4edd70e763e0ee4934e081bbd50332939c08252d507f69b1b90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ef87f990db2fff4d8d679e127a181ffc957dbdd7c9c995aec2bf489d61973d4a2d8acd3f161bcdedb3277cf841e24451d551989cfecaec83a4e7a49ace62f75
|
7
|
+
data.tar.gz: ad732c08a12433986d7a2214c3f9cdcaf8704d555960a8ace5bc8c82f835276b216157394d215b38ec3e5426cd11c6273cc416f5a9ad055eba708380d1161421
|
data/README.md
CHANGED
@@ -44,7 +44,7 @@ echo 'ruby 3.2.2' >> ~/.tool-versions
|
|
44
44
|
|
45
45
|
2. Require this project as a dependency:
|
46
46
|
- Create a new Ruby project
|
47
|
-
- In the Gemfile, add `gem "open_ai_bot"
|
47
|
+
- In the Gemfile, add `gem "open_ai_bot"`
|
48
48
|
- Inherit your bot class from `OpenAIBot`
|
49
49
|
|
50
50
|
## Run
|
data/lib/open_ai/chat_gpt.rb
CHANGED
@@ -98,17 +98,25 @@ module ChatGPT
|
|
98
98
|
if response["error"]
|
99
99
|
error_text = "```#{response["error"]["message"]}```"
|
100
100
|
error_text += "\n\nHint: send /restart command to reset the context." if error_text.match? "tokens"
|
101
|
-
|
101
|
+
send_chat_gpt_error(error_text.strip)
|
102
102
|
else
|
103
103
|
text = response.dig("choices", 0, "message", "content")
|
104
104
|
puts "#{Time.now.utc} | Chat ID: #{@chat.id}, tokens used: #{response.dig("usage", "total_tokens")}"
|
105
105
|
|
106
|
-
|
107
|
-
@thread.add!(:assistant, text)
|
106
|
+
send_chat_gpt_response(text)
|
108
107
|
end
|
109
108
|
end
|
110
109
|
end
|
111
110
|
|
111
|
+
def send_chat_gpt_error(text)
|
112
|
+
reply(text, parse_mode: "Markdown")
|
113
|
+
end
|
114
|
+
|
115
|
+
def send_chat_gpt_response(text)
|
116
|
+
reply(text)
|
117
|
+
@thread.add!(:assistant, text)
|
118
|
+
end
|
119
|
+
|
112
120
|
def add_name(name, text)
|
113
121
|
return "" if text.nil? || text.empty?
|
114
122
|
|
data/lib/open_ai/whisper.rb
CHANGED
@@ -26,15 +26,23 @@ module Whisper
|
|
26
26
|
response = send_whisper_request(file[:file])
|
27
27
|
|
28
28
|
if response["error"]
|
29
|
-
|
29
|
+
send_whisper_error(response["error"])
|
30
30
|
else
|
31
|
-
|
31
|
+
send_whisper_response(response["text"])
|
32
32
|
end
|
33
33
|
ensure
|
34
34
|
FileUtils.rm_rf(file[:names]) if file
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
def send_whisper_response(text)
|
39
|
+
reply(text)
|
40
|
+
end
|
41
|
+
|
42
|
+
def send_whisper_error
|
43
|
+
reply_code(text)
|
44
|
+
end
|
45
|
+
|
38
46
|
def ogg_to_mp3(file)
|
39
47
|
ogg = file.original_filename
|
40
48
|
mp3 = ogg.sub(/og.\z/, "mp3")
|
data/open_ai_bot.gemspec
CHANGED