Skip to content

Commit 7ab469b

Browse files
committed
fix: disable for welcome board
1 parent ba83c80 commit 7ab469b

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

src/main/kotlin/cc/unitmesh/devti/gui/chat/ChatCodingPanel.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class ChatCodingPanel(private val chatCodingService: ChatCodingService, val disp
7171
myList.background = UIUtil.getListBackground()
7272

7373
myScrollPane = JBScrollPane(
74-
welcomeComponent,
74+
myList,
7575
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
7676
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER
7777
)
@@ -137,11 +137,15 @@ class ChatCodingPanel(private val chatCodingService: ChatCodingService, val disp
137137
}
138138

139139
fun addMessage(message: String, isMe: Boolean = false, displayPrompt: String = "") {
140-
if (!hasMessage) {
141-
myScrollPane.remove(welcomeComponent)
142-
hasMessage = true
143-
myScrollPane.setViewportView(myList)
144-
}
140+
// if (!hasMessage) {
141+
// myScrollPane.remove(welcomeComponent)
142+
// hasMessage = true
143+
// try {
144+
// myScrollPane.setViewportView(myList)
145+
// } catch (e: Exception) {
146+
// e.printStackTrace()
147+
// }
148+
// }
145149

146150
val role = if (isMe) ChatRole.User else ChatRole.Assistant
147151
val displayText = displayPrompt.ifEmpty { message }

src/main/kotlin/cc/unitmesh/devti/llms/openai/OpenAIProvider.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class OpenAIProvider(val project: Project) : CodeCopilotProvider {
3535
private val timeout = Duration.ofSeconds(600)
3636
private val openAiVersion: String = AutoDevSettingsState.getInstance()?.openAiModel ?: OPENAI_MODEL[0]
3737
private val openAiKey: String = AutoDevSettingsState.getInstance()?.openAiKey ?: ""
38+
private val maxTokenLength: Int = AutoDevSettingsState.maxTokenLength
3839

3940
init {
4041

@@ -104,7 +105,7 @@ class OpenAIProvider(val project: Project) : CodeCopilotProvider {
104105
val systemMessage = ChatMessage(ChatMessageRole.USER.value(), promptText)
105106

106107
historyMessageLength += promptText.length
107-
if (historyMessageLength > 16384) {
108+
if (historyMessageLength > maxTokenLength) {
108109
messages.clear()
109110
}
110111

src/main/kotlin/cc/unitmesh/devti/provider/PromptStrategy.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cc.unitmesh.devti.provider
33
import cc.unitmesh.devti.llms.tokenizer.Tokenizer
44
import cc.unitmesh.devti.llms.tokenizer.TokenizerImpl
55
import cc.unitmesh.devti.prompting.model.FinalCodePrompt
6+
import cc.unitmesh.devti.settings.AutoDevSettingsState
67
import com.intellij.openapi.extensions.ExtensionPointName
78
import com.intellij.psi.PsiElement
89
import com.intellij.serviceContainer.LazyExtensionInstance
@@ -21,8 +22,7 @@ abstract class PromptStrategy : LazyExtensionInstance<PromptStrategy>() {
2122
return implementationClass
2223
}
2324

24-
// The default OpenAI Token will be 4096, we leave 2048 for the code.
25-
open fun tokenLength(): Int = 8192
25+
open fun tokenLength(): Int = AutoDevSettingsState.maxTokenLength
2626
fun count(code: String): Int = tokenizer.count(code)
2727
abstract fun advice(prefixCode: String, suffixCode: String): FinalCodePrompt
2828
abstract fun advice(psiFile: PsiElement, calleeName: String = ""): FinalCodePrompt

src/main/kotlin/cc/unitmesh/devti/settings/AutoDevSettingsState.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ class AutoDevSettingsState : PersistentStateComponent<AutoDevSettingsState> {
2020
var language = DEFAULT_HUMAN_LANGUAGE
2121
var maxTokenLength = MAX_TOKEN_LENGTH.toString()
2222

23+
fun fetchMaxTokenLength(): Int {
24+
return maxTokenLength.toIntOrNull() ?: MAX_TOKEN_LENGTH
25+
}
26+
2327
@Synchronized
2428
override fun getState(): AutoDevSettingsState {
2529
return this
@@ -31,6 +35,8 @@ class AutoDevSettingsState : PersistentStateComponent<AutoDevSettingsState> {
3135
}
3236

3337
companion object {
38+
val maxTokenLength: Int get() = getInstance().fetchMaxTokenLength()
39+
3440
fun getInstance(): AutoDevSettingsState {
3541
return ApplicationManager.getApplication().getService(AutoDevSettingsState::class.java).state
3642
}

0 commit comments

Comments
 (0)