Skip to content

Commit 32e7643

Browse files
committed
fix(custom-agent): fix CustomAgentExecutor requestFormat issue #51
- Remove new line character at the end of the requestFormat string in CustomAgentExecutor. - Set the responseFormat to the value from CustomAgentConfig if available.
1 parent 583ee94 commit 32e7643

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/main/kotlin/cc/unitmesh/devti/counit/CustomAgentExecutor.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ class CustomAgentExecutor(val project: Project) : CustomSSEProcessor() {
2020
private var client = OkHttpClient()
2121
private val logger = logger<CustomAgentExecutor>()
2222

23-
override var requestFormat: String = "{ \"messageKeys\": {\"role\": \"role\", \"content\": \"content\"} }\n"
23+
override var requestFormat: String = "{ \"messageKeys\": {\"role\": \"role\", \"content\": \"content\"} }"
2424
override var responseFormat: String = "\$.choices[0].delta.content"
2525

2626
fun execute(input: String, agent: CustomAgentConfig): Flow<String>? {
27-
this.responseFormat = agent.connector?.responseFormat ?: this.responseFormat
2827
this.requestFormat = agent.connector?.requestFormat ?: this.requestFormat
28+
this.responseFormat = agent.connector?.responseFormat ?: this.responseFormat
2929

3030
val customRequest = CustomRequest(listOf(Message("user", input)))
3131
val request = customRequest.updateCustomFormat(requestFormat)

src/main/kotlin/cc/unitmesh/devti/llms/custom/JSONBodyResponseCallback.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ class JSONBodyResponseCallback(private val responseFormat: String,private val ca
1717

1818
override fun onResponse(call: Call, response: Response) {
1919
val responseBody: String? = response.body?.string()
20+
if (responseFormat.isEmpty()) {
21+
runBlocking {
22+
callback(responseBody ?: "")
23+
}
24+
25+
return
26+
}
27+
2028
val responseContent: String = JsonPath.parse(responseBody)?.read(responseFormat) ?: ""
2129

2230
runBlocking() {

0 commit comments

Comments
 (0)