mirror of
https://github.com/carlrobertoh/ProxyAI.git
synced 2026-05-22 03:30:04 +00:00
feat: Handle "stop" parameter transformation in CodeCompletionRequestFactory (#1125)
This commit is contained in:
parent
67824c2689
commit
1fe0e35aa5
1 changed files with 17 additions and 1 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package ee.carlrobert.codegpt.codecompletions
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException
|
||||
import com.fasterxml.jackson.core.type.TypeReference
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import com.intellij.openapi.components.service
|
||||
import ee.carlrobert.codegpt.completions.llama.LlamaModel
|
||||
|
|
@ -24,6 +25,7 @@ import ee.carlrobert.service.GrpcCodeCompletionRequest
|
|||
import okhttp3.MediaType.Companion.toMediaType
|
||||
import okhttp3.Request
|
||||
import okhttp3.RequestBody.Companion.toRequestBody
|
||||
import org.apache.commons.text.StringEscapeUtils
|
||||
import java.nio.charset.StandardCharsets
|
||||
|
||||
object CodeCompletionRequestFactory {
|
||||
|
|
@ -175,7 +177,21 @@ object CodeCompletionRequestFactory {
|
|||
requestBuilder.addHeader(entry.key, value)
|
||||
}
|
||||
val transformedBody = body.entries.associate { (key, value) ->
|
||||
key to transformValue(value, infillTemplate, details)
|
||||
when (key.lowercase()) {
|
||||
"stop" -> {
|
||||
if (value is String) {
|
||||
if (value.isEmpty())
|
||||
null
|
||||
if (value.startsWith("[") && value.endsWith("]"))
|
||||
key to ObjectMapper().readValue(value, object : TypeReference<List<String>>() {})
|
||||
else
|
||||
key to value.split(",").map { StringEscapeUtils.unescapeJava(it.trim()) }
|
||||
} else {
|
||||
key to value
|
||||
}
|
||||
}
|
||||
else -> key to transformValue(value, infillTemplate, details)
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue