chat_gpt_error_handler 0.2.1 → 0.2.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 +21 -37
- 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: 8d58bdea8e5604d2160eec14444c9be586d5ebab1e6ac16ee9c76175080b8984
|
4
|
+
data.tar.gz: 0b20217fe18f736085f47bde8be9cc4a4a0905291b504490d4e39bfe76dd756f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 792a0f62cab7ffa3b770225ad9edd8c122d7e2f7bb2b506bdf381af766c60ea5cc147073b2a4babc3b1cea2494054555710fef600ead813e91f89e14405de448
|
7
|
+
data.tar.gz: 96d5581efe1cb5954c429f973fd2527d415a886da0267ea620c7deac813cc6cbcb37512c37244f453a38235057a05e72082f3240da3647503d0bf0a9243ea474
|
@@ -46,48 +46,32 @@ module ChatGptErrorHandler
|
|
46
46
|
}
|
47
47
|
)
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
if response["choices"].nil?
|
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
|
-
)
|
62
|
-
end
|
63
|
-
|
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.")
|
49
|
+
response_text = if response["choices"].nil?
|
50
|
+
"GPT returned an empty response to your error message."
|
66
51
|
else
|
67
|
-
|
52
|
+
response["choices"].map { |c| c["text"].to_s }.join("")
|
53
|
+
end
|
68
54
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
line += (" " + word)
|
81
|
-
end
|
55
|
+
shortened_response_text = []
|
56
|
+
begin
|
57
|
+
# try to format the response text to be 75 characters per line
|
58
|
+
response_text.split(" ").reduce("") do |line, word|
|
59
|
+
if line.length + word.length > 75
|
60
|
+
shortened_response_text << line
|
61
|
+
line = word
|
62
|
+
elsif word == response_text.split(" ").last
|
63
|
+
shortened_response_text << [line + " " + word]
|
64
|
+
else
|
65
|
+
line += (" " + word)
|
82
66
|
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
67
|
end
|
88
|
-
|
89
|
-
|
68
|
+
shortened_response_text = shortened_response_text.join("\n")
|
69
|
+
rescue => e
|
70
|
+
# The formatting does not always work, so if it fails, just use the original response text
|
71
|
+
shortened_response_text = response_text
|
90
72
|
end
|
73
|
+
|
74
|
+
print_error_and_solution(error, shortened_response_text.strip)
|
91
75
|
rescue => gpt_error
|
92
76
|
puts "\e[31mAn error occurred while communicating with GPT:\e[0m"
|
93
77
|
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.1
|
4
|
+
version: 0.2.2.1
|
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
|