Skip to content

Commit

Permalink
LLM Setting Component
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanj committed Jun 3, 2024
1 parent b49208d commit 3c43826
Show file tree
Hide file tree
Showing 13 changed files with 548 additions and 112 deletions.
14 changes: 11 additions & 3 deletions src/main/java/com/devoxx/genie/model/Constant.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@ private Constant() {
// The fixed command prompts
public static final String SYSTEM_PROMPT = """
You are a software developer with expert knowledge in any programming language.
Always return the response in Markdown.
The Devoxx Genie plugin supports the following commands: /test: write unit tests on selected code\\n/explain: explain the selected code\\n/review: review selected code\\n/custom: set custom prompt in settings
The Devoxx Genie plugin supports the following commands:
/test: write unit tests on selected code
/explain: explain the selected code
/review: review selected code
/custom: set custom prompt in settings
The Devoxx Genie is open source and available at https://github.com/devoxx/DevoxxGenieIDEAPlugin.
Do not include any more info which might be incorrect, like discord, twitter, documentation or website info. Only provide info that is correct and relevant to the code or plugin.
Do not include any more info which might be incorrect, like discord, twitter, documentation or website info.
Only provide info that is correct and relevant to the code or plugin.
""";

public static final String MARKDOWN = "\nAlways use markdown to format your prompt. For example, use **bold** or *italic* text and ``` code blocks ```.";

public static final String TEST_PROMPT = "Write a unit test for this code using JUnit.";
public static final String REVIEW_PROMPT = "Review the selected code, can it be improved or are there any bugs?";
public static final String EXPLAIN_PROMPT = "Break down the code in simple terms to help a junior developer grasp its functionality.";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.devoxx.genie.service;

import com.devoxx.genie.model.Constant;
import com.devoxx.genie.model.request.ChatMessageContext;
import com.devoxx.genie.service.settings.SettingsStateService;
import com.intellij.openapi.application.ApplicationManager;
Expand Down Expand Up @@ -50,7 +51,9 @@ static PromptExecutionService getInstance() {
MessageCreationService messageCreationService = MessageCreationService.getInstance();

if (ChatMemoryService.getInstance().isEmpty()) {
ChatMemoryService.getInstance().add(new SystemMessage(SettingsStateService.getInstance().getSystemPrompt()));
ChatMemoryService.getInstance().add(
new SystemMessage(SettingsStateService.getInstance().getSystemPrompt() + Constant.MARKDOWN)
);
}

UserMessage userMessage = messageCreationService.createUserMessage(chatMessageContext);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.devoxx.genie.service.settings.llm;

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.Service;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.util.xmlb.XmlSerializerUtil;
import lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.NotNull;

import static com.devoxx.genie.model.Constant.*;

@Getter
@Setter
@Service
@State(
name = "com.devoxx.genie.ui.SettingsState",
storages = @Storage("DevoxxGenieSettingsPlugin.xml")
)
public final class LLMStateService implements PersistentStateComponent<LLMStateService> {

public static LLMStateService getInstance() {
return ApplicationManager.getApplication().getService(LLMStateService.class);
}

// Local LLM URL fields
private String ollamaModelUrl = OLLAMA_MODEL_URL;
private String lmstudioModelUrl = LMSTUDIO_MODEL_URL;
private String gpt4allModelUrl = GPT4ALL_MODEL_URL;
private String janModelUrl = JAN_MODEL_URL;

// LLM API Keys
private String openAIKey = "";
private String mistralKey = "";
private String anthropicKey = "";
private String groqKey = "";
private String deepInfraKey = "";
private String geminiKey = "";

// Search API Keys
private Boolean hideSearchButtonsFlag = HIDE_SEARCH_BUTTONS;
private String googleSearchKey = "";
private String googleCSIKey = "";
private String tavilySearchKey = "";

// Enable stream mode
private Boolean streamMode = STREAM_MODE;

@Override
public LLMStateService getState() {
return this;
}

@Override
public void loadState(@NotNull LLMStateService state) {
XmlSerializerUtil.copyBean(state, this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.devoxx.genie.service.settings.llmconfig;

import com.devoxx.genie.ui.util.DoubleConverter;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.Service;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.util.xmlb.XmlSerializerUtil;
import com.intellij.util.xmlb.annotations.OptionTag;
import lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.NotNull;

import static com.devoxx.genie.model.Constant.*;

@Getter
@Setter
@Service
@State(
name = "com.devoxx.genie.ui.LLMConfigState",
storages = @Storage("DevoxxGenieLLMConfigPlugin.xml")
)
public final class LLMConfigStateService implements PersistentStateComponent<LLMConfigStateService> {

public static LLMConfigStateService getInstance() {
return ApplicationManager.getApplication().getService(LLMConfigStateService.class);
}

// Prompt fields
private String systemPrompt = SYSTEM_PROMPT;
private String testPrompt = TEST_PROMPT;
private String reviewPrompt = REVIEW_PROMPT;
private String explainPrompt = EXPLAIN_PROMPT;
private String customPrompt = CUSTOM_PROMPT;

// LLM settings
@OptionTag(converter = DoubleConverter.class)
private Double temperature = TEMPERATURE;

@OptionTag(converter = DoubleConverter.class)
private Double topP = TOP_P;

private Integer timeout = TIMEOUT;
private Integer maxRetries = MAX_RETRIES;
private Integer chatMemorySize = MAX_MEMORY;

// Was unable to make it work with Integer for some unknown reason
private String maxOutputTokens = MAX_OUTPUT_TOKENS.toString();

// Last selected LLM provider and model name
private String lastSelectedProvider;
private String lastSelectedModel;

// Enable AST mode
private Boolean astMode = AST_MODE;
private Boolean astParentClass = AST_PARENT_CLASS;
private Boolean astClassReference = AST_CLASS_REFERENCE;
private Boolean astFieldReference = AST_FIELD_REFERENCE;

@Override
public LLMConfigStateService getState() {
return this;
}

@Override
public void loadState(@NotNull LLMConfigStateService state) {
XmlSerializerUtil.copyBean(state, this);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.devoxx.genie.service.settings;
package com.devoxx.genie.service.settings.prompts;

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.PersistentStateComponent;
Expand All @@ -21,17 +21,17 @@
)
public final class PromptSettingsStateService implements PersistentStateComponent<PromptSettingsStateService> {

public static PromptSettingsStateService getInstance() {
return ApplicationManager.getApplication().getService(PromptSettingsStateService.class);
}

// Prompt fields
private String systemPrompt = SYSTEM_PROMPT;
private String testPrompt = TEST_PROMPT;
private String reviewPrompt = REVIEW_PROMPT;
private String explainPrompt = EXPLAIN_PROMPT;
private String customPrompt = CUSTOM_PROMPT;

public static PromptSettingsStateService getInstance() {
return ApplicationManager.getApplication().getService(PromptSettingsStateService.class);
}

@Override
public PromptSettingsStateService getState() {
return this;
Expand Down

This file was deleted.

Loading

0 comments on commit 3c43826

Please sign in to comment.