natsukantou 0.2.0 → 0.2.2

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: 1edac0c042ee1ad4c1051d15028d5c6ff9ac397160c5bc83c9cd8c7fe1730d3f
4
- data.tar.gz: 9e8950028f71f90f4e1b141a63d74027c021b36a2231151e290b50fcd396ec34
3
+ metadata.gz: eeacff02b528faa718685f0538b9e81d953874f411a0966c3ab4340d9a0a0aee
4
+ data.tar.gz: dd2b7056ab77874e2783f8e6f7f4e6691a5dfe37022ebc4f274461fa912c5536
5
5
  SHA512:
6
- metadata.gz: 82d10f0790a4eb1899ec277b90b9fa3c66de282d08915fd5e9d2fe6e53d97a39b12205a9ec8389c6bdbf5587f492fb072ca70d02326bd991be7f94217f144b8e
7
- data.tar.gz: 7c81870166e14a41957246cd266a8b0e58e6868421ed7115deb853746e036d3f913fed5880412d73e9b530f3dcab8304a430ca5475c1decbf7ad7f0876c458bb
6
+ metadata.gz: ad4f341ac35371d2f63850c7d2f327770e25ba5e1b6af1e8b9bd2acf8bc0cd3c85db52b9bbf1fa7b4742b22df44d7351a16ebccd74f5dd87649f053932c4fa69
7
+ data.tar.gz: 86c26ea7575ff81d8c1d57baa37c9f5b84d9b8ef4a0d7a91db581cc76c0ca710347644b5ebe8a18419477400d6360554744c36760f638c7e715aba6eca95abc4
data/.rubocop.yml CHANGED
@@ -28,6 +28,9 @@ Style/TrailingCommaInArguments:
28
28
  Style/TrailingCommaInHashLiteral:
29
29
  Enabled: false
30
30
 
31
+ Style/TrailingCommaInArrayLiteral:
32
+ Enabled: false
33
+
31
34
  Style/NegatedIf:
32
35
  Enabled: false
33
36
 
data/CHANGELOG.md CHANGED
@@ -17,3 +17,15 @@
17
17
  ## [0.1.3] - 2023-02-27
18
18
 
19
19
  - Skip interlacing if nodes' text() are identical
20
+
21
+ ## [0.2.0] - 2023-03-05
22
+
23
+ - Add ChatGPT
24
+
25
+ ## [0.2.1] - 2023-04-30
26
+
27
+ - Remove newline characters in HandleRubyMarkup, which helps improving translation
28
+
29
+ ## [0.2.2] - 2023-10-10
30
+
31
+ - Fix ChatGPT not able to distinguish content to be translated and our instructions.
@@ -9,6 +9,13 @@ module Natsukantou
9
9
  class ChatGpt
10
10
  include UtilityBase
11
11
 
12
+ SYSTEM_ROLE_TEMPLATE = <<~SYSTEM_ROLE_TEMPLATE
13
+ You are a professional XML translator, translating from %<lang_from>s to %<lang_to>s.
14
+ You will be given a raw XML document. When translating, maintain XML structure as is.
15
+ You are only allowed to return the translated XML and nothing else.
16
+ IMPORTANT: ONLY RETURN TRANSLATED TEXT AND NOTHING ELSE.
17
+ SYSTEM_ROLE_TEMPLATE
18
+
12
19
  # @param app [Hash]
13
20
  # @param access_token [String] API access token
14
21
  #
@@ -51,16 +58,21 @@ module Natsukantou
51
58
  private
52
59
 
53
60
  def translate(text)
54
- message = "Please help me to translate the XML `#{text}` from #{env.lang_from.code} to #{env.lang_to.code}, maintaining XML structure." # rubocop:disable Layout/LineLength
55
-
56
- response = client.chat(
57
- parameters: {
58
- model: "gpt-3.5-turbo",
59
- messages: [{ role: "user", content: message }],
60
- temperature: 0.7,
61
- }
61
+ system_message = format(
62
+ SYSTEM_ROLE_TEMPLATE, lang_from: env.lang_from.code, lang_to: env.lang_to.code
62
63
  )
63
64
 
65
+ parameters = {
66
+ model: "gpt-3.5-turbo",
67
+ messages: [
68
+ { role: "system", content: system_message },
69
+ { role: "user", content: text },
70
+ ],
71
+ temperature: 0.7,
72
+ }
73
+
74
+ response = client.chat(parameters: parameters)
75
+
64
76
  translated_xml = response.dig("choices", 0, "message", "content")
65
77
 
66
78
  translated_xml.strip!
@@ -26,7 +26,7 @@ module Natsukantou
26
26
 
27
27
  def process_node(node)
28
28
  node.css('rt').each(&:remove)
29
- node.inner_text = node.text.gsub(' ', '')
29
+ node.inner_text = node.text.gsub(/[[:space:]]/, '')
30
30
  end
31
31
  end
32
32
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Natsukantou
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.2"
5
5
  end
data/natsukantou.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.email = ["mark@goodlife.tw"]
10
10
 
11
11
  spec.summary = "human language translation library for XML documents"
12
- spec.description = "human language translation library for XML documents, supporting DeepL"
12
+ spec.description = "human language translation library for XML documents, supporting DeepL and ChatGPT"
13
13
  spec.homepage = "https://gitlab.com/lulalala/natsukantou"
14
14
  spec.license = "MIT"
15
15
  spec.required_ruby_version = ">= 2.7.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: natsukantou
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - lulalala
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-05 00:00:00.000000000 Z
11
+ date: 2023-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: middleware
@@ -123,6 +123,7 @@ dependencies:
123
123
  - !ruby/object:Gem::Version
124
124
  version: 3.5.0
125
125
  description: human language translation library for XML documents, supporting DeepL
126
+ and ChatGPT
126
127
  email:
127
128
  - mark@goodlife.tw
128
129
  executables:
@@ -182,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
183
  - !ruby/object:Gem::Version
183
184
  version: '0'
184
185
  requirements: []
185
- rubygems_version: 3.4.7
186
+ rubygems_version: 3.4.10
186
187
  signing_key:
187
188
  specification_version: 4
188
189
  summary: human language translation library for XML documents