immosquare-translate 0.1.4 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/immosquare-translate/translator.rb +20 -12
- data/lib/immosquare-translate/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebb9b4954484db537e1e5a348615ec85fd548699a1163615fa3963f394eca358
|
4
|
+
data.tar.gz: f7a10ba2036eaeb0ce74846b2b87c9fc6fdf785fec27094bc1ea96a953e96b53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef04b72ee73ebb5d43f8271731a3c508bf0c60549a2e102f687e05f2dcd83db81ab827e9bc3fa61b7a76af62be8cce67ecb19165ef80e0a526765d3092d28105
|
7
|
+
data.tar.gz: 722e14d7315e7d140b5ee9512351a548120c8922aee79147cb4faf4627a21fb316c456e14741a9acd1ff89db8d576aa4bfcaec2f77bd1166c140f196365403c1
|
@@ -26,16 +26,23 @@ module ImmosquareTranslate
|
|
26
26
|
"Authorization" => "Bearer #{ImmosquareTranslate.configuration.openai_api_key}"
|
27
27
|
}
|
28
28
|
|
29
|
-
prompt_system = "As a sophisticated translation AI, your role is to translate sentences from a specified source language to multiple target languages. " \
|
30
|
-
"
|
31
|
-
"
|
32
|
-
"
|
29
|
+
prompt_system = "As a sophisticated translation AI, your role is to accurately translate sentences from a specified source language to multiple target languages. " \
|
30
|
+
"All translations must be returned as a single, pure JSON string, adhering strictly to JSON format standards. Use ISO 639-1 codes to specify languages. " \
|
31
|
+
"Should the input be HTML, return the translated content preserving the original HTML formatting. " \
|
32
|
+
"In cases where the sentence contains newline characters '\\n', or tab characters '\\t', ensure these are retained in the translation without alteration. " \
|
33
|
+
"Your output should be free from markdown (e.g., ```json) or any extraneous formatting characters, focusing solely on maintaining the integrity of the JSON structure."
|
33
34
|
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
"
|
36
|
+
|
37
|
+
|
38
|
+
prompt = "Translate the #{text.size} #{text.size == 1 ? "sentence" : "sentences"} provided below from the source language (ISO 639-1 code: #{from}) to the target languages specified: #{to_iso.map {|iso, language| "#{language} (ISO 639-1 code: #{iso})" }.join(", ")}. " \
|
39
|
+
"Before translating, correct any spelling or grammatical errors in each sentence. " \
|
40
|
+
"If the source language is also a target language, include the corrected version of the sentence for that language as well. " \
|
41
|
+
"Format the translation output as a JSON string adhering to the following structure: " \
|
42
|
+
"{\"datas\":[{\"locale_iso\": \"Translated Text\"}]}, where 'locale_iso' is replaced with the appropriate ISO 639-1 code for each translation. " \
|
43
|
+
"Ensure the output strictly follows this JSON format, without any extraneous characters or formatting. " \
|
44
|
+
"Sentences to translate:"
|
45
|
+
|
39
46
|
|
40
47
|
text.each_with_index do |sentence, index|
|
41
48
|
prompt += "\n#{index + 1}: #{sentence}"
|
@@ -80,10 +87,11 @@ module ImmosquareTranslate
|
|
80
87
|
## On s'assure de ne renvoyer que les locales demandées
|
81
88
|
## car l'API peut renvoyer des locales non demandées...
|
82
89
|
##============================================================##
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
90
|
+
content = JSON.parse(choice["message"]["content"])
|
91
|
+
datas = content["datas"]
|
92
|
+
datas.map do |hash|
|
93
|
+
hash.select {|key, _| to.include?(key) }
|
94
|
+
end.reject(&:empty?)
|
87
95
|
rescue StandardError => e
|
88
96
|
puts(e.message)
|
89
97
|
puts(e.backtrace)
|