chatgpt_assistant 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c735d019dd75e4679918ae36b75d61978f78cf4b7ca11c8530915cc738cb7ec6
4
- data.tar.gz: 73bdda5095040e37e3bb270c287ec8549fe156749a35b28ecca592c5205b17c9
3
+ metadata.gz: 23b30dcd5724b3978f30a1ac8ebabce7c47b2013302282248a9a10e67904d631
4
+ data.tar.gz: a4cb01e4548897b34152a63ca600eb1b9fa72c3a2131dbb950b95cb998328cc2
5
5
  SHA512:
6
- metadata.gz: 5ebf7e87f62c820eb5988dfe6a0635d385a2329bdb7b690e5ee15bac182ab162f8e502b111d14fb4c66aa6923a702e57b7f8ae5fef351582ff5b1a9a1bd7bf8f
7
- data.tar.gz: 78367d4df7a05b0290889fb854a925abd239b277e8fe9f7236db9c6715405c989f40ed0d732c0db05e3abd6e63c70099c96317fe5f3c13213f53aa26d5cf84f8
6
+ metadata.gz: 0f7d4daf964b6566c3a703b971090924b20d3d818b886533deae985eeac719860c40dfefef63983069f57cb991b4e02611e0f86f98fb7fdff9d288287f222513
7
+ data.tar.gz: 228a9a7799d596c5da4e53e0a9f8a505587f15f99af4928fef1824a88449a7e0febc64289406c29f2c67a038440fb19e054ccb2a389eec6831be041031af5bf6
data/.rubocop.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  AllCops:
2
2
  TargetRubyVersion: 2.6
3
+ NewCops: enable
3
4
 
4
5
  Style/StringLiterals:
5
6
  Enabled: true
data/Dockerfile CHANGED
@@ -1,4 +1,4 @@
1
- FROM ruby:3.2.0
1
+ FROM ruby:3.2.2
2
2
  RUN apt-get update -qq && apt-get install -y nodejs postgresql-client ffmpeg
3
3
  WORKDIR /chatgpt_assistant
4
4
  COPY Gemfile /chatgpt_assistant/Gemfile
data/Gemfile CHANGED
@@ -12,7 +12,7 @@ gem "simplecov", "~> 0.21", group: :test
12
12
 
13
13
  gem "vcr", "~> 6.0", group: :test
14
14
 
15
- gem "rubocop", "~> 1.21"
15
+ gem "rubocop", "~> 1.49"
16
16
 
17
17
  gem "rubocop-rspec", "~> 2.4"
18
18
 
data/Gemfile.lock CHANGED
@@ -167,7 +167,7 @@ GEM
167
167
  opus-ruby (1.0.1)
168
168
  ffi
169
169
  parallel (1.22.1)
170
- parser (3.2.1.0)
170
+ parser (3.2.2.0)
171
171
  ast (~> 2.4.1)
172
172
  pg (1.4.6)
173
173
  public_suffix (5.0.1)
@@ -207,24 +207,24 @@ GEM
207
207
  diff-lcs (>= 1.2.0, < 2.0)
208
208
  rspec-support (~> 3.12.0)
209
209
  rspec-support (3.12.0)
210
- rubocop (1.45.1)
210
+ rubocop (1.49.0)
211
211
  json (~> 2.3)
212
212
  parallel (~> 1.10)
213
213
  parser (>= 3.2.0.0)
214
214
  rainbow (>= 2.2.2, < 4.0)
215
215
  regexp_parser (>= 1.8, < 3.0)
216
216
  rexml (>= 3.2.5, < 4.0)
217
- rubocop-ast (>= 1.24.1, < 2.0)
217
+ rubocop-ast (>= 1.28.0, < 2.0)
218
218
  ruby-progressbar (~> 1.7)
219
219
  unicode-display_width (>= 2.4.0, < 3.0)
220
- rubocop-ast (1.26.0)
220
+ rubocop-ast (1.28.0)
221
221
  parser (>= 3.2.1.0)
222
222
  rubocop-capybara (2.17.1)
223
223
  rubocop (~> 1.41)
224
224
  rubocop-rspec (2.19.0)
225
225
  rubocop (~> 1.33)
226
226
  rubocop-capybara (~> 2.17)
227
- ruby-progressbar (1.11.0)
227
+ ruby-progressbar (1.13.0)
228
228
  ruby2_keywords (0.0.5)
229
229
  rufus-scheduler (3.8.2)
230
230
  fugit (~> 1.1, >= 1.1.6)
@@ -292,7 +292,7 @@ DEPENDENCIES
292
292
  rake (~> 13.0)
293
293
  redis
294
294
  rspec (~> 3.0)
295
- rubocop (~> 1.21)
295
+ rubocop (~> 1.49)
296
296
  rubocop-rspec (~> 2.4)
297
297
  sidekiq
298
298
  sidekiq-scheduler
data/SECURITY.md ADDED
@@ -0,0 +1,15 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ | Version | Supported |
6
+ | ------- | ------------------ |
7
+ | 0.1.4 | :white_check_mark: |
8
+ | 0.1.3 | :x: |
9
+ | 0.1.2 | :x: |
10
+ | 0.1.1 | :x: |
11
+ | 0.1.0 | :x: |
12
+
13
+ ## Reporting a Vulnerability
14
+
15
+ You can open an security vulnerability issue
data/exe/chatgpt_bot CHANGED
@@ -5,7 +5,7 @@ require_relative "../lib/chatgpt_assistant"
5
5
 
6
6
  puts "Starting Chatgpt Assistant"
7
7
  puts "Bot Type: #{ARGV[0]}"
8
- puts "Mode: #{ENV["MODE"]}"
8
+ puts "Mode: #{ENV.fetch("MODE", nil)}"
9
9
  case ARGV[0]
10
10
  when "telegram"
11
11
  ChatgptAssistant::Main.new("telegram").start
@@ -40,7 +40,7 @@ module ChatgptAssistant
40
40
 
41
41
  def login_event
42
42
  bot.command :login do |event|
43
- @message = event.message.content.split(" ")[1]
43
+ @message = event.message.content.split[1]
44
44
  @evnt = event
45
45
  message.nil? ? event.respond(commom_messages[:login]) : login_action
46
46
  end
@@ -48,7 +48,7 @@ module ChatgptAssistant
48
48
 
49
49
  def register_event
50
50
  bot.command :register do |event|
51
- @message = event.message.content.split(" ")[1]
51
+ @message = event.message.content.split[1]
52
52
  @evnt = event
53
53
  message.nil? ? event.respond(commom_messages[:register]) : register_action
54
54
  end
@@ -68,7 +68,7 @@ module ChatgptAssistant
68
68
  bot.command :hist do |event|
69
69
  @evnt = event
70
70
  event.respond error_messages[:user_not_logged_in] if user.nil?
71
- title = event.message.content.split(" ")[1..].join(" ")
71
+ title = event.message.content.split[1..].join(" ")
72
72
  @chat = user.chat_by_title(title)
73
73
  event.respond error_messages[:chat_not_found] if chat.nil? && user
74
74
  hist_action if user && chat
@@ -94,7 +94,7 @@ module ChatgptAssistant
94
94
  def sl_chat_event
95
95
  bot.command :sl_chat do |event|
96
96
  @evnt = event
97
- chat_to_select = event.message.content.split(" ")[1..].join(" ")
97
+ chat_to_select = event.message.content.split[1..].join(" ")
98
98
  @user = find_user(discord_id: event.user.id)
99
99
  event.respond error_messages[:user_not_logged_in] if user.nil?
100
100
 
@@ -105,7 +105,7 @@ module ChatgptAssistant
105
105
  def ask_event
106
106
  bot.command :ask do |event|
107
107
  @evnt = event
108
- @message = event.message.content.split(" ")[1..].join(" ")
108
+ @message = event.message.content.split[1..].join(" ")
109
109
  @user = find_user(discord_id: event.user.id)
110
110
  event.respond error_messages[:user_not_logged_in] if user.nil?
111
111
  ask_action if user
@@ -135,7 +135,7 @@ module ChatgptAssistant
135
135
  def speak_event
136
136
  bot.command :speak do |event|
137
137
  @evnt = event
138
- @message = event.message.content.split(" ")[1..].join(" ")
138
+ @message = event.message.content.split[1..].join(" ")
139
139
  @user = find_user(discord_id: event.user.id)
140
140
  @chat = user.current_chat
141
141
  speak_connect_checker_action
@@ -76,7 +76,7 @@ module ChatgptAssistant
76
76
  end
77
77
 
78
78
  def create_chat_action
79
- chat_title = evnt.message.content.split(" ")[1..].join(" ")
79
+ chat_title = evnt.message.content.split[1..].join(" ")
80
80
  @chat = Chat.new(user_id: user.id, title: chat_title, status: 0)
81
81
  chat.save ? respond_with_success : send_message(error_messages[:chat_creation])
82
82
  end
@@ -30,11 +30,13 @@ module ChatgptAssistant
30
30
  end
31
31
 
32
32
  def telegram_send_message(text, chat_id)
33
- bot.api.send_message(chat_id: chat_id, text: text)
33
+ messages = parse_message(text, 4096)
34
+ messages.each { |m| bot.api.send_message(chat_id: chat_id, text: m) }
34
35
  end
35
36
 
36
37
  def discord_send_message(text)
37
- evnt.respond text
38
+ messages = parse_message(text, 2000)
39
+ messages.each { |m| evnt.respond m }
38
40
  end
39
41
 
40
42
  def discord_help_message
@@ -29,9 +29,7 @@ module ChatgptAssistant
29
29
 
30
30
  def download_audio(audio_url)
31
31
  audio_conn = Faraday.new(url: audio_url)
32
- File.open(dl_file_name, "wb") do |file|
33
- file.write(audio_conn.get.body)
34
- end
32
+ File.binwrite(dl_file_name, audio_conn.get.body)
35
33
  FFMPEG::Movie.new(dl_file_name).transcode(file_name)
36
34
  File.delete(dl_file_name)
37
35
  end
@@ -39,14 +37,14 @@ module ChatgptAssistant
39
37
  def header
40
38
  {
41
39
  "Content-Type": "multipart/form-data",
42
- "Authorization": "Bearer #{openai_api_key}"
40
+ Authorization: "Bearer #{openai_api_key}"
43
41
  }
44
42
  end
45
43
 
46
44
  def payload
47
45
  {
48
- "file": Faraday::UploadIO.new(file_name, "audio/mp3"),
49
- "model": "whisper-1"
46
+ file: Faraday::UploadIO.new(file_name, "audio/mp3"),
47
+ model: "whisper-1"
50
48
  }
51
49
  end
52
50
 
@@ -61,9 +61,7 @@ module ChatgptAssistant
61
61
  engine: "neural"
62
62
  )
63
63
 
64
- File.open("voice/aws-#{time}.mp3", "wb") do |file|
65
- file.write(response.audio_stream.read)
66
- end
64
+ File.binwrite("voice/aws-#{time}.mp3", response.audio_stream.read)
67
65
  "voice/aws-#{time}.mp3"
68
66
  end
69
67
 
@@ -86,9 +84,7 @@ module ChatgptAssistant
86
84
  voice: voice
87
85
  ).result
88
86
 
89
- File.open("voice/ibm-#{time}.mp3", "wb") do |audio_file|
90
- audio_file.write(audio)
91
- end
87
+ File.binwrite("voice/ibm-#{time}.mp3", audio)
92
88
  "voice/ibm-#{time}.mp3"
93
89
  end
94
90
 
@@ -9,23 +9,23 @@ module ChatgptAssistant
9
9
  # This class is responsible for the configuration of the Chatgpt Assistant
10
10
  class Config
11
11
  def initialize
12
- @env_type = ENV["ENV_TYPE"]
13
- @language = ENV["LANGUAGE"]
14
- @mode = ENV["MODE"]
15
- @database_host = ENV["POSTGRES_HOST"]
16
- @database_name = ENV["POSTGRES_DB"]
17
- @database_username = ENV["POSTGRES_USER"]
18
- @database_password = ENV["POSTGRES_PASSWORD"]
19
- @openai_api_key = ENV["OPENAI_API_KEY"]
20
- @telegram_token = ENV["TELEGRAM_TOKEN"]
21
- @discord_token = ENV["DISCORD_TOKEN"]
22
- @discord_client_id = ENV["DISCORD_CLIENT_ID"]
23
- @ibm_api_key = ENV["IBM_API_KEY"]
24
- @ibm_url = ENV["IBM_URL"]
25
- @aws_access_key_id = ENV["AWS_ACCESS_KEY_ID"]
26
- @aws_secret_access_key = ENV["AWS_SECRET_ACCESS_KEY"]
27
- @aws_region = ENV["AWS_REGION"]
28
- @discord_prefix = ENV["DISCORD_PREFIX"]
12
+ @env_type = ENV.fetch("ENV_TYPE", nil)
13
+ @language = ENV.fetch("LANGUAGE", nil)
14
+ @mode = ENV.fetch("MODE", nil)
15
+ @database_host = ENV.fetch("POSTGRES_HOST", nil)
16
+ @database_name = ENV.fetch("POSTGRES_DB", nil)
17
+ @database_username = ENV.fetch("POSTGRES_USER", nil)
18
+ @database_password = ENV.fetch("POSTGRES_PASSWORD", nil)
19
+ @openai_api_key = ENV.fetch("OPENAI_API_KEY", nil)
20
+ @telegram_token = ENV.fetch("TELEGRAM_TOKEN", nil)
21
+ @discord_token = ENV.fetch("DISCORD_TOKEN", nil)
22
+ @discord_client_id = ENV.fetch("DISCORD_CLIENT_ID", nil)
23
+ @ibm_api_key = ENV.fetch("IBM_API_KEY", nil)
24
+ @ibm_url = ENV.fetch("IBM_URL", nil)
25
+ @aws_access_key_id = ENV.fetch("AWS_ACCESS_KEY_ID", nil)
26
+ @aws_secret_access_key = ENV.fetch("AWS_SECRET_ACCESS_KEY", nil)
27
+ @aws_region = ENV.fetch("AWS_REGION", nil)
28
+ @discord_prefix = ENV.fetch("DISCORD_PREFIX", nil)
29
29
  end
30
30
 
31
31
  attr_reader :openai_api_key, :telegram_token, :discord_token, :ibm_api_key, :ibm_url,
@@ -13,7 +13,7 @@ class VisitorMigration < ActiveRecord::Migration[5.2]
13
13
  t.string :discord_id, limit: 100
14
14
  t.integer :platform, null: false, default: 0
15
15
  t.string :name, null: false
16
- t.integer :current_user_id, null: false, default: 0
16
+ t.integer :current_user_id, default: 0
17
17
  t.timestamps
18
18
  end
19
19
  end
@@ -7,8 +7,6 @@ class Visitor < ActiveRecord::Base
7
7
  has_many :visitor_actions
8
8
  # has_one :tel_user, foreign_key: "telegram_id", class_name: "User"
9
9
  # has_one :dis_user, foreign_key: "discord_id", class_name: "User"
10
- validates :telegram_id, uniqueness: true
11
- validates :discord_id, uniqueness: true
12
10
  validates :name, presence: true
13
11
  validates :platform, presence: true
14
12
  enum platform: { telegram: 0, discord: 1 }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ChatgptAssistant
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
5
  end
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.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - JesusGautamah
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-09 00:00:00.000000000 Z
11
+ date: 2023-04-10 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,
@@ -37,6 +37,7 @@ files:
37
37
  - LICENSE.txt
38
38
  - README.md
39
39
  - Rakefile
40
+ - SECURITY.md
40
41
  - deploy.sh
41
42
  - deploy_and_build.sh
42
43
  - docker-compose.prod.yml
@@ -79,6 +80,7 @@ metadata:
79
80
  homepage_uri: https://github.com/JesusGautamah/chatgpt_assistant
80
81
  source_code_uri: https://github.com/JesusGautamah/chatgpt_assistant.git
81
82
  changelog_uri: https://github.com/JesusGautamah/chatgpt_assistant/releases
83
+ rubygems_mfa_required: 'true'
82
84
  post_install_message:
83
85
  rdoc_options: []
84
86
  require_paths: