Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loextension aisupport #10680

Merged
merged 10 commits into from
Jun 25, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,38 @@ guiUseServerSettings = Use server settings
guiUsePremiumAccount = Use premium account (for premium user)
guiPremiumUsername = User name:
guiPremiumApiKey = API Key:
guiAiSupportSettings = AI Support Settings
guiUseAiSupport = Use AI Support
guiAiUrl = AI Server URL
guiAiModel = AI Model
guiAiApiKey = AI API Key
guiAiAutoCorrect = Enable automatic Error detection
guiAiShowStylisticChanges = Show also suggestions for stylistic changes
guiAiExperimentalHint = NOTE: This feature is still very experimental.
guiAiQualityHint = The speed and quality of the results depends on the installation and model used.
loMenuAiSupport = AI Support
loMenuAiAddErrorMarks = AI: add detected errors
loMenuAiGeneralCommand = AI: General paragraph changes
loMenuAiGeneralCommandTitle = Command input
loMenuAiGeneralCommandMessage = Enter any command to manipulate the paragraph
loAiWaitDialogTitle = Please Wait
loAiWaitDialogMessage = Please wait until the AI has completed your request.\nThis may take some time depending on the workload.
loAiRuleDescription = AI error detection
loAiRuleMessage = The AI suggests the following correction
loAiDialogTitle = LT AI Dialog
loAiDialogInstructionLabel = Instruction
loAiDialogParagraphLabel = Text to be edited
loAiDialogResultLabel = AI generated text
loAiDialogExecuteButton = Execute instruction
loAiDialogcopyResultButton = Copy Result
loAiDialogResetButton = Reset
loAiDialogClearButton = Delete text
loAiDialogUndoButton = Undo
loAiDialogOverrideButton = override Paragraph
loAiDialogaddToButton = add to Paragraph
loAiDialogHelpButton = Help
loAiDialogCloseButton = Close
loAiCorrectInstruction = Output the grammatically and orthographically corrected text
guiStyleRepeatedWordText = Maximum distance between two repeated words (0 - 5 sentences):
guiLongSentencesText = Maximum sentences length (5 - 100 words):
guiLongParagraphsText = Maximum paragraphs length (5 - {0} words):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,38 @@ guiLongSentencesText = Maximum sentences length (5 - 100 words):
guiPremiumUsername = User name:
guiLongParagraphsText = Maximum paragraphs length (5 - {0} words):
guiPremiumApiKey = API Key:
guiAiSupportSettings = AI Support Settings
guiUseAiSupport = Use AI Support
guiAiUrl = AI Server URL
guiAiModel = AI Model
guiAiApiKey = AI API Key
guiAiAutoCorrect = Enable automatic Error detection
guiAiShowStylisticChanges = Show also suggestions for stylistic changes
guiAiExperimentalHint = NOTE: This feature is still very experimental.
guiAiQualityHint = The speed and quality of the results depends on the installation and model used.
loMenuAiSupport = AI Support
loMenuAiAddErrorMarks = AI: add detected errors
loMenuAiGeneralCommand = AI: General paragraph changes
loMenuAiGeneralCommandTitle = Command input
loMenuAiGeneralCommandMessage = Enter any command to manipulate the paragraph
loAiWaitDialogTitle = Please Wait
loAiWaitDialogMessage = Please wait until the AI has completed your request.\nThis may take some time depending on the workload.
loAiRuleDescription = AI error detection
loAiRuleMessage = The AI suggests the following correction
loAiDialogTitle = LT AI Dialog
loAiDialogInstructionLabel = Instruction
loAiDialogParagraphLabel = Text to be edited
loAiDialogResultLabel = AI generated text
loAiDialogExecuteButton = Execute instruction
loAiDialogcopyResultButton = Copy Result
loAiDialogResetButton = Reset
loAiDialogClearButton = Delete text
loAiDialogUndoButton = Undo
loAiDialogOverrideButton = override Paragraph
loAiDialogaddToButton = add to Paragraph
loAiDialogHelpButton = Help
loAiDialogCloseButton = Close
loAiCorrectInstruction = Output the grammatically and orthographically corrected text
guiUnderlineColor = Underline Color of Category
guiUColorHint = Underline colors are supported by LibreOffice version 6.2.0 and higher
guiUColorHint1 = Underline types are supported by LibreOffice version 6.3.0 and higher
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class Configuration {
public final static short UNDERLINE_BOLDWAVE = 18;
public final static short UNDERLINE_BOLD = 12;
public final static short UNDERLINE_DASH = 5;

static final int DEFAULT_SERVER_PORT = 8081; // should be HTTPServerConfig.DEFAULT_PORT but we don't have that dependency
static final int DEFAULT_NUM_CHECK_PARAS = -1; // default number of parameters to be checked by TextLevelRules in LO/OO
static final int FONT_STYLE_INVALID = -1;
Expand All @@ -80,6 +80,13 @@ public class Configuration {
static final boolean DEFAULT_ENABLE_GOAL_SPECIFIC_RULES = false;
static final boolean DEFAULT_FILTER_OVERLAPPING_MATCHES = true;
static final boolean DEFAULT_SAVE_LO_CACHE = true;
static final boolean DEFAULT_USE_AI_SUPPORT = false;
static final boolean DEFAULT_AI_AUTO_CORRECT = false;
static final boolean DEFAULT_AI_SHOW_STYLISTIC_CHANGES = false;

static final String DEFAULT_AI_MODEL = "gpt-4";
static final String DEFAULT_AI_URL = "http://localhost:8080/v1/chat/completions/";
static final String DEFAULT_AI_APIKEY = "1234567";

static final Color STYLE_COLOR = new Color(0, 175, 0);

Expand Down Expand Up @@ -137,6 +144,12 @@ public class Configuration {
private static final String FILTER_OVERLAPPING_MATCHES_KEY = "filterOverlappingMatches";
private static final String SAVE_LO_CACHE_KEY = "saveLoCache";
private static final String LT_VERSION_KEY = "ltVersion";
private static final String AI_URL_KEY = "aiUrl";
private static final String AI_APIKEY_KEY = "aiApiKey";
private static final String AI_MODEL_KEY = "aiModel";
private static final String AI_USE_AI_SUPPORT_KEY = "useAiSupport";
private static final String AI_AUTO_CORRECT_KEY = "aiAutoCorrect";
private static final String AI_SHOW_STYLISTIC_CHANGES_KEY = "aiShowStylisticChanges";

private static final String DELIMITER = ",";
// find all comma followed by zero or more white space characters that are preceded by ":" AND a valid 6-digit hex code
Expand Down Expand Up @@ -218,6 +231,12 @@ public class Configuration {
private boolean switchOff = false;
private boolean isOffice = false;
private boolean isOpenOffice = false;
private String aiUrl = DEFAULT_AI_URL;
private String aiApiKey = DEFAULT_AI_APIKEY;
private String aiModel = DEFAULT_AI_MODEL;
private boolean useAiSupport = DEFAULT_USE_AI_SUPPORT;
private boolean aiAutoCorrect = DEFAULT_AI_AUTO_CORRECT;
private boolean aiShowStylisticChanges = DEFAULT_AI_SHOW_STYLISTIC_CHANGES;

/**
* Uses the configuration file from the default location.
Expand Down Expand Up @@ -301,6 +320,12 @@ public void initOptions() {
enableGoalSpecificRules = DEFAULT_ENABLE_GOAL_SPECIFIC_RULES;
filterOverlappingMatches = DEFAULT_FILTER_OVERLAPPING_MATCHES;
saveLoCache = DEFAULT_SAVE_LO_CACHE;
aiUrl = DEFAULT_AI_URL;
aiApiKey = DEFAULT_AI_APIKEY;
aiModel = DEFAULT_AI_MODEL;
useAiSupport = DEFAULT_USE_AI_SUPPORT;
aiAutoCorrect = DEFAULT_AI_AUTO_CORRECT;
aiShowStylisticChanges = DEFAULT_AI_SHOW_STYLISTIC_CHANGES;
externalRuleDirectory = null;
lookAndFeelName = null;
currentProfile = null;
Expand Down Expand Up @@ -368,6 +393,12 @@ void restoreState(Configuration configuration) {
this.isOffice = configuration.isOffice;
this.isOpenOffice = configuration.isOpenOffice;
this.ltVersion = configuration.ltVersion;
this.aiUrl = configuration.aiUrl;
this.aiApiKey = configuration.aiApiKey;
this.aiModel = configuration.aiModel;
this.useAiSupport = configuration.useAiSupport;
this.aiAutoCorrect = configuration.aiAutoCorrect;
this.aiShowStylisticChanges = configuration.aiShowStylisticChanges;

this.disabledRuleIds.clear();
this.disabledRuleIds.addAll(configuration.disabledRuleIds);
Expand Down Expand Up @@ -569,6 +600,54 @@ public void setRemoteApiKey(String remoteApiKey) {
this.remoteApiKey = remoteApiKey;
}

public String aiUrl() {
return aiUrl;
}

public void setAiUrl(String aiUrl) {
this.aiUrl = aiUrl;
}

public String aiModel() {
return aiModel;
}

public void setAiModel(String aiModel) {
this.aiModel = aiModel;
}

public String aiApiKey() {
return aiApiKey;
}

public void setAiApiKey(String aiApiKey) {
this.aiApiKey = aiApiKey;
}

public boolean useAiSupport() {
return useAiSupport;
}

public void setUseAiSupport(boolean useAiSupport) {
this.useAiSupport = useAiSupport;
}

public boolean aiAutoCorrect() {
return aiAutoCorrect;
}

public void setAiAutoCorrect(boolean aiAutoCorrect) {
this.aiAutoCorrect = aiAutoCorrect;
}

public boolean aiShowStylisticChanges() {
return aiShowStylisticChanges;
}

public void setAiShowStylisticChanges(boolean aiShowStylisticChanges) {
this.aiShowStylisticChanges = aiShowStylisticChanges;
}

public String getRemoteApiKey() {
return isPremium ? remoteApiKey : null;
}
Expand Down Expand Up @@ -1200,6 +1279,13 @@ public boolean isValidServerUrl(String url) {
return true;
}

public boolean isValidAiServerUrl(String url) {
if (!Pattern.matches("https?://.+(:\\d+)?.*", url)) {
return false;
}
return true;
}

private void loadConfiguration() throws IOException {
loadConfiguration(null);
}
Expand Down Expand Up @@ -1426,6 +1512,37 @@ private void loadCurrentProfile(Properties props, String prefix, String qualifie
saveLoCache = Boolean.parseBoolean(saveLoCacheString);
}

String aiString = (String) props.get(prefix + AI_URL_KEY);
if (aiString != null) {
aiUrl = aiString;
}

aiString = (String) props.get(prefix + AI_MODEL_KEY);
if (aiString != null) {
aiModel = aiString;
}

aiString = (String) props.get(prefix + AI_APIKEY_KEY);
if (aiString != null) {
aiApiKey = aiString;
}

aiString = (String) props.get(prefix + AI_USE_AI_SUPPORT_KEY);
if (aiString != null) {
useAiSupport = Boolean.parseBoolean(aiString);
}

aiString = (String) props.get(prefix + AI_AUTO_CORRECT_KEY);
if (aiString != null) {
aiAutoCorrect = Boolean.parseBoolean(aiString);
}

aiString = (String) props.get(prefix + AI_SHOW_STYLISTIC_CHANGES_KEY);
if (aiString != null) {
aiShowStylisticChanges = Boolean.parseBoolean(aiString);
}


String rulesValuesString = (String) props.get(prefix + CONFIGURABLE_RULE_VALUES_KEY + qualifier);
if (rulesValuesString == null) {
rulesValuesString = (String) props.get(prefix + CONFIGURABLE_RULE_VALUES_KEY);
Expand Down Expand Up @@ -1659,6 +1776,12 @@ private void setAllProfileKeys() {
allProfileKeys.add(ENABLE_GOAL_SPECIFIC_RULES_KEY);
allProfileKeys.add(FILTER_OVERLAPPING_MATCHES_KEY);
allProfileKeys.add(SAVE_LO_CACHE_KEY);
allProfileKeys.add(AI_URL_KEY);
allProfileKeys.add(AI_APIKEY_KEY);
allProfileKeys.add(AI_MODEL_KEY);
allProfileKeys.add(AI_USE_AI_SUPPORT_KEY);
allProfileKeys.add(AI_AUTO_CORRECT_KEY);
allProfileKeys.add(AI_SHOW_STYLISTIC_CHANGES_KEY);

allProfileLangKeys.add(DISABLED_RULES_KEY);
allProfileLangKeys.add(ENABLED_RULES_KEY);
Expand Down Expand Up @@ -1790,6 +1913,24 @@ private void saveConfigForCurrentProfile(Properties props, String prefix, String
if (remoteApiKey != null) {
props.setProperty(prefix + REMOTE_APIKEY_KEY, remoteApiKey);
}
if (aiUrl != null) {
props.setProperty(prefix + AI_URL_KEY, aiUrl);
}
if (aiModel != null) {
props.setProperty(prefix + AI_MODEL_KEY, aiModel);
}
if (aiApiKey != null) {
props.setProperty(prefix + AI_APIKEY_KEY, aiApiKey);
}
if (useAiSupport != DEFAULT_USE_AI_SUPPORT) {
props.setProperty(prefix + AI_USE_AI_SUPPORT_KEY, Boolean.toString(useAiSupport));
}
if (aiAutoCorrect != DEFAULT_AI_AUTO_CORRECT) {
props.setProperty(prefix + AI_AUTO_CORRECT_KEY, Boolean.toString(aiAutoCorrect));
}
if (this.aiShowStylisticChanges != DEFAULT_AI_SHOW_STYLISTIC_CHANGES) {
props.setProperty(prefix + AI_SHOW_STYLISTIC_CHANGES_KEY, Boolean.toString(aiShowStylisticChanges));
}
if (fontName != null) {
props.setProperty(prefix + FONT_NAME_KEY, fontName);
}
Expand Down
Loading