natsukantou 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d29dec07a03407ea767c53dce9760627262abf2fb35d3f9888659be3c2442efa
4
- data.tar.gz: 36b30c5b5fff59a62293acdf660fd7f508c0b8bfc20c1882c3f7139b7ba4a06c
3
+ metadata.gz: eeacff02b528faa718685f0538b9e81d953874f411a0966c3ab4340d9a0a0aee
4
+ data.tar.gz: dd2b7056ab77874e2783f8e6f7f4e6691a5dfe37022ebc4f274461fa912c5536
5
5
  SHA512:
6
- metadata.gz: 07cb8f6e26187a971f0ff080767b7662a62ce7f0eb7730c647586ea351925ba94190156400ac37d3012d8bdaa7f848bd7456dc58b0216cb5e5ccb386ba9d4be5
7
- data.tar.gz: da43175d1d13f63a0c2255cdc110257e35e54d8164ec65fbbdab1c81c1eff01b146db8e5239cef8312bfea87802e6be9258dcf42401991a72e379f35d5ba4288
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
@@ -25,3 +25,7 @@
25
25
  ## [0.2.1] - 2023-04-30
26
26
 
27
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!
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Natsukantou
4
- VERSION = "0.2.1"
4
+ VERSION = "0.2.2"
5
5
  end
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.1
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-04-29 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
@@ -183,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
183
  - !ruby/object:Gem::Version
184
184
  version: '0'
185
185
  requirements: []
186
- rubygems_version: 3.4.12
186
+ rubygems_version: 3.4.10
187
187
  signing_key:
188
188
  specification_version: 4
189
189
  summary: human language translation library for XML documents