chat_gpt_error_handler 0.2.1 → 0.2.2
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 +25 -34
- data/lib/chat_gpt_error_handler/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66653c69558faf46858d9892cae31406a59ef8ded01b35fc2a34a499918f0144
|
4
|
+
data.tar.gz: b412a2641d9c98ae2c690576d41e85107e65015d1427e1b82311f727608ae485
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4610b96802076855b71b75b7929c50f02518749afbde6643cdd04c9e1fc0e1188a221ff4372f7e60eae3304441f6f01cdd0daa8d7cdeeed7ac5dd46104e1b64
|
7
|
+
data.tar.gz: b92f12739b96255631b45cec85544dbd68f8697ddca6aaa501c85dc0115e4de68f73f8882fe41c60062e72d0d9f8521bdeb775e9a88107dc503d36c94dea7a44
|
@@ -46,48 +46,39 @@ module ChatGptErrorHandler
|
|
46
46
|
}
|
47
47
|
)
|
48
48
|
|
49
|
-
|
50
49
|
# Try a second time if the response is empty. Raise the second time
|
51
50
|
if response["choices"].nil?
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
max_tokens: 250,
|
59
|
-
stop: nil
|
60
|
-
}
|
61
|
-
)
|
51
|
+
if @retried.nil?
|
52
|
+
@retried = true
|
53
|
+
redo
|
54
|
+
else
|
55
|
+
raise "GPT returned an empty response to your error message."
|
56
|
+
end
|
62
57
|
end
|
63
58
|
|
64
|
-
|
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 }
|
59
|
+
response_text = response["choices"].map { |c| c["text"].to_s }
|
68
60
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
end
|
61
|
+
response_text = response_text.join("")
|
62
|
+
shortened_response_text = []
|
63
|
+
begin
|
64
|
+
# try to format the response text to be 75 characters per line
|
65
|
+
response_text.split(" ").reduce("") do |line, word|
|
66
|
+
if line.length + word.length > 75
|
67
|
+
shortened_response_text << line
|
68
|
+
line = word
|
69
|
+
elsif word == response_text.split(" ").last
|
70
|
+
shortened_response_text << [line + " " + word]
|
71
|
+
else
|
72
|
+
line += (" " + word)
|
82
73
|
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
|
87
74
|
end
|
88
|
-
|
89
|
-
|
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
|
90
79
|
end
|
80
|
+
|
81
|
+
print_error_and_solution(error, shortened_response_text.strip)
|
91
82
|
rescue => gpt_error
|
92
83
|
puts "\e[31mAn error occurred while communicating with GPT:\e[0m"
|
93
84
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Schwaderer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-06-
|
11
|
+
date: 2023-06-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|