mirror of
https://github.com/carlrobertoh/ProxyAI.git
synced 2026-05-20 09:24:08 +00:00
feat: support code editing and commit message generation for Deepseek R1 model (closes #835)
This commit is contained in:
parent
33760001d7
commit
668c8ed27e
4 changed files with 21 additions and 11 deletions
|
|
@ -19,6 +19,7 @@ import com.intellij.openapi.vcs.changes.Change
|
|||
import com.intellij.vcs.commit.CommitWorkflowUi
|
||||
import ee.carlrobert.codegpt.EncodingManager
|
||||
import ee.carlrobert.codegpt.completions.CompletionRequestService
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.ThinkingOutputParser
|
||||
import ee.carlrobert.codegpt.ui.OverlayUtil
|
||||
import ee.carlrobert.codegpt.util.CommitWorkflowChanges
|
||||
import ee.carlrobert.codegpt.util.GitUtil.getProjectRepository
|
||||
|
|
@ -123,12 +124,17 @@ abstract class BaseCommitWorkflowAction : DumbAwareAction() {
|
|||
class CommitMessageEventListener(
|
||||
private val project: Project,
|
||||
private val commitWorkflowUi: CommitWorkflowUi
|
||||
) : CompletionEventListener<String?> {
|
||||
private val messageBuilder = StringBuilder()
|
||||
) : CompletionEventListener<String> {
|
||||
|
||||
override fun onMessage(message: String?, eventSource: EventSource) {
|
||||
messageBuilder.append(message)
|
||||
updateCommitMessage(messageBuilder.toString())
|
||||
private val messageBuilder = StringBuilder()
|
||||
private val thinkingOutputParser = ThinkingOutputParser()
|
||||
|
||||
override fun onMessage(message: String, eventSource: EventSource) {
|
||||
val processedChunk = thinkingOutputParser.processChunk(message)
|
||||
if (processedChunk.isNotEmpty() && thinkingOutputParser.isFinished) {
|
||||
messageBuilder.append(message)
|
||||
updateCommitMessage(messageBuilder.toString())
|
||||
}
|
||||
}
|
||||
|
||||
override fun onComplete(result: StringBuilder) {
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import com.intellij.openapi.util.text.StringUtil
|
|||
import com.intellij.psi.PsiDocumentManager
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager
|
||||
import com.intellij.ui.JBColor
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.ThinkingOutputParser
|
||||
import ee.carlrobert.codegpt.ui.ObservableProperties
|
||||
import ee.carlrobert.codegpt.ui.OverlayUtil
|
||||
import ee.carlrobert.llm.client.openai.completion.ErrorDetails
|
||||
|
|
@ -28,9 +29,13 @@ class EditCodeCompletionListener(
|
|||
|
||||
private var replacedLength = 0
|
||||
private var currentHighlighter: RangeHighlighter? = null
|
||||
private val thinkingOutputParser = ThinkingOutputParser()
|
||||
|
||||
override fun onMessage(message: String, eventSource: EventSource) {
|
||||
runInEdt { handleDiff(message) }
|
||||
val processedChunk = thinkingOutputParser.processChunk(message)
|
||||
if (processedChunk.isNotEmpty() && thinkingOutputParser.isFinished) {
|
||||
runInEdt { handleDiff(processedChunk) }
|
||||
}
|
||||
}
|
||||
|
||||
override fun onComplete(messageBuilder: StringBuilder) {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ class ThinkingOutputParser {
|
|||
|
||||
companion object {
|
||||
private const val OPEN_TAG = "<think>"
|
||||
private const val CLOSE_TAG = "</think>"
|
||||
private const val CLOSE_TAG = "</think>\n\n"
|
||||
}
|
||||
|
||||
var thoughtProcess: String = ""
|
||||
|
|
@ -29,7 +29,6 @@ class ThinkingOutputParser {
|
|||
buffer.append(chunk)
|
||||
val current = buffer.toString()
|
||||
|
||||
|
||||
val indexOpen = current.indexOf(OPEN_TAG)
|
||||
if (indexOpen == -1) {
|
||||
return ""
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ class ThinkingOutputParserTest {
|
|||
@Test
|
||||
fun `when not processing then return empty string`() {
|
||||
val parser = ThinkingOutputParser()
|
||||
assertThat(parser.processChunk("Some text")).isEmpty()
|
||||
assertThat(parser.processChunk("Some text")).isEqualTo("Some text")
|
||||
assertThat(parser.thoughtProcess).isEmpty()
|
||||
}
|
||||
|
||||
|
|
@ -27,7 +27,7 @@ class ThinkingOutputParserTest {
|
|||
@Test
|
||||
fun `when thinking finished then return everything after the last closing think tag`() {
|
||||
val parser = ThinkingOutputParser()
|
||||
parser.processChunk("<think>the internal thought</think>")
|
||||
parser.processChunk("<think>the internal thought</think>\n\n")
|
||||
assertThat(parser.thoughtProcess).isEqualTo("the internal thought")
|
||||
|
||||
val finalOutput = parser.processChunk("Here is the user response.")
|
||||
|
|
@ -46,7 +46,7 @@ class ThinkingOutputParserTest {
|
|||
assertThat(parser.processChunk(" with even more details... ")).isEmpty()
|
||||
assertThat(parser.thoughtProcess).isEqualTo("some internal processing with even more details... ")
|
||||
|
||||
val finalOutput = parser.processChunk("</think>The final answer.")
|
||||
val finalOutput = parser.processChunk("</think>\n\nThe final answer.")
|
||||
|
||||
assertThat(finalOutput).isEqualTo("The final answer.")
|
||||
assertThat(parser.thoughtProcess).isEqualTo("some internal processing with even more details...")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue