diff --git a/build.gradle.kts b/build.gradle.kts index a798b0a5..b658a7d2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ plugins { } group = "com.devoxx.genie" -version = "0.1.13" +version = "0.1.14" repositories { mavenCentral() diff --git a/src/main/java/com/devoxx/genie/model/Constant.java b/src/main/java/com/devoxx/genie/model/Constant.java index 28b8fd58..6257579c 100644 --- a/src/main/java/com/devoxx/genie/model/Constant.java +++ b/src/main/java/com/devoxx/genie/model/Constant.java @@ -22,7 +22,7 @@ private Constant() { public static final Integer MAX_OUTPUT_TOKENS = 2500; public static final Integer MAX_RETRIES = 3; public static final Integer TIMEOUT = 60; - public static final Integer MAX_MEMORY = 6; + public static final Integer MAX_MEMORY = 10; public static final Boolean STREAM_MODE = false; diff --git a/src/main/java/com/devoxx/genie/service/ChatMemoryService.java b/src/main/java/com/devoxx/genie/service/ChatMemoryService.java index c4d3907c..72da7044 100644 --- a/src/main/java/com/devoxx/genie/service/ChatMemoryService.java +++ b/src/main/java/com/devoxx/genie/service/ChatMemoryService.java @@ -1,5 +1,7 @@ package com.devoxx.genie.service; +import com.devoxx.genie.ui.listener.ChatMemorySizeListener; +import com.devoxx.genie.ui.topic.AppTopics; import com.intellij.openapi.application.ApplicationManager; import dev.langchain4j.data.message.ChatMessage; import dev.langchain4j.memory.chat.MessageWindowChatMemory; @@ -8,14 +10,26 @@ import java.util.List; -public class ChatMemoryService { +public class ChatMemoryService implements ChatMemorySizeListener { - private final MessageWindowChatMemory chatMemory = - MessageWindowChatMemory.builder() - .id("devoxxgenie") - .chatMemoryStore(new InMemoryChatMemoryStore()) - .maxMessages(10) // TODO Make this configurable in the Settings page - .build(); + private final InMemoryChatMemoryStore inMemoryChatMemoryStore = new InMemoryChatMemoryStore(); + + private MessageWindowChatMemory chatMemory; + + /** + * Initialize the chat memory service triggered by PostStartupActivity + * @link PostStartupActivity + */ + public void init() { + createChatMemory(SettingsStateService.getInstance().getChatMemorySize()); + createChangeListener(); + } + + private void createChangeListener() { + ApplicationManager.getApplication().getMessageBus() + .connect() + .subscribe(AppTopics.CHAT_MEMORY_SIZE_TOPIC, this); + } @NotNull public static ChatMemoryService getInstance() { @@ -37,4 +51,17 @@ public List messages() { public boolean isEmpty() { return chatMemory.messages().isEmpty(); } + + @Override + public void onChatMemorySizeChanged(int chatMemorySize) { + createChatMemory(chatMemorySize); + } + + private void createChatMemory(int chatMemorySize) { + chatMemory = MessageWindowChatMemory.builder() + .id("devoxxgenie") + .chatMemoryStore(inMemoryChatMemoryStore) + .maxMessages(chatMemorySize) + .build(); + } } diff --git a/src/main/java/com/devoxx/genie/service/PostStartupActivity.java b/src/main/java/com/devoxx/genie/service/PostStartupActivity.java new file mode 100644 index 00000000..fc5a18c0 --- /dev/null +++ b/src/main/java/com/devoxx/genie/service/PostStartupActivity.java @@ -0,0 +1,18 @@ +package com.devoxx.genie.service; + +import com.intellij.openapi.project.Project; +import com.intellij.openapi.startup.ProjectActivity; +import kotlin.Unit; +import kotlin.coroutines.Continuation; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class PostStartupActivity implements ProjectActivity { + + @Nullable + @Override + public Object execute(@NotNull Project project, @NotNull Continuation continuation) { + ChatMemoryService.getInstance().init(); + return continuation; + } +} diff --git a/src/main/java/com/devoxx/genie/service/SettingsStateService.java b/src/main/java/com/devoxx/genie/service/SettingsStateService.java index f295eb96..90af85d9 100644 --- a/src/main/java/com/devoxx/genie/service/SettingsStateService.java +++ b/src/main/java/com/devoxx/genie/service/SettingsStateService.java @@ -56,7 +56,7 @@ public static SettingsStateService getInstance() { private Integer timeout = Constant.TIMEOUT; private Integer maxRetries = Constant.MAX_RETRIES; - private Integer maxMemory = Constant.MAX_MEMORY; + private Integer chatMemorySize = Constant.MAX_MEMORY; // Was unable to make it work with Integer for some unknown reason private String maxOutputTokens = Constant.MAX_OUTPUT_TOKENS.toString(); diff --git a/src/main/java/com/devoxx/genie/ui/DevoxxGenieSettingsManager.java b/src/main/java/com/devoxx/genie/ui/DevoxxGenieSettingsManager.java index 52d38564..925dc018 100644 --- a/src/main/java/com/devoxx/genie/ui/DevoxxGenieSettingsManager.java +++ b/src/main/java/com/devoxx/genie/ui/DevoxxGenieSettingsManager.java @@ -49,6 +49,7 @@ public class DevoxxGenieSettingsManager implements Configurable { private JFormattedTextField timeoutField; private JFormattedTextField retryField; + private JFormattedTextField chatMemorySizeField; private JCheckBox streamModeCheckBox; @@ -103,6 +104,7 @@ public JComponent createComponent() { setTitle("LLM Parameters", settingsPanel, gbc); + chatMemorySizeField = addFormattedFieldWithLabel(settingsPanel, gbc, "Chat memory size:", settings.getTemperature()); temperatureField = addFormattedFieldWithLabel(settingsPanel, gbc, "Temperature:", settings.getTemperature()); topPField = addFormattedFieldWithLabel(settingsPanel, gbc, "Top-P:", settings.getTopP()); maxOutputTokensField = addTextFieldWithLabel(settingsPanel, gbc, "Maximum output tokens :", settings.getMaxOutputTokens()); @@ -348,6 +350,7 @@ public boolean isModified() { isModified |= isFieldModified(timeoutField, settings.getTimeout()); isModified |= isFieldModified(maxOutputTokensField, settings.getMaxOutputTokens()); isModified |= isFieldModified(retryField, settings.getMaxRetries()); + isModified |= isFieldModified(chatMemorySizeField, settings.getChatMemorySize()); isModified |= isFieldModified(testPromptField, settings.getTestPrompt()); isModified |= isFieldModified(explainPromptField, settings.getExplainPrompt()); isModified |= isFieldModified(reviewPromptField, settings.getReviewPrompt()); @@ -383,6 +386,7 @@ public void apply() { notifySettingsChanged(); } + boolean chatMemoryModified = false; updateSettingIfModified(ollamaUrlField, settings.getOllamaModelUrl(), settings::setOllamaModelUrl); updateSettingIfModified(lmstudioUrlField, settings.getLmstudioModelUrl(), settings::setLmstudioModelUrl); updateSettingIfModified(gpt4allUrlField, settings.getGpt4allModelUrl(), settings::setGpt4allModelUrl); @@ -391,6 +395,7 @@ public void apply() { updateSettingIfModified(topPField, doubleConverter.toString(settings.getTopP()), value -> settings.setTopP(doubleConverter.fromString(value))); updateSettingIfModified(timeoutField, settings.getTimeout(), value -> settings.setTimeout(safeCastToInteger(value))); updateSettingIfModified(retryField, settings.getMaxRetries(), value -> settings.setMaxRetries(safeCastToInteger(value))); + chatMemoryModified = updateSettingIfModified(chatMemorySizeField, settings.getChatMemorySize(), value -> settings.setChatMemorySize(safeCastToInteger(value))); updateSettingIfModified(maxOutputTokensField, settings.getMaxOutputTokens(), settings::setMaxOutputTokens); updateSettingIfModified(testPromptField, settings.getTestPrompt(), settings::setTestPrompt); updateSettingIfModified(explainPromptField, settings.getExplainPrompt(), settings::setExplainPrompt); @@ -407,6 +412,10 @@ public void apply() { updateSettingIfModified(astParentClassCheckBox, settings.getAstParentClass(), value -> settings.setAstParentClass(Boolean.parseBoolean(value))); updateSettingIfModified(astReferenceClassesCheckBox, settings.getAstClassReference(), value -> settings.setAstClassReference(Boolean.parseBoolean(value))); updateSettingIfModified(astReferenceFieldCheckBox, settings.getAstFieldReference(), value -> settings.setAstFieldReference(Boolean.parseBoolean(value))); + + if (chatMemoryModified) { + notifyChatMemorySizeChangeListeners(); + } } /** @@ -427,6 +436,15 @@ public boolean updateSettingIfModified(JComponent field, return false; } + /** + * Notify the chat memory size change listeners + */ + public void notifyChatMemorySizeChangeListeners() { + ApplicationManager.getApplication().getMessageBus() + .syncPublisher(AppTopics.CHAT_MEMORY_SIZE_TOPIC) + .onChatMemorySizeChanged(SettingsStateService.getInstance().getChatMemorySize()); + } + /** * Extract the string value from the field * @@ -468,6 +486,7 @@ public void reset() { setValue(topPField, settingsState.getTopP()); setValue(timeoutField, settingsState.getTimeout()); setValue(retryField, settingsState.getMaxRetries()); + setValue(chatMemorySizeField, settingsState.getChatMemorySize()); } /** diff --git a/src/main/java/com/devoxx/genie/ui/listener/ChatMemorySizeListener.java b/src/main/java/com/devoxx/genie/ui/listener/ChatMemorySizeListener.java new file mode 100644 index 00000000..aab36225 --- /dev/null +++ b/src/main/java/com/devoxx/genie/ui/listener/ChatMemorySizeListener.java @@ -0,0 +1,5 @@ +package com.devoxx.genie.ui.listener; + +public interface ChatMemorySizeListener { + void onChatMemorySizeChanged(int chatMemorySize); +} diff --git a/src/main/java/com/devoxx/genie/ui/topic/AppTopics.java b/src/main/java/com/devoxx/genie/ui/topic/AppTopics.java index db57add3..e67335ae 100644 --- a/src/main/java/com/devoxx/genie/ui/topic/AppTopics.java +++ b/src/main/java/com/devoxx/genie/ui/topic/AppTopics.java @@ -1,5 +1,6 @@ package com.devoxx.genie.ui.topic; +import com.devoxx.genie.ui.listener.ChatMemorySizeListener; import com.devoxx.genie.ui.listener.ChatMessageManagementService; import com.devoxx.genie.ui.listener.SettingsChangeListener; import com.intellij.util.messages.Topic; @@ -12,4 +13,6 @@ public class AppTopics { public static final Topic CHAT_MESSAGES_CHANGED_TOPIC = Topic.create("chatChanged", ChatMessageManagementService.class); + public static final Topic CHAT_MEMORY_SIZE_TOPIC = + new Topic<>("CHAT_MEMORY_SIZE_TOPIC", ChatMemorySizeListener.class); } diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 7273a338..dedec251 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -32,6 +32,10 @@ ]]> v0.1.14 +
    +
  • Feat #78: Set chat memory size in Settings page.
  • +

v0.1.13

  • Feat #71: Auto Abstract Syntax Tree (AST) context: Automatically includes information about the superclass and class fields in the context for better code analysis and understanding.
  • @@ -189,6 +193,7 @@ +