Skip to content

Commit afa1b02

Browse files
rbenzaAirsaid
authored andcommitted
Shorten role
1 parent 1dc9ccc commit afa1b02

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/main/java/com/airsaid/localization/translate/impl/openai/ChatGPTTranslator.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@
2424
import com.google.auto.service.AutoService;
2525
import com.intellij.openapi.diagnostic.Logger;
2626
import com.intellij.util.io.RequestBuilder;
27-
import icons.PluginIcons;
27+
2828
import org.jetbrains.annotations.NotNull;
2929
import org.jetbrains.annotations.Nullable;
3030

31-
import javax.swing.*;
3231
import java.util.List;
3332

33+
import javax.swing.Icon;
34+
35+
import icons.PluginIcons;
36+
3437

3538
@AutoService(AbstractTranslator.class)
3639
public class ChatGPTTranslator extends AbstractTranslator {
@@ -82,16 +85,13 @@ public String getAppKeyDisplay() {
8285
@Override
8386
@NotNull
8487
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);
9190

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));
9393

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));
9595

9696
return GsonUtil.getInstance().getGson().toJson(body);
9797
}

0 commit comments

Comments
 (0)