chatgpt_assistant 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,144 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ChatgptAssistant
4
+ # This class is responsible for storing the default messages
5
+ class DefaultMessages
6
+ def initialize(language = "en")
7
+ @language = language
8
+ load_message_context
9
+ end
10
+
11
+ attr_reader :language, :commom_messages, :success_messages, :error_messages, :help_messages
12
+
13
+ def load_message_context
14
+ @commom_messages = send("commom_messages_#{language}")
15
+ @success_messages = send("success_messages_#{language}")
16
+ @error_messages = send("error_messages_#{language}")
17
+ @help_messages = send("help_messages_#{language}")
18
+ end
19
+
20
+ private
21
+
22
+ def commom_messages_pt
23
+ {
24
+ start: "Olá, eu sou o Chatgpt Assistant, um chatbot que usa a API da OpenAI para responder suas perguntas no Telegram e Discord.",
25
+ stop: "Até mais!",
26
+ start_helper: "Primeiro, é necessário cadastrar seu usuário no banco de dados.
27
+ \nPara isso, mande ume mensagem com seu email e senha de acesso de 4 digitos.
28
+ \nExemplo: register/user@email.com:1234",
29
+ start_sec_helper: "Caso você já tenha um usuário cadastrado, basta fazer login.
30
+ \nExemplo: login/user@email.com:3214",
31
+ register: "Para se registrar no sistema, digite register/email:senha (a senha deve ser um numero de 4 digitos ex: 1234).
32
+ \nExemplo de Registro: register/user@email.com:3214",
33
+ login: "Para fazer login no sistema, digite login/email:senha (a senha deve ser um numero de 4 digitos ex: 1234).
34
+ \nExemplo de Login: login/user@mail.com:2134",
35
+ chat_list: "Aqui estão os chats que você criou:"
36
+ }
37
+ end
38
+
39
+ def success_messages_pt
40
+ {
41
+ user_created: "Usuário criado com sucesso!",
42
+ chat_created: "Chat criado com sucesso!",
43
+ chat_selected: "Chat selecionado com sucesso!",
44
+ user_logged_in: "Login realizado com sucesso!",
45
+ voice_channel_connected: "O bot entrou no canal de voz com sucesso!"
46
+ }
47
+ end
48
+
49
+ def error_messages_pt
50
+ {
51
+ nil: "Não entendi o que você disse. Tente novamente",
52
+ email: "O email que você digitou não é válido. Tente novamente",
53
+ password: "A senha que você digitou não é válida. Tente novamente",
54
+ user: "O usuário que você digitou não existe. Tente novamente",
55
+ user_creation: "Erro ao criar usuário. Tente novamente",
56
+ user_already_exists: "O usuário que você digitou já existe. Tente novamente",
57
+ chat_creation: "Erro ao criar chat. Tente novamente",
58
+ no_messages_founded: "Nenhuma mensagem encontrada",
59
+ no_chat_selected: "Nenhum chat selecionado",
60
+ chat_not_found: "Chat não encontrado",
61
+ no_chats_founded: "Nenhum chat encontrado",
62
+ user_not_logged_in: "Usuário não logado",
63
+ user_not_found: "Usuário não encontrado",
64
+ something_went_wrong: "Algo deu errado. Tente novamente mais tarde.",
65
+ message_history_too_long: "O histórico mensagem é muito longo.",
66
+ text_length: "O texto de resposta é muito longo. Tente diminuir a quantidade de respostas na mesma mensagem.",
67
+ user_not_in_voice_channel: "Você não está em um canal de voz.",
68
+ bot_not_in_voice_channel: "O bot não está em um canal de voz.",
69
+ invalid_command: "Comando inválido. Tente novamente."
70
+ }
71
+ end
72
+
73
+ def help_messages_pt
74
+ ["Para começar a conversar comigo, digite /start",
75
+ "Para parar de conversar comigo, digite /stop",
76
+ "Para se registrar no sistema, digite register/email:senha (a senha deve ser um numero de 4 digitos ex: 1234)",
77
+ "Para fazer login no sistema, digite login/email:senha (a senha deve ser um numero de 4 digitos ex: 1234)",
78
+ "Para criar um novo chat, digite new_chat/nome do chat",
79
+ "Para selecionar um chat, digite sl_chat/nome do chat",
80
+ "Para listar os chats que você criou, digite /list",
81
+ "Para ver esta mensagem novamente, digite /help"]
82
+ end
83
+
84
+ def commom_messages_en
85
+ {
86
+ start: "Hello, I'm the Chatgpt Assistant, a chatbot that uses the OpenAI API to answer your questions on Telegram and Discord.",
87
+ stop: "See you later!",
88
+ start_helper: "First, you need to register your user in the database.
89
+ \nTo do this, send a message with your email and password of 4 digits access.
90
+ \nExample: register/user@mail.com:3421",
91
+ start_sec_helper: "If you already have a registered user, just log in.
92
+ \nExample: login/user@mail.com:5423",
93
+ register: "To register in the system, type register/email:password (the password must be a 4 digit number ex: 1234).
94
+ \nExample of Registration: register/user@mail.com:3241",
95
+ login: "To log in to the system, type login/email:password (the password must be a 4 digit number ex: 1234).
96
+ \nExample of Login: login/user@mail.com:2134",
97
+ chat_list: "Here are the chats you created:"
98
+ }
99
+ end
100
+
101
+ def success_messages_en
102
+ {
103
+ user_created: "User created successfully!",
104
+ chat_created: "Chat created successfully!",
105
+ chat_selected: "Chat selected successfully!",
106
+ user_logged_in: "Login successfully!"
107
+ }
108
+ end
109
+
110
+ def error_messages_en
111
+ {
112
+ nil: "I didn't understand what you said. Try again",
113
+ email: "The email you typed is not valid. Try again",
114
+ password: "The password you typed is not valid. Try again",
115
+ user: "The user you typed does not exist. Try again",
116
+ user_creation: "Error creating user. Try again",
117
+ chat_creation: "Error creating chat. Try again",
118
+ no_messages_founded: "No messages found",
119
+ no_chat_selected: "No chat selected",
120
+ no_chats_founded: "No chats found",
121
+ chat_not_found: "Chat not found",
122
+ user_not_logged_in: "User not logged in",
123
+ user_not_found: "User not found",
124
+ something_went_wrong: "Something went wrong. Try again later.",
125
+ message_history_too_long: "The message history is too long.",
126
+ text_length: "The response text is too long. Try to reduce the number of answers in the same message.",
127
+ user_not_in_voice_channel: "You are not in a voice channel.",
128
+ bot_not_in_voice_channel: "The bot is not in a voice channel.",
129
+ invalid_command: "Invalid command. Try again."
130
+ }
131
+ end
132
+
133
+ def help_messages_en
134
+ ["To start talking to me, type /start",
135
+ "To stop talking to me, type /stop",
136
+ "To register in the system, type register/email:password (the password must be a 4 digit number ex: 1234)",
137
+ "To log in to the system, type login/email:password (the password must be a 4 digit number ex: 1234)",
138
+ "To create a new chat, type new_chat/chat name",
139
+ "To select a chat, type sl_chat/chat name",
140
+ "To list the chats you created, type /list",
141
+ "To see this message again, type /help"]
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_record"
4
+ require "active_model"
5
+
6
+ # This file contains the migrations for the database tables
7
+
8
+ # User model
9
+ class UserMigration < ActiveRecord::Migration[5.2]
10
+ def change
11
+ return if ActiveRecord::Base.connection.table_exists? :users
12
+
13
+ create_table :users do |t|
14
+ t.string :email, null: false, limit: 100
15
+ t.string :password_hash, null: false, limit: 100
16
+ t.string :password_salt, null: false, limit: 100
17
+ t.string :name, null: false, limit: 100
18
+ t.string :telegram_id, limit: 100
19
+ t.string :discord_id, limit: 100
20
+ t.integer :current_chat_id, null: false, default: 0
21
+ t.integer :role, null: false, default: 0
22
+ t.integer :open_chats, null: false, default: 0
23
+ t.integer :closed_chats, null: false, default: 0
24
+ t.integer :total_chats, null: false, default: 0
25
+ t.integer :total_messages, null: false, default: 0
26
+ t.timestamps
27
+ end
28
+ end
29
+ end
30
+
31
+ # Chat model
32
+ class ChatMigration < ActiveRecord::Migration[5.2]
33
+ def change
34
+ return if ActiveRecord::Base.connection.table_exists? :chats
35
+
36
+ create_table :chats do |t|
37
+ t.references :user, null: false, foreign_key: true
38
+ t.text :title, null: false, default: "", limit: 100
39
+ t.integer :status, null: false, default: 0
40
+ t.timestamps
41
+ end
42
+ end
43
+ end
44
+
45
+ # Message model
46
+ class MessageMigration < ActiveRecord::Migration[5.2]
47
+ def change
48
+ return if ActiveRecord::Base.connection.table_exists? :messages
49
+
50
+ create_table :messages do |t|
51
+ t.references :chat, null: false, foreign_key: true
52
+ t.integer :role, null: false, default: 0
53
+ t.text :content, null: false, default: ""
54
+ t.timestamps
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_record"
4
+
5
+ # User model
6
+ class User < ActiveRecord::Base
7
+ before_save :generate_password_salt
8
+ validates :email, presence: true, uniqueness: true
9
+ validates :password_hash, presence: true
10
+ validates :name, presence: true
11
+ validates :role, presence: true
12
+ validates :open_chats, presence: true
13
+ validates :closed_chats, presence: true
14
+ validates :total_chats, presence: true
15
+ validates :total_messages, presence: true
16
+
17
+ has_many :chats
18
+
19
+ def generate_password_salt
20
+ self.password_salt = BCrypt::Engine.generate_salt
21
+ self.password_hash = BCrypt::Engine.hash_secret(password_hash, password_salt)
22
+ end
23
+
24
+ def last_chat
25
+ chats.last
26
+ end
27
+ end
28
+
29
+ # Chat model
30
+ class Chat < ActiveRecord::Base
31
+ validates :user_id, presence: true
32
+ validates :status, presence: true
33
+ validates :title, presence: true
34
+
35
+ belongs_to :user
36
+ has_many :messages
37
+ end
38
+
39
+ # Message model
40
+ class Message < ActiveRecord::Base
41
+ validates :content, presence: true
42
+ enum role: { user: 0, assistant: 1 }
43
+
44
+ belongs_to :chat
45
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ChatgptAssistant
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "chatgpt_assistant/audio_recognition"
4
+ require_relative "chatgpt_assistant/default_messages"
5
+ require_relative "chatgpt_assistant/audio_synthesis"
6
+ require_relative "chatgpt_assistant/chatter_logger"
7
+ require_relative "chatgpt_assistant/chatter"
8
+ require_relative "chatgpt_assistant/version"
9
+ require_relative "chatgpt_assistant/config"
10
+ require_relative "chatgpt_assistant/models"
11
+ require_relative "bots/application_bot"
12
+ require_relative "bots/telegram_bot"
13
+ require_relative "bots/discord_bot"
14
+ require "streamio-ffmpeg"
15
+ require "aws-sdk-polly"
16
+ require "telegram/bot"
17
+ require "ibm_watson"
18
+ require "discordrb"
19
+ require "faraday"
20
+ require "bcrypt"
21
+
22
+ module ChatgptAssistant
23
+ # This class is responsible for initializing the Chatgpt Assistant
24
+ class Main
25
+ def initialize(mode)
26
+ @mode = mode
27
+ @config = Config.new
28
+ end
29
+
30
+ def start
31
+ return telegram_bot if telegram_mode?
32
+ return discord_bot if discord_mode?
33
+
34
+ raise "Invalid mode"
35
+ end
36
+
37
+ private
38
+
39
+ attr_reader :mode, :config
40
+
41
+ def telegram_mode?
42
+ mode == "telegram"
43
+ end
44
+
45
+ def telegram_bot
46
+ TelegramBot.new(config).start
47
+ end
48
+
49
+ def discord_mode?
50
+ mode == "discord"
51
+ end
52
+
53
+ def discord_bot
54
+ DiscordBot.new(config).start
55
+ end
56
+ end
57
+ end
data/logs/.keep ADDED
File without changes
@@ -0,0 +1,4 @@
1
+ module ChatgptAssistant
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
data/voice/.keep ADDED
File without changes
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chatgpt_assistant
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - JesusGautamah
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-04-02 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |-
14
+ This gem has the intention to facilitate the creation of chatbots with GPT-3.5-turbo,
15
+ Telegram bot, Discord bot, Audio Transcription and IBM Cloud Text to Speech in docker containers.
16
+ email:
17
+ - lima.jesuscc@gmail.com
18
+ executables:
19
+ - chatgpt_assistant
20
+ - chatgpt_bot
21
+ extensions: []
22
+ extra_rdoc_files: []
23
+ files:
24
+ - ".env_sample"
25
+ - ".rspec"
26
+ - ".rubocop.yml"
27
+ - CHANGELOG.md
28
+ - CODE_OF_CONDUCT.md
29
+ - CONTRIBUTING.md
30
+ - Dockerfile
31
+ - Gemfile
32
+ - Gemfile.lock
33
+ - LICENSE
34
+ - LICENSE.txt
35
+ - README.md
36
+ - Rakefile
37
+ - deploy.sh
38
+ - deploy_and_build.sh
39
+ - docker-compose.prod.yml
40
+ - docker-compose.yml
41
+ - exe/chatgpt_assistant
42
+ - exe/chatgpt_bot
43
+ - lib/bots/application_bot.rb
44
+ - lib/bots/discord_bot.rb
45
+ - lib/bots/telegram_bot.rb
46
+ - lib/chatgpt_assistant.rb
47
+ - lib/chatgpt_assistant/audio_recognition.rb
48
+ - lib/chatgpt_assistant/audio_synthesis.rb
49
+ - lib/chatgpt_assistant/chatter.rb
50
+ - lib/chatgpt_assistant/chatter_logger.rb
51
+ - lib/chatgpt_assistant/config.rb
52
+ - lib/chatgpt_assistant/default_messages.rb
53
+ - lib/chatgpt_assistant/migrations.rb
54
+ - lib/chatgpt_assistant/models.rb
55
+ - lib/chatgpt_assistant/version.rb
56
+ - logs/.keep
57
+ - sig/chatgpt_assistant.rbs
58
+ - voice/.keep
59
+ homepage: https://github.com/JesusGautamah/chatgpt_assistant
60
+ licenses:
61
+ - MIT
62
+ metadata:
63
+ allowed_push_host: https://rubygems.org
64
+ homepage_uri: https://github.com/JesusGautamah/chatgpt_assistant
65
+ source_code_uri: https://github.com/JesusGautamah/chatgpt_assistant.git
66
+ changelog_uri: https://github.com/JesusGautamah/chatgpt_assistant/blob/master/CHANGELOG.md
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 2.6.0
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubygems_version: 3.2.32
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Easy way chatbot with GPT-3.5-turbo, Telegram bot, Discord bot, Audio Transcription
86
+ and IBM Cloud Text to Speech.
87
+ test_files: []