natsukantou 0.2.0 → 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 +4 -4
- data/.rubocop.yml +3 -0
- data/CHANGELOG.md +12 -0
- data/lib/natsukantou/chat_gpt.rb +20 -8
- data/lib/natsukantou/handle_ruby_markup.rb +1 -1
- data/lib/natsukantou/version.rb +1 -1
- data/natsukantou.gemspec +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eeacff02b528faa718685f0538b9e81d953874f411a0966c3ab4340d9a0a0aee
|
4
|
+
data.tar.gz: dd2b7056ab77874e2783f8e6f7f4e6691a5dfe37022ebc4f274461fa912c5536
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad4f341ac35371d2f63850c7d2f327770e25ba5e1b6af1e8b9bd2acf8bc0cd3c85db52b9bbf1fa7b4742b22df44d7351a16ebccd74f5dd87649f053932c4fa69
|
7
|
+
data.tar.gz: 86c26ea7575ff81d8c1d57baa37c9f5b84d9b8ef4a0d7a91db581cc76c0ca710347644b5ebe8a18419477400d6360554744c36760f638c7e715aba6eca95abc4
|
data/.rubocop.yml
CHANGED
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.
|
data/lib/natsukantou/chat_gpt.rb
CHANGED
@@ -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
|
-
|
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!
|
data/lib/natsukantou/version.rb
CHANGED
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.
|
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-
|
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.
|
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
|