immosquare-translate 0.1.4 → 0.1.5
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 +17 -11
- 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: 9daf467e21100501ea1833692e80742d341950fb05f1a451b25134a83e7ba7e1
|
4
|
+
data.tar.gz: 7fe077c183fb8beee8d917abad7d014eafd811ef300574cfc776427efad51f0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5758dc40a24ab4721d4ec72184d181567e96949b03aeb71e8bbdd14ffc107f0def5197719bf069ab65486fb65876223029d67f5f82de12a5ee96391c5dd61b97
|
7
|
+
data.tar.gz: 8ade76c458bb26cec34a1c369703b6e1141a10fc99fbb56774e423ea3ccb95658c82863c7c86cb9169d3fd82e2434cafeb200390f2b7d283a391de44c574e868
|
@@ -26,16 +26,21 @@ 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
|
-
"It is imperative that you return the translations in a single, pure JSON string format. Use ISO 639-1 language codes for specifying languages
|
31
|
-
"If string is html, you should return the translated html
|
29
|
+
prompt_system = "As a sophisticated translation AI, your role is to translate sentences from a specified source language to multiple target languages.\n" \
|
30
|
+
"It is imperative that you return the translations in a single, pure JSON string format. Use ISO 639-1 language codes for specifying languages.\n" \
|
31
|
+
"If string is html, you should return the translated html.\n" \
|
32
32
|
"Ensure that the output does not include markdown (```json) or any other formatting characters. Adhere to the JSON structure meticulously."
|
33
33
|
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
"
|
38
|
-
"
|
35
|
+
|
36
|
+
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(", ")}. " \
|
37
|
+
"Before translating, correct any spelling or grammatical errors in each sentence. " \
|
38
|
+
"If the source language is also a target language, include the corrected version of the sentence for that language as well. " \
|
39
|
+
"Format the translation output as a JSON string adhering to the following structure: " \
|
40
|
+
"{\"datas\":[{\"locale_iso\": \"Translated Text\"}]}, where 'locale_iso' is replaced with the appropriate ISO 639-1 code for each translation. " \
|
41
|
+
"Ensure the output strictly follows this JSON format, without any extraneous characters or formatting. " \
|
42
|
+
"Sentences to translate:"
|
43
|
+
|
39
44
|
|
40
45
|
text.each_with_index do |sentence, index|
|
41
46
|
prompt += "\n#{index + 1}: #{sentence}"
|
@@ -80,10 +85,11 @@ module ImmosquareTranslate
|
|
80
85
|
## On s'assure de ne renvoyer que les locales demandées
|
81
86
|
## car l'API peut renvoyer des locales non demandées...
|
82
87
|
##============================================================##
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
88
|
+
content = JSON.parse(choice["message"]["content"])
|
89
|
+
datas = content["datas"]
|
90
|
+
datas.map do |hash|
|
91
|
+
hash.select {|key, _| to.include?(key) }
|
92
|
+
end.reject(&:empty?)
|
87
93
|
rescue StandardError => e
|
88
94
|
puts(e.message)
|
89
95
|
puts(e.backtrace)
|