Skip to content

Commit

Permalink
Fixes from commit comments
Browse files Browse the repository at this point in the history
  • Loading branch information
InAnYan committed Aug 7, 2024
1 parent 441308d commit 58196dd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
8 changes: 6 additions & 2 deletions src/main/java/org/jabref/logic/ai/AiChatLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import org.jabref.logic.ai.chathistory.AiChatHistory;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.CanonicalBibEntry;
import org.jabref.model.entry.LinkedFile;
import org.jabref.preferences.AiPreferences;

Expand Down Expand Up @@ -115,9 +116,12 @@ private void rebuildChain() {
}

private void setSystemMessage(String systemMessage) {
String realSystemMessage = systemMessage + "\n\n" + "Here is the paper you are analyzing: " + entry.toString();
String newSystemMessage = augmentSystemMessage(systemMessage);
chatMemory.add(new SystemMessage(newSystemMessage));
}

chatMemory.add(new SystemMessage(realSystemMessage));
private String augmentSystemMessage(String oldSystemMessage) {
return oldSystemMessage + "\n\n" + "Here is the paper you are analyzing: " + CanonicalBibEntry.getCanonicalRepresentation(entry);
}

public AiMessage execute(UserMessage message) {
Expand Down
20 changes: 11 additions & 9 deletions src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -2784,15 +2784,17 @@ public AiPreferences getAiPreferences() {
return aiPreferences;
}

boolean aiEnabled = getBoolean(AI_ENABLED);

aiPreferences = new AiPreferences(
getBoolean(AI_ENABLED),
aiEnabled,
AiPreferences.AiProvider.valueOf(get(AI_PROVIDER)),
get(AI_OPEN_AI_CHAT_MODEL),
get(AI_MISTRAL_AI_CHAT_MODEL),
get(AI_HUGGING_FACE_CHAT_MODEL),
getBoolean(AI_ENABLED) ? getApiKeyForAiProvider(AiPreferences.AiProvider.OPEN_AI) : "",
getBoolean(AI_ENABLED) ? getApiKeyForAiProvider(AiPreferences.AiProvider.MISTRAL_AI) : "",
getBoolean(AI_ENABLED) ? getApiKeyForAiProvider(AiPreferences.AiProvider.HUGGING_FACE) : "",
aiEnabled ? getApiKeyForAiProvider(AiPreferences.AiProvider.OPEN_AI) : "",
aiEnabled ? getApiKeyForAiProvider(AiPreferences.AiProvider.MISTRAL_AI) : "",
aiEnabled ? getApiKeyForAiProvider(AiPreferences.AiProvider.HUGGING_FACE) : "",
getBoolean(AI_CUSTOMIZE_SETTINGS),
get(AI_OPEN_AI_API_BASE_URL),
get(AI_MISTRAL_AI_API_BASE_URL),
Expand All @@ -2815,19 +2817,19 @@ public AiPreferences getAiPreferences() {
EasyBind.listen(aiPreferences.huggingFaceChatModelProperty(), (obs, oldValue, newValue) -> put(AI_HUGGING_FACE_CHAT_MODEL, newValue));

EasyBind.listen(aiPreferences.openAiApiTokenProperty(), (obs, oldValue, newValue) -> {
if (getBoolean(AI_ENABLED)) {
if (aiPreferences.getEnableAi()) {
storeAiApiTokenInKeyring(AiPreferences.AiProvider.OPEN_AI, newValue);
}
});

EasyBind.listen(aiPreferences.mistralAiApiTokenProperty(), (obs, oldValue, newValue) -> {
if (getBoolean(AI_ENABLED)) {
if (aiPreferences.getEnableAi()) {
storeAiApiTokenInKeyring(AiPreferences.AiProvider.MISTRAL_AI, newValue);
}
});

EasyBind.listen(aiPreferences.huggingFaceApiTokenProperty(), (obs, oldValue, newValue) -> {
if (getBoolean(AI_ENABLED)) {
if (aiPreferences.getEnableAi()) {
storeAiApiTokenInKeyring(AiPreferences.AiProvider.HUGGING_FACE, newValue);
}
});
Expand All @@ -2840,12 +2842,12 @@ public AiPreferences getAiPreferences() {

EasyBind.listen(aiPreferences.embeddingModelProperty(), (obs, oldValue, newValue) -> put(AI_EMBEDDING_MODEL, newValue.name()));
EasyBind.listen(aiPreferences.instructionProperty(), (obs, oldValue, newValue) -> put(AI_SYSTEM_MESSAGE, newValue));
EasyBind.listen(aiPreferences.temperatureProperty(), (obs, oldValue, newValue) -> putDouble(AI_TEMPERATURE, (double) newValue));
EasyBind.listen(aiPreferences.temperatureProperty(), (obs, oldValue, newValue) -> putDouble(AI_TEMPERATURE, newValue.doubleValue()));
EasyBind.listen(aiPreferences.contextWindowSizeProperty(), (obs, oldValue, newValue) -> putInt(AI_CONTEXT_WINDOW_SIZE, newValue));
EasyBind.listen(aiPreferences.documentSplitterChunkSizeProperty(), (obs, oldValue, newValue) -> putInt(AI_DOCUMENT_SPLITTER_CHUNK_SIZE, newValue));
EasyBind.listen(aiPreferences.documentSplitterOverlapSizeProperty(), (obs, oldValue, newValue) -> putInt(AI_DOCUMENT_SPLITTER_OVERLAP_SIZE, newValue));
EasyBind.listen(aiPreferences.ragMaxResultsCountProperty(), (obs, oldValue, newValue) -> putInt(AI_RAG_MAX_RESULTS_COUNT, newValue));
EasyBind.listen(aiPreferences.ragMinScoreProperty(), (obs, oldValue, newValue) -> putDouble(AI_RAG_MIN_SCORE, (Double) newValue));
EasyBind.listen(aiPreferences.ragMinScoreProperty(), (obs, oldValue, newValue) -> putDouble(AI_RAG_MIN_SCORE, newValue.doubleValue()));

return aiPreferences;
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/jabref/preferences/PreferencesService.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,11 @@ public interface PreferencesService {

AiPreferences getAiPreferences();

/**
* Retrieves the API key for the specified AI provider.
*
* @param provider the AI provider for which the API key is requested
* @return the API key for the specified AI provider, or empty string if no key is found
*/
String getApiKeyForAiProvider(AiPreferences.AiProvider provider);
}

0 comments on commit 58196dd

Please sign in to comment.