chat_gpt_error_handler 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/chat_gpt_error_handler/error_handler.rb +34 -25
- data/lib/chat_gpt_error_handler/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8eb4d741fe11dd031e02e4405a131ba4a440a0306575a97246b6486de5f7ae3e
|
4
|
+
data.tar.gz: 589d87cf005f91a365b9399e99a9d45711dce60d9847500790395c3173f9b097
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef2028789e012e4856f1397fcf98c8e2ee3c593a4d22dec620d05a1b20c539b3103e6892e8463e59e1f19f2bee4fa892f49035f3ec80f3818ecf7d7a68663795
|
7
|
+
data.tar.gz: cbf4c7bb9ebe54e539e543c36108387c089f9a2fb891968ddf0e7bf0f23a57c5a6d9eb179c3ba63a07da2603201a74e822fe74f1203eeac8648d158e2bf20477
|
@@ -46,39 +46,48 @@ module ChatGptErrorHandler
|
|
46
46
|
}
|
47
47
|
)
|
48
48
|
|
49
|
+
|
49
50
|
# Try a second time if the response is empty. Raise the second time
|
50
51
|
if response["choices"].nil?
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
52
|
+
response = client.completions(
|
53
|
+
parameters: {
|
54
|
+
model: "text-davinci-002",
|
55
|
+
prompt: prompt,
|
56
|
+
n: 1,
|
57
|
+
temperature: 0.85,
|
58
|
+
max_tokens: 250,
|
59
|
+
stop: nil
|
60
|
+
}
|
61
|
+
)
|
57
62
|
end
|
58
63
|
|
59
|
-
|
64
|
+
if true #response["choices"].nil?
|
65
|
+
print_error_and_solution(error, "ChatGPT returned an empty response to your error message. You may need to try again.")
|
66
|
+
else
|
67
|
+
response_text = response["choices"].map { |c| c["text"].to_s }
|
60
68
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
69
|
+
response_text = response_text.join("")
|
70
|
+
shortened_response_text = []
|
71
|
+
begin
|
72
|
+
# try to format the response text to be 75 characters per line
|
73
|
+
response_text.split(" ").reduce("") do |line, word|
|
74
|
+
if line.length + word.length > 75
|
75
|
+
shortened_response_text << line
|
76
|
+
line = word
|
77
|
+
elsif word == response_text.split(" ").last
|
78
|
+
shortened_response_text << [line + " " + word]
|
79
|
+
else
|
80
|
+
line += (" " + word)
|
81
|
+
end
|
73
82
|
end
|
83
|
+
shortened_response_text = shortened_response_text.join("\n")
|
84
|
+
rescue => e
|
85
|
+
# The formatting does not always work, so if it fails, just use the original response text
|
86
|
+
shortened_response_text = response_text
|
74
87
|
end
|
75
|
-
shortened_response_text = shortened_response_text.join("\n")
|
76
|
-
rescue => e
|
77
|
-
# The formatting does not always work, so if it fails, just use the original response text
|
78
|
-
shortened_response_text = response_text
|
79
|
-
end
|
80
88
|
|
81
|
-
|
89
|
+
print_error_and_solution(error, shortened_response_text.strip)
|
90
|
+
end
|
82
91
|
rescue => gpt_error
|
83
92
|
puts "\e[31mAn error occurred while communicating with GPT:\e[0m"
|
84
93
|
puts gpt_error.message
|
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.2.
|
4
|
+
version: 0.2.1
|
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-
|
11
|
+
date: 2023-06-02 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.
|
93
|
-
signing_key:
|
92
|
+
rubygems_version: 3.4.1
|
93
|
+
signing_key:
|
94
94
|
specification_version: 4
|
95
95
|
summary: Helpful ChatGpt hints for your Rails app
|
96
96
|
test_files: []
|