jekyll-chatgpt-translate 0.0.25 → 0.0.27
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 416596f5103bd30f33ffd088c1da48fd422e9ed90be9a89de3874aa8fc95d26a
|
4
|
+
data.tar.gz: 0b091f92583d249630aace8b8e46246178469680ea35fe74b546fae1e97a2c3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be86868fafea658f8cdf68344923a9f1b137893678254e899709407fc7146293d43baa9e73e448d3dd23f0a9c57605e62aa20132ce03cb9a15182c4c59828a7a
|
7
|
+
data.tar.gz: 27eddf1b7a551d5c998b1cbcd781709ca9c02b0975d216f31ff431d2c79dbf2b86ad2ad0c96805cf1b5d810d3e6d6581c30269b1ddc6170e4146de23f2a89779
|
data/.rubocop.yml
CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |s|
|
|
28
28
|
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
|
29
29
|
s.required_ruby_version = '>= 2.6'
|
30
30
|
s.name = 'jekyll-chatgpt-translate'
|
31
|
-
s.version = '0.0.
|
31
|
+
s.version = '0.0.27'
|
32
32
|
s.license = 'MIT'
|
33
33
|
s.summary = 'Translate Jekyll Pages Through ChatGPT'
|
34
34
|
s.description = [
|
@@ -35,6 +35,9 @@ module GptTranslate; end
|
|
35
35
|
# Copyright:: Copyright (c) 2023 Yegor Bugayenko
|
36
36
|
# License:: MIT
|
37
37
|
class GptTranslate::ChatGPT
|
38
|
+
# Is TRUE if we already shown to the user the available models.
|
39
|
+
@@models_printed = false
|
40
|
+
|
38
41
|
# Ctor.
|
39
42
|
# +key+ OpenAI API Key, which can't be nil, but can be empty string, which means dry mode (no calls to OpenAI)
|
40
43
|
# +source+ The language to translate from
|
@@ -77,12 +80,17 @@ class GptTranslate::ChatGPT
|
|
77
80
|
private
|
78
81
|
|
79
82
|
def translate_par(par)
|
83
|
+
client = OpenAI::Client.new(access_token: @key)
|
84
|
+
if @@models_printed
|
85
|
+
Jekyll.logger.info("Available ChatGPT models: #{client.models.list['data'].map { |m| m['id'] }.join(', ')}")
|
86
|
+
@@models_printed = true
|
87
|
+
end
|
88
|
+
prompt = GptTranslate::Prompt.new(par, @source, @target).to_s
|
80
89
|
start = Time.now
|
81
90
|
answer = nil
|
82
91
|
attempt = 0
|
83
92
|
begin
|
84
|
-
|
85
|
-
response = OpenAI::Client.new(access_token: @key).chat(
|
93
|
+
response = client.chat(
|
86
94
|
parameters: {
|
87
95
|
model: @model,
|
88
96
|
messages: [{ role: 'user', content: prompt }],
|
@@ -90,7 +98,10 @@ class GptTranslate::ChatGPT
|
|
90
98
|
}
|
91
99
|
)
|
92
100
|
answer = response.dig('choices', 0, 'message', 'content')
|
93
|
-
|
101
|
+
if answer.nil?
|
102
|
+
Jekyll.logger.error("No content returned by ChatGPT: #{response}")
|
103
|
+
raise 'No content returned by ChatGPT'
|
104
|
+
end
|
94
105
|
Jekyll.logger.debug("ChatGPT prompt: #{prompt.inspect}, ChatGPT answer: #{answer.inspect}")
|
95
106
|
rescue StandardError => e
|
96
107
|
attempt += 1
|
@@ -56,10 +56,10 @@ class GptTranslate::Ping
|
|
56
56
|
before = Net::HTTP.get_response(URI(uri))
|
57
57
|
if before.is_a?(Net::HTTPSuccess)
|
58
58
|
html = before.body
|
59
|
+
@site.static_files << DownloadedFile.new(@site, @path, html)
|
59
60
|
if html.include?(marker)
|
60
61
|
Jekyll.logger.info("No need to translate, the page exists at \
|
61
62
|
#{uri.inspect} (#{html.split.count} words)")
|
62
|
-
@site.static_files << DownloadedFile.new(@site, @path, html)
|
63
63
|
return true
|
64
64
|
end
|
65
65
|
Jekyll.logger.info("Re-translation required for #{uri.inspect}")
|