jekyll-chatgpt-translate 0.0.25 → 0.0.26

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: 76c9c7e2f01f4350b38e1343d88918c9a89bfb5ace6bc84855bba6cd401cf027
4
- data.tar.gz: 35dbf1ac0f89d6a3a68de2a1f36ae451686b665a8ef4a3f9adc4054623d45dc9
3
+ metadata.gz: 9f480f74d9f096d1b24d516f05c1c24a27cefe7e87cc9db917d2fffe727646fe
4
+ data.tar.gz: 0dd088c831b8a3d9685bf4363ea7821d83d8602767fb933740b938552475d98e
5
5
  SHA512:
6
- metadata.gz: db448c1104508d9084c1b28ea687fda646b72c6c03b78e72c4423106c28d9414120b323957f0c967a7932926870fac33a7a7dc713571c0179f58cd5cdfca0f00
7
- data.tar.gz: 96f431eb35b166ab4cc82575f8dbee0b80e845f5801d3d7436aede3d75becb196e3dd2aee36595742f0a664237bbe804d449e1f10348579b509111384beabb73
6
+ metadata.gz: c286215fa7b40fab206be74d7f03d02963f307009ba6d91c0f1ff7ce06795eb29be1588c022a994696755677e6640fb595aca7246474d8a1bc9072f38f5458a1
7
+ data.tar.gz: af831575ce9749aada2c42ad5c4d8798890490e5e0795cd87f70cce9a2d8b7bbaa3d7dfba9b95e9b5f81eaef2e9f9513ca1542341e1393bc4878c6ee257911af
data/.rubocop.yml CHANGED
@@ -35,3 +35,5 @@ Layout/EndAlignment:
35
35
  Enabled: false
36
36
  Metrics/ClassLength:
37
37
  Max: 200
38
+ Style/ClassVars:
39
+ Enabled: false
@@ -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.25'
31
+ s.version = '0.0.26'
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
- prompt = GptTranslate::Prompt.new(par, @source, @target).to_s
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
- raise 'No content returned by ChatGPT' if answer.nil?
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
@@ -23,5 +23,5 @@
23
23
  # SOFTWARE.
24
24
 
25
25
  module GptTranslate
26
- VERSION = '0.0.25'
26
+ VERSION = '0.0.26'
27
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-chatgpt-translate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.25
4
+ version: 0.0.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko