Skip to content

Commit

Permalink
feat(coder): add disable history messages #54
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Jan 5, 2024
1 parent 516a765 commit 265d343
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/main/kotlin/cc/unitmesh/devti/gui/chat/ChatActionType.kt
Expand Up @@ -57,10 +57,7 @@ enum class ChatActionType {
COUNIT -> ""
CODE_REVIEW -> ""
CREATE_GENIUS -> ""
GENERATE_TEST_DATA -> "Generate JSON for given $lang code. So that we can use it to test for APIs. \n" +
"Make sure JSON contains real business logic, not just data structure. \n" +
"For example, if the code is a function that returns a list of users, " +
"the JSON should contain a list of users, not just a list of user objects."
GENERATE_TEST_DATA -> "Generate JSON for given $lang code. So that we can use it to test for APIs. \n"
}
}

Expand Down
Expand Up @@ -98,6 +98,9 @@ class AzureOpenAIProvider(val project: Project) : LLMProvider {
if (historyMessageLength > maxTokenLength) {
messages.clear()
}
if (project.coderSetting.state.noChatHistory) {
messages.clear()
}

messages.add(SimpleOpenAIFormat.fromChatMessage(systemMessage))
val requestText = Json.encodeToString<SimpleOpenAIBody>(
Expand Down
Expand Up @@ -4,6 +4,7 @@ import cc.unitmesh.devti.gui.chat.ChatRole
import cc.unitmesh.devti.llms.LLMProvider
import cc.unitmesh.devti.settings.AutoDevSettingsState
import cc.unitmesh.devti.settings.ResponseType
import cc.unitmesh.devti.settings.coder.coderSetting
import com.fasterxml.jackson.databind.ObjectMapper
import com.intellij.openapi.components.Service
import com.intellij.openapi.diagnostic.logger
Expand Down Expand Up @@ -71,6 +72,9 @@ class CustomLLMProvider(val project: Project) : LLMProvider {
if (!keepHistory) {
clearMessage()
}
if (project.coderSetting.state.noChatHistory) {
messages.clear()
}

messages += Message("user", promptText)

Expand Down
Expand Up @@ -103,6 +103,10 @@ class OpenAIProvider(val project: Project) : LLMProvider {
clearMessage()
}

if (project.coderSetting.state.noChatHistory) {
messages.clear()
}

var output = ""
val completionRequest = prepareRequest(promptText, systemPrompt)

Expand Down
Expand Up @@ -14,6 +14,8 @@ class AutoDevCoderConfigurable(project: Project) : BoundConfigurable(AutoDevBund
private val recordingInLocalCheckBox = JCheckBox()
private val disableAdvanceContextCheckBox = JCheckBox()
private val inEditorCompletionCheckBox = JCheckBox()
private val noChatHistoryCheckBox = JCheckBox()

private val explainCodeField = JTextField()
private val refactorCodeField = JTextField()
private val fixIssueCodeField = JTextField()
Expand All @@ -40,6 +42,16 @@ class AutoDevCoderConfigurable(project: Project) : BoundConfigurable(AutoDevBund
prop = state::disableAdvanceContext.toMutableProperty()
)
}

row(AutoDevBundle.message("settings.autodev.coder.noChatHistory")) {
fullWidthCell(noChatHistoryCheckBox)
.bind(
componentGet = { it.isSelected },
componentSet = { component, value -> component.isSelected = value },
prop = state::noChatHistory.toMutableProperty()
)
}

row(AutoDevBundle.message("settings.autodev.coder.inEditorCompletion")) {
fullWidthCell(inEditorCompletionCheckBox)
.bind(
Expand Down Expand Up @@ -90,6 +102,7 @@ class AutoDevCoderConfigurable(project: Project) : BoundConfigurable(AutoDevBund
it.refactorCode = state.refactorCode
it.fixIssueCode = state.fixIssueCode
it.generateTest = state.generateTest
it.noChatHistory = state.noChatHistory
}
}
}
Expand Down
Expand Up @@ -22,6 +22,8 @@ class AutoDevCoderSettingService(
var recordingInLocal by property(false)
var disableAdvanceContext by property(false)
var inEditorCompletion by property(false)
var noChatHistory by property(false)

var explainCode: String by property("Explain \$lang code") { it.isEmpty() }
var refactorCode: String by property("Refactor the given \$lang code") { it.isEmpty() }
var fixIssueCode: String by property("Help me fix this issue") { it.isEmpty() }
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/messages/AutoDevBundle.properties
Expand Up @@ -91,6 +91,7 @@ settings.autodev.coder=AutoDev Coder
settings.autodev.coder.recordingInLocal=Recording Instruction In Local
settings.autodev.coder.disableAdvanceContext=Disable Advance Context (like framework context or others)
settings.autodev.coder.inEditorCompletion=Completion in Editor
settings.autodev.coder.noChatHistory=No Chat History
settings.autodev.coder.explainCode=Explain code
settings.autodev.coder.refactorCode=Refactor code
settings.autodev.coder.fixIssueCode=Fix issue
Expand Down

0 comments on commit 265d343

Please sign in to comment.