chat_gpt_error_handler 0.1.1 → 0.2.0

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: 1fd24aab4edf0e7e07a010bcc31ebed6f8777b2762ba32a017864841a0a7293c
4
- data.tar.gz: 48e0f9e6947492ea28f24d20a338b6d943f7db9726c8659c0347789b914170b3
3
+ metadata.gz: 8f060d15937f7fa9046e4ab5a2d417d5594900fef00b4302de4c7835c5c05d59
4
+ data.tar.gz: c02b547ce605567394c4e49ff564d953dbb9ded90bcde3999106e3a83b1006d9
5
5
  SHA512:
6
- metadata.gz: 77e2d20c1720bef22f47b5e7bb64e7737b8b0e3ecf8f9def63dccbe1901b12fdbdcc276cdecc9d704256954c247deaab3a15dc63081b311dc886cedd8fff471f
7
- data.tar.gz: f9fe79b6e1302b5ae071a7e3df15f037b3fc30273a1ea7dd9e35c141d8e59f819f35ae1039783ec9e12e31363213ad5da35b42b9c75b74a14519563084589d67
6
+ metadata.gz: f412184b2e243fb0445081a6d2ad98cad4e7aecdddd394ae8d5d4543fc79aecac2b139d2d6baa9f862c2df78f2aea09cddf3ea0e7ab23706cd84ee872b09f24b
7
+ data.tar.gz: 209e6fa81d297e0592d20963a9d323eed1bf4feaa6d8650498fcb6f82064157382ea1411db5214de20c2a158415cbbf8d6c9c3e5e3fb932b129199a761af7bcc
data/README.md CHANGED
@@ -12,11 +12,12 @@ Add this line to your application's Gemfile:
12
12
  gem "chat_gpt_error_handler"
13
13
  ```
14
14
 
15
- Set your [OpenAI API Token](https://openai.com/product#made-for-developers) in an initializer:
15
+ Set your [OpenAI API Token](https://openai.com/product#made-for-developers) and enable the gem in an initializer:
16
16
 
17
17
  ```ruby
18
18
  # config/initializers/chat_gpt_error_handler.rb
19
19
  ChatGptErrorHandler.openai_access_token = 'your_openai_access_token_here'
20
+ ChatGptErrorHandler.enabled = true
20
21
  ```
21
22
 
22
23
  And you're off!
@@ -5,8 +5,10 @@ module ChatGptErrorHandler
5
5
  class ErrorHandler
6
6
  def initialize(app)
7
7
  @app = app
8
- OpenAI.configure do |config|
9
- config.access_token = ChatGptErrorHandler.openai_access_token || ENV.fetch('OPENAI_ACCESS_TOKEN')
8
+ if ChatGptErrorHandler.enabled
9
+ OpenAI.configure do |config|
10
+ config.access_token = ChatGptErrorHandler.openai_access_token || ENV.fetch('OPENAI_ACCESS_TOKEN')
11
+ end
10
12
  end
11
13
  end
12
14
 
@@ -14,7 +16,7 @@ module ChatGptErrorHandler
14
16
  begin
15
17
  @app.call(env)
16
18
  rescue => error
17
- send_to_gpt(error)
19
+ send_to_gpt(error) if ChatGptErrorHandler.enabled
18
20
  raise error
19
21
  end
20
22
  end
@@ -43,6 +45,17 @@ module ChatGptErrorHandler
43
45
  stop: nil
44
46
  }
45
47
  )
48
+
49
+ # Try a second time if the response is empty. Raise the second time
50
+ if response["choices"].nil?
51
+ if @retried.nil?
52
+ @retried = true
53
+ redo
54
+ else
55
+ raise "GPT returned an empty response to your error message."
56
+ end
57
+ end
58
+
46
59
  response_text = response["choices"].map { |c| c["text"].to_s }
47
60
 
48
61
  response_text = response_text.join("")
@@ -67,7 +80,6 @@ module ChatGptErrorHandler
67
80
 
68
81
  print_error_and_solution(error, shortened_response_text.strip)
69
82
  rescue => gpt_error
70
- require 'debug'; debugger
71
83
  puts "\e[31mAn error occurred while communicating with GPT:\e[0m"
72
84
  puts gpt_error.message
73
85
  puts gpt_error.backtrace
@@ -1,3 +1,3 @@
1
1
  module ChatGptErrorHandler
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -2,8 +2,11 @@ require "chat_gpt_error_handler/version"
2
2
  require "chat_gpt_error_handler/engine"
3
3
 
4
4
  module ChatGptErrorHandler
5
- mattr_accessor :openai_access_token
5
+ mattr_accessor :openai_access_token, :enabled
6
6
 
7
7
  # Default value for the openai_access_token, used when not explicitly set by the user
8
8
  @@openai_access_token = nil
9
+
10
+ # Default value to allow opting-in
11
+ @@enabled = false
9
12
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chat_gpt_error_handler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Schwaderer
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-17 00:00:00.000000000 Z
11
+ date: 2023-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -74,7 +74,7 @@ licenses:
74
74
  metadata:
75
75
  homepage_uri: https://github.com/schwad/chat_gpt_error_handler
76
76
  source_code_uri: https://github.com/schwad/chat_gpt_error_handler
77
- post_install_message:
77
+ post_install_message:
78
78
  rdoc_options: []
79
79
  require_paths:
80
80
  - lib
@@ -89,8 +89,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
89
  - !ruby/object:Gem::Version
90
90
  version: '0'
91
91
  requirements: []
92
- rubygems_version: 3.4.1
93
- signing_key:
92
+ rubygems_version: 3.0.3.1
93
+ signing_key:
94
94
  specification_version: 4
95
95
  summary: Helpful ChatGpt hints for your Rails app
96
96
  test_files: []