|
24 | 24 | import com.google.auto.service.AutoService; |
25 | 25 | import com.intellij.openapi.diagnostic.Logger; |
26 | 26 | import com.intellij.util.io.RequestBuilder; |
27 | | -import icons.PluginIcons; |
| 27 | + |
28 | 28 | import org.jetbrains.annotations.NotNull; |
29 | 29 | import org.jetbrains.annotations.Nullable; |
30 | 30 |
|
31 | | -import javax.swing.*; |
32 | 31 | import java.util.List; |
33 | 32 |
|
| 33 | +import javax.swing.Icon; |
| 34 | + |
| 35 | +import icons.PluginIcons; |
| 36 | + |
34 | 37 |
|
35 | 38 | @AutoService(AbstractTranslator.class) |
36 | 39 | public class ChatGPTTranslator extends AbstractTranslator { |
@@ -82,16 +85,13 @@ public String getAppKeyDisplay() { |
82 | 85 | @Override |
83 | 86 | @NotNull |
84 | 87 | public String getRequestBody(@NotNull Lang fromLang, @NotNull Lang toLang, @NotNull String text) { |
85 | | - String roleSystem = String.format("Become a professional translator. You're translating text for the user interface of an Android app. Your audience are native %s speakers so try to keep cultural connotations. Use the exact formatting and style of the original text. " + |
86 | | - "Try to keep the translated text around the same length or shorter than the original. Just repeat the original text when the translation is not different (e.g a word like 'OK'). Now translate the text from the user into %s", toLang.getEnglishName(), toLang.getEnglishName()); |
87 | | - |
88 | | - ChatGPTMessage role = new ChatGPTMessage("system", roleSystem); // todo find out why gives SocketTimeOUt exception |
89 | | - |
90 | | - String instruction = String.format("Translate the text below into %s while maintaining the original formatting and style. Keep translations concise and repeat the original text for unchanged translations (e.g. 'OK'). Text to translate: %s", toLang.getEnglishName(), text); |
| 88 | + String lang = toLang.getEnglishName(); |
| 89 | + String roleSystem = String.format("Translate the user provided text into %s. Apply these translation rules; 1.Keep the exact original formatting and style. 2.Keep translations concise and repeat the original text for unchanged translations (e.g. 'OK'). 3.Audience: native %s speakers. 4.Text is used in: Android app User interface", lang, lang); |
91 | 90 |
|
92 | | - ChatGPTMessage msg = new ChatGPTMessage("user", instruction); |
| 91 | + ChatGPTMessage role = new ChatGPTMessage("system", roleSystem); |
| 92 | + ChatGPTMessage msg = new ChatGPTMessage("user", String.format("Text to translate: %s", text)); |
93 | 93 |
|
94 | | - OpenAIRequest body = new OpenAIRequest("gpt-3.5-turbo", List.of(msg)); |
| 94 | + OpenAIRequest body = new OpenAIRequest("gpt-3.5-turbo", List.of(role, msg)); |
95 | 95 |
|
96 | 96 | return GsonUtil.getInstance().getGson().toJson(body); |
97 | 97 | } |
|
0 commit comments