open_ai_bot 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/open_ai/chat_gpt.rb +10 -2
- 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: ab73dddf78a2ee4632cebce42aa05bfcbed8f2e124bf54c6db3c46ddded104f2
|
4
|
+
data.tar.gz: aced420618f366b93f9255b1002ea4b94cdd20a376be69955afca99143ad37d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03f5fb788b3777e1b112a4d0af08765fad8d1ec35e274543576dea5c43e7ed354aecd0bd69e7ddc1855df3d015c3c1253519e2feec2cd1664073e3fe20966a04
|
7
|
+
data.tar.gz: 693978a14106f13fd183451233d8cbda0d1158b152eba7f02c0f3c70558c830dae4e81eb4ad4235779c3525ec97ddf24ef41244d3b2fedb7c34822306219f0b4
|
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
|
-
|
106
|
+
send_chat_gpt_response(text)
|
107
107
|
@thread.add!(:assistant, text)
|
108
108
|
end
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
112
|
+
def send_chat_gpt_error(text)
|
113
|
+
reply(text, parse_mode: "Markdown")
|
114
|
+
end
|
115
|
+
|
116
|
+
def send_chat_gpt_response(text)
|
117
|
+
reply(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