chatgpt_assistant 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.env_sample +21 -5
- data/README.md +9 -6
- data/lib/chatgpt_assistant/audio_synthesis.rb +54 -15
- data/lib/chatgpt_assistant/bots/discord/actions.rb +0 -1
- data/lib/chatgpt_assistant/bots/discord_bot.rb +3 -4
- data/lib/chatgpt_assistant/bots/telegram/events.rb +2 -1
- data/lib/chatgpt_assistant/bots/telegram/validations.rb +1 -1
- data/lib/chatgpt_assistant/config.rb +3 -0
- data/lib/chatgpt_assistant/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb819ab0257d4970e716aed3d6d59cb5ef89d0476525b5c7dbd93f03df97b309
|
4
|
+
data.tar.gz: 9ce437ae8051fab6fbfd0b446fdaecd60f17dad068d55d96d572877c915b217f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aac472695d96b1566294928d09a80b4d49f995519da1df049f85aa8a51baff1585e35f8669f2842755423303f4a1b27eb740a7ca9c00691978e47254edbd5494
|
7
|
+
data.tar.gz: fd8075eb05fe5e354676311884ba55f26ae5a073536076a4d40914e34a66c4e45e7f98e9d85967d9a36828362f4cf9076d2e74af2c99359fddbf39fd907218db
|
data/.env_sample
CHANGED
@@ -1,22 +1,38 @@
|
|
1
|
+
# Bot Settings
|
1
2
|
ENV_TYPE=development
|
2
3
|
LANGUAGE=en
|
3
4
|
MODE=aws
|
4
5
|
DISCORD_PREFIX=!!
|
6
|
+
LUCY_SU= Your command to run docker compose as root
|
5
7
|
|
8
|
+
# Database Settings
|
6
9
|
POSTGRES_DB=chatgpt_assistant_development
|
7
10
|
POSTGRES_USER=postgres
|
8
11
|
POSTGRES_PASSWORD=postgres
|
9
12
|
|
10
|
-
|
11
|
-
|
13
|
+
# Server Settings
|
14
|
+
REDIS_URL=redis://localhost:6379
|
15
|
+
|
16
|
+
# Bot Settings
|
12
17
|
TELEGRAM_TOKEN=Your Telegram Bot Token
|
18
|
+
DISCORD_CLIENT_ID=Your Discord Client ID
|
19
|
+
DISCORD_TOKEN=Your Discord Token
|
20
|
+
|
21
|
+
# OpenAI Settings
|
13
22
|
OPENAI_API_KEY=Your OpenAI API Key
|
14
|
-
|
23
|
+
|
24
|
+
# API Settings - Set MODE to the API you want to use for text to speech
|
25
|
+
IBM_API_KEY=Your IBM API Key # set MODE=ibm
|
26
|
+
IBM_URL=Your IBM Text to Speech URL
|
27
|
+
|
28
|
+
AWS_ACCESS_KEY=Your AWS Access Key ID # set MODE=aws
|
15
29
|
AWS_SECRET_ACCESS_KEY=Your AWS Secret Access Key
|
16
30
|
AWS_REGION=Your AWS Region
|
17
|
-
DISCORD_CLIENT_ID=Your Discord Client ID
|
18
|
-
DISCORD_TOKEN=Your Discord Token
|
19
31
|
|
32
|
+
AZURE_SPEECH_URL= YOUR_AZURE_SPEECH_URL # set MODE=azure
|
33
|
+
AZURE_SPEECH_KEY= YOUR_AZURE_SPEECH_KEY
|
34
|
+
|
35
|
+
# SMTP Settings
|
20
36
|
SMTP_ADDRESS=YOUR_SMTP_ADDRESS
|
21
37
|
SMTP_PASSWORD=YOUR_SMTP_PASSWORD
|
22
38
|
SMTP_PORT=YOUR_SMTP_PORT
|
data/README.md
CHANGED
@@ -4,16 +4,19 @@
|
|
4
4
|
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
|
5
5
|
[![Ruby Version](https://img.shields.io/badge/Ruby-2.6.0%2B-blue.svg)](https://www.ruby-lang.org/en/)
|
6
6
|
|
7
|
-
This Ruby gem provides an easy way to initialize a client for Telegram and Discord bots using the ChatGPT API, audio transcription,
|
7
|
+
This Ruby gem provides an easy way to initialize a client for Telegram and Discord bots using the ChatGPT API, audio transcription, Text to Speech, creating an assistant that can answer questions in text and voice and have a conversation with the user.
|
8
|
+
|
9
|
+
#### Voice messages on telegram only - discord voice bot is not available and not planned to be implemented anymore
|
10
|
+
##### Discord voice bot is been replaced by a voice assistant local packege to act like google assistant, alexa, siri, cortana, etc. The voice assistant is been developed to linux and android, but it can be ported to other platforms in the future.
|
11
|
+
|
12
|
+
#### Speech to Text services - OpenAI Audio Transcription
|
13
|
+
##### More services will be added in the future
|
14
|
+
#### Text to Speech services - IBM Watson, AWS Polly, Azure Text to Speech
|
8
15
|
|
9
|
-
#### Discord Voice Bot temporary disabled due connection issues
|
10
|
-
#### Telegram voice messages are working fine
|
11
16
|
#### Languages supported currently: en, pt
|
12
17
|
|
13
18
|
#### Registration and Account Confirmation are avaiable on telegram only, sign in with the same credentials on discord after registering on telegram.
|
14
19
|
|
15
|
-
Other contributions are welcome too!
|
16
|
-
Remember to give a star to this repo if you like it!
|
17
20
|
## Requirements
|
18
21
|
|
19
22
|
- Ruby > 2.6.0 - for the gem who can create bots projects in your machine
|
@@ -59,7 +62,7 @@ Make sure to run bundle before using the Lucy Dockerunner rake tasks.
|
|
59
62
|
|
60
63
|
Then, edit the .env_sample file to include the necessary credentials and rename it to .env. Run bundle install to install the necessary dependencies.
|
61
64
|
|
62
|
-
|
65
|
+
Include `LUCY_SU=sudo` in your .env if u run docker compose with sudo
|
63
66
|
|
64
67
|
## Migrate your database
|
65
68
|
```bash
|
@@ -6,31 +6,28 @@ module ChatgptAssistant
|
|
6
6
|
class AudioSynthesis
|
7
7
|
def initialize(config)
|
8
8
|
@config = config
|
9
|
-
@openai_api_key = config.openai_api_key
|
10
9
|
@language = config.language
|
11
|
-
@conn = faraday_instance
|
12
10
|
classify_mode
|
13
11
|
end
|
14
12
|
|
15
13
|
def synthesize_text(text)
|
14
|
+
@text = text
|
16
15
|
if ibm_mode?
|
17
|
-
synthesize_text_ibm
|
16
|
+
synthesize_text_ibm
|
18
17
|
elsif aws_mode?
|
19
|
-
synthesize_text_aws
|
18
|
+
synthesize_text_aws
|
19
|
+
elsif azure_mode?
|
20
|
+
synthesize_text_azure
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
23
24
|
private
|
24
25
|
|
25
|
-
attr_reader :
|
26
|
-
:config, :language, :voice
|
26
|
+
attr_reader :ibm_api_key, :ibm_url, :aws_access_key_id, :aws_secret_access_key, :aws_region,
|
27
|
+
:config, :language, :voice, :azure_speech_url, :azure_speech_key, :text
|
27
28
|
|
28
|
-
def
|
29
|
-
Faraday.new(url:
|
30
|
-
faraday.request :multipart
|
31
|
-
faraday.request :url_encoded
|
32
|
-
faraday.adapter Faraday.default_adapter
|
33
|
-
end
|
29
|
+
def conn(url)
|
30
|
+
Faraday.new(url: url)
|
34
31
|
end
|
35
32
|
|
36
33
|
def classify_mode
|
@@ -43,12 +40,14 @@ module ChatgptAssistant
|
|
43
40
|
@aws_secret_access_key = config.aws_secret_access_key
|
44
41
|
@aws_region = config.aws_region
|
45
42
|
@voice = send("#{language}_aws_voice")
|
43
|
+
elsif azure_mode?
|
44
|
+
@azure_speech_url = config.azure_speech_url
|
45
|
+
@azure_speech_key = config.azure_speech_key
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
def synthesize_text_aws
|
49
|
+
def synthesize_text_aws
|
50
50
|
time = Time.now.to_i
|
51
|
-
@time = Time.now.to_i
|
52
51
|
polly_client = Aws::Polly::Client.new(
|
53
52
|
access_key_id: aws_access_key_id,
|
54
53
|
secret_access_key: aws_secret_access_key,
|
@@ -65,7 +64,7 @@ module ChatgptAssistant
|
|
65
64
|
"voice/aws-#{time}.mp3"
|
66
65
|
end
|
67
66
|
|
68
|
-
def synthesize_text_ibm
|
67
|
+
def synthesize_text_ibm
|
69
68
|
time = Time.now.to_i
|
70
69
|
authenticator = IBMWatson::Authenticators::IamAuthenticator.new(
|
71
70
|
apikey: ibm_api_key
|
@@ -88,6 +87,25 @@ module ChatgptAssistant
|
|
88
87
|
"voice/ibm-#{time}.mp3"
|
89
88
|
end
|
90
89
|
|
90
|
+
def synthesize_text_azure
|
91
|
+
@voice = send("#{language}_azure_voice")
|
92
|
+
time = Time.now.to_i
|
93
|
+
headers = {
|
94
|
+
"Ocp-Apim-Subscription-Key": azure_speech_key,
|
95
|
+
"Content-Type": "application/ssml+xml",
|
96
|
+
"X-Microsoft-OutputFormat": "audio-48khz-192kbitrate-mono-mp3",
|
97
|
+
"User-Agent": "curl"
|
98
|
+
}
|
99
|
+
|
100
|
+
response = conn(azure_speech_url).post do |req|
|
101
|
+
req.headers = headers
|
102
|
+
req.body = voice
|
103
|
+
end
|
104
|
+
|
105
|
+
File.binwrite("voice/azure-#{time}.mp3", response.body)
|
106
|
+
"voice/azure-#{time}.mp3"
|
107
|
+
end
|
108
|
+
|
91
109
|
def pt_aws_voice
|
92
110
|
"Vitoria"
|
93
111
|
end
|
@@ -104,6 +122,23 @@ module ChatgptAssistant
|
|
104
122
|
"en-US_AllisonV3Voice"
|
105
123
|
end
|
106
124
|
|
125
|
+
def pt_azure_voice
|
126
|
+
<<~XML
|
127
|
+
<speak xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="http://www.w3.org/2001/mstts"
|
128
|
+
xmlns:emo="http://www.w3.org/2009/10/emotionml" version="1.0" xml:lang="pt-BR">
|
129
|
+
<voice name="pt-BR-AntonioNeural">#{text}</voice>
|
130
|
+
</speak>
|
131
|
+
XML
|
132
|
+
end
|
133
|
+
|
134
|
+
def en_azure_voice
|
135
|
+
<<~XML
|
136
|
+
<speak xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="http://www.w3.org/2001/mstts" xmlns:emo="http://www.w3.org/2009/10/emotionml" version="1.0" xml:lang="en-US">
|
137
|
+
<voice name="en-US-JennyNeural">#{text}</voice>
|
138
|
+
</speak>
|
139
|
+
XML
|
140
|
+
end
|
141
|
+
|
107
142
|
def ibm_mode?
|
108
143
|
config.mode == "ibm"
|
109
144
|
end
|
@@ -111,5 +146,9 @@ module ChatgptAssistant
|
|
111
146
|
def aws_mode?
|
112
147
|
config.mode == "aws"
|
113
148
|
end
|
149
|
+
|
150
|
+
def azure_mode?
|
151
|
+
config.mode == "azure"
|
152
|
+
end
|
114
153
|
end
|
115
154
|
end
|
@@ -10,7 +10,6 @@ module ChatgptAssistant
|
|
10
10
|
when "user not found"
|
11
11
|
send_message error_messages[:user_not_found]
|
12
12
|
when "wrong password"
|
13
|
-
puts "wrong password"
|
14
13
|
send_message error_messages[:wrong_password]
|
15
14
|
when find_user(email: user_email).email
|
16
15
|
send_message success_messages[:user_logged_in]
|
@@ -7,7 +7,7 @@ require_relative "discord/chat_actions"
|
|
7
7
|
require_relative "discord/events"
|
8
8
|
require_relative "discord/voice_actions"
|
9
9
|
require_relative "discord/voice_checkers"
|
10
|
-
|
10
|
+
require_relative "discord/validations"
|
11
11
|
module ChatgptAssistant
|
12
12
|
# This class is responsible to handle the discord bot
|
13
13
|
class DiscordBot < ApplicationBot
|
@@ -20,8 +20,6 @@ module ChatgptAssistant
|
|
20
20
|
new_chat_event
|
21
21
|
sl_chat_event
|
22
22
|
ask_event
|
23
|
-
voice_connect_event
|
24
|
-
voice_disconnect_event
|
25
23
|
private_message_event
|
26
24
|
bot_init
|
27
25
|
end
|
@@ -29,7 +27,7 @@ module ChatgptAssistant
|
|
29
27
|
private
|
30
28
|
|
31
29
|
attr_reader :message
|
32
|
-
attr_accessor :evnt, :
|
30
|
+
attr_accessor :evnt, :chats, :chat
|
33
31
|
|
34
32
|
include Bots::Discord::Bot
|
35
33
|
include Bots::Discord::Auth
|
@@ -38,5 +36,6 @@ module ChatgptAssistant
|
|
38
36
|
include Bots::Discord::Events
|
39
37
|
include Bots::Discord::VoiceActions
|
40
38
|
include Bots::Discord::VoiceCheckers
|
39
|
+
include Bots::Discord::Validations
|
41
40
|
end
|
42
41
|
end
|
@@ -39,7 +39,7 @@ module ChatgptAssistant
|
|
39
39
|
user_info = msg.text.split("/* ").last
|
40
40
|
name, token = user_info.split(":")
|
41
41
|
send_message "#{name} - #{token}", msg.chat.id
|
42
|
-
if user_confirmed?
|
42
|
+
if user_confirmed?(name, token)
|
43
43
|
send_message success_messages[:account_confirmed], msg.chat.id
|
44
44
|
else
|
45
45
|
send_message error_messages[:account_not_confirmed], msg.chat.id
|
@@ -104,6 +104,7 @@ module ChatgptAssistant
|
|
104
104
|
ai_response = telegram_process_ai_voice(user_audio[:file])
|
105
105
|
telegram_send_voice_message(voice: ai_response[:voice], text: ai_response[:text])
|
106
106
|
delete_file ai_response[:voice]
|
107
|
+
delete_file user_audio[:file]
|
107
108
|
rescue UserNotLoggedInError, NoChatSelectedError, MessageNotCreatedError, AccountNotVerifiedError => e
|
108
109
|
send_message e.message, msg.chat.id
|
109
110
|
end
|
@@ -46,7 +46,7 @@ module ChatgptAssistant
|
|
46
46
|
msg.text.include?("login/") || msg.text.include?("register/") || msg.text.include?("sign_out/") || msg.text.include?("confirm/* ")
|
47
47
|
end
|
48
48
|
|
49
|
-
def user_confirmed?
|
49
|
+
def user_confirmed?(name, token)
|
50
50
|
user.name == name && user.confirm_account(token)
|
51
51
|
end
|
52
52
|
end
|
@@ -27,11 +27,14 @@ module ChatgptAssistant
|
|
27
27
|
@aws_secret_access_key = ENV.fetch("AWS_SECRET_ACCESS_KEY", nil)
|
28
28
|
@aws_region = ENV.fetch("AWS_REGION", nil)
|
29
29
|
@discord_prefix = ENV.fetch("DISCORD_PREFIX", nil)
|
30
|
+
@azure_speech_url = ENV.fetch("AZURE_SPEECH_URL", nil)
|
31
|
+
@azure_speech_key = ENV.fetch("AZURE_SPEECH_KEY", nil)
|
30
32
|
end
|
31
33
|
|
32
34
|
attr_reader :openai_api_key, :telegram_token, :discord_token, :ibm_api_key, :ibm_url,
|
33
35
|
:aws_access_key_id, :aws_secret_access_key, :aws_region, :mode, :language,
|
34
36
|
:discord_client_id, :discord_public_key, :env_type, :discord_prefix,
|
37
|
+
:azure_speech_url, :azure_speech_key,
|
35
38
|
:smtp_address, :smtp_port, :smtp_domain, :smtp_user_name, :smtp_password,
|
36
39
|
:smtp_authentication, :smtp_enable_starttls_auto
|
37
40
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chatgpt_assistant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- JesusGautamah
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-07-
|
11
|
+
date: 2023-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |-
|
14
14
|
This gem has the intention to facilitate the creation of chatbots with Chatgpt,
|
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
117
|
- !ruby/object:Gem::Version
|
118
118
|
version: '0'
|
119
119
|
requirements: []
|
120
|
-
rubygems_version: 3.
|
120
|
+
rubygems_version: 3.4.10
|
121
121
|
signing_key:
|
122
122
|
specification_version: 4
|
123
123
|
summary: Easy way chatbot with Chatgpt, Telegram bot, Discord bot, currently using
|